-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update counts to exclude deleted comments
- Loading branch information
Showing
14 changed files
with
97 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 11 additions & 7 deletions
18
packages/components/src/DiscussionTitle/DiscussionTitle.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { DiscussionTitle } from './DiscussionTitle' | ||
|
||
import type { Meta, StoryFn } from '@storybook/react' | ||
import type { IComment } from '../CommentItem/types' | ||
|
||
export default { | ||
title: 'Components/DiscussionTitle', | ||
component: DiscussionTitle, | ||
} as Meta<typeof DiscussionTitle> | ||
|
||
export const NoComments: StoryFn<typeof DiscussionTitle> = () => ( | ||
<DiscussionTitle length={0} /> | ||
<DiscussionTitle comments={[]} /> | ||
) | ||
|
||
export const OneComment: StoryFn<typeof DiscussionTitle> = () => ( | ||
<DiscussionTitle length={1} /> | ||
) | ||
export const OneComment: StoryFn<typeof DiscussionTitle> = () => { | ||
const comment = {} as IComment | ||
|
||
export const MultipleComments: StoryFn<typeof DiscussionTitle> = () => ( | ||
<DiscussionTitle length={45} /> | ||
) | ||
return <DiscussionTitle comments={[comment]} /> | ||
} | ||
|
||
export const MultipleComments: StoryFn<typeof DiscussionTitle> = () => { | ||
const comment = {} as IComment | ||
return <DiscussionTitle comments={[comment, comment, comment]} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18
packages/components/src/DiscussionTitle/DiscussionTitle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { filterNonDeletedComments } from './filterNonDeletedComments' | ||
|
||
import type { IComment } from 'src/models' | ||
|
||
describe('nonDeletedCommentsCount', () => { | ||
it('returns the full total when no comments are marked as deleted', () => { | ||
const comments = [{ _id: '1' }, { _id: '2' }, { _id: '3' }] as IComment[] | ||
expect(filterNonDeletedComments(comments)).toEqual(comments) | ||
}) | ||
|
||
it('returns the reduced total when comments are marked as deleted', () => { | ||
const comments = [ | ||
{ _id: '1', _deleted: true }, | ||
{ _id: '2', _deleted: true }, | ||
{ _id: '3' }, | ||
] as IComment[] | ||
expect(filterNonDeletedComments(comments)).toEqual([comments[2]]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { IComment } from 'src/models' | ||
|
||
export const filterNonDeletedComments = (comments: IComment[]): IComment[] => { | ||
return comments.filter(({ _deleted }) => _deleted !== true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '@testing-library/jest-dom/vitest' | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
import { nonDeletedCommentsCount } from './nonDeletedCommentsCount' | ||
|
||
import type { IComment } from 'src/models' | ||
|
||
describe('nonDeletedCommentsCount', () => { | ||
it('returns the full total when no comments are marked as deleted', () => { | ||
const comments = [{}, {}, {}, {}] as IComment[] | ||
expect(nonDeletedCommentsCount(comments)).toEqual(4) | ||
}) | ||
|
||
it('returns the reduced total when comments are marked as deleted', () => { | ||
const comments = [ | ||
{ _deleted: true }, | ||
{ _deleted: true }, | ||
{}, | ||
{}, | ||
] as IComment[] | ||
expect(nonDeletedCommentsCount(comments)).toEqual(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { filterNonDeletedComments } from './filterNonDeletedComments' | ||
|
||
import type { IComment } from 'src/models' | ||
|
||
export const nonDeletedCommentsCount = (comments: IComment[]): number => { | ||
return filterNonDeletedComments(comments).length | ||
} |