Skip to content

Commit

Permalink
Get _omittedCommentsOffset_ from the server response
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Jun 22, 2024
1 parent b81af09 commit bec08f3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.133.0] - Not released
### Added
- Add a "description" meta-tag to the index.html.
### Changed
- Switch to V3 server API (with _omittedCommentsOffset_ field and two comments
after the fold).
### Fixed
- Update SSI patterns in index.html to support dashes in groupnames.

Expand Down
2 changes: 0 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export function postParser(post) {
...post,
commentsDisabled: post.commentsDisabled === '1',
savePostStatus: initialAsyncState,
// After what comment the omittedComments span is started?
omittedCommentsOffset: post.omittedComments > 0 ? 1 : 0,
// All hashtags used in the post body
hashtags: tokenizeHashtags()(post.body || '').map((t) => t.text),
};
Expand Down
76 changes: 57 additions & 19 deletions test/unit/redux/reducers/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,61 @@ describe('comments-related data', () => {
};

it(`should parse post without comments`, () => {
expect(postParser({ id: 'post', comments: [], omittedComments: 0 }), 'to equal', {
...emptyPostState,
id: 'post',
});
expect(
postParser({ id: 'post', comments: [], omittedComments: 0, omittedCommentsOffset: 0 }),
'to equal',
{
...emptyPostState,
id: 'post',
},
);
});

it(`should parse post with unfolded comments`, () => {
expect(postParser({ id: 'post', comments: ['c1', 'c2'], omittedComments: 0 }), 'to equal', {
...emptyPostState,
id: 'post',
comments: ['c1', 'c2'],
});
expect(
postParser({
id: 'post',
comments: ['c1', 'c2'],
omittedComments: 0,
omittedCommentsOffset: 0,
}),
'to equal',
{
...emptyPostState,
id: 'post',
comments: ['c1', 'c2'],
},
);
});

it(`should parse post with folded comments`, () => {
expect(postParser({ id: 'post', comments: ['c1', 'c2'], omittedComments: 3 }), 'to equal', {
...emptyPostState,
id: 'post',
comments: ['c1', 'c2'],
omittedComments: 3,
omittedCommentsOffset: 1,
});
expect(
postParser({
id: 'post',
comments: ['c1', 'c2'],
omittedComments: 3,
omittedCommentsOffset: 1,
}),
'to equal',
{
...emptyPostState,
id: 'post',
comments: ['c1', 'c2'],
omittedComments: 3,
omittedCommentsOffset: 1,
},
);
});

it(`should parse post with hashtags`, () => {
expect(
postParser({ id: 'post', body: 'Hello #wórld!', comments: [], omittedComments: 0 }),
postParser({
id: 'post',
body: 'Hello #wórld!',
comments: [],
omittedComments: 0,
omittedCommentsOffset: 0,
}),
'to equal',
{
...emptyPostState,
Expand All @@ -69,18 +97,21 @@ describe('comments-related data', () => {
id: 'post0',
comments: [],
omittedComments: 0,
omittedCommentsOffset: 0,
omittedCommentLikes: 0,
}),
post1: postParser({
id: 'post1',
comments: ['comm11', 'comm12'],
omittedComments: 0,
omittedCommentsOffset: 0,
omittedCommentLikes: 0,
}),
post2: postParser({
id: 'post2',
comments: ['comm21', 'comm22'],
omittedComments: 2,
omittedCommentsOffset: 1,
omittedCommentLikes: 2,
}),
};
Expand Down Expand Up @@ -352,7 +383,7 @@ describe('comments-related data', () => {
describe('SHOW_MORE_COMMENTS', () => {
const action = (postId, comments) => ({
type: response(SHOW_MORE_COMMENTS),
payload: { posts: { id: postId, comments, omittedComments: 0 } },
payload: { posts: { id: postId, comments, omittedComments: 0, omittedCommentsOffset: 0 } },
});

it('should expand comments of post2', () => {
Expand Down Expand Up @@ -390,7 +421,14 @@ describe('comments-related data', () => {
describe('COMPLETE_POST_COMMENTS', () => {
const action = (postId, comments, omittedComments) => ({
type: response(COMPLETE_POST_COMMENTS),
payload: { posts: { id: postId, comments, omittedComments } },
payload: {
posts: {
id: postId,
comments,
omittedComments,
omittedCommentsOffset: omittedComments ? 1 : 0,
},
},
});

it(`should complete a missing first comment`, () => {
Expand Down

0 comments on commit bec08f3

Please sign in to comment.