Skip to content

Commit

Permalink
Add manual fixture data
Browse files Browse the repository at this point in the history
  • Loading branch information
abeddow91 committed Jan 24, 2024
1 parent 49d0209 commit 855126e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
10 changes: 5 additions & 5 deletions dotcom-rendering/src/components/Discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ export const Discussion = ({
}, [discussionApiUrl, hashCommentId]);

useEffect(() => {
// There's no point showing the view more button if there isn't much more to view
if (commentCount === 0 || commentCount === 1 || commentCount === 2) {
if (window.location.hash === '#comments') {
setIsExpanded(true);
}
}, [commentCount]);
}, []);

useEffect(() => {
if (window.location.hash === '#comments') {
// There's no point showing the view more button if there isn't much more to view
if (commentCount === 0 || commentCount === 1 || commentCount === 2) {
setIsExpanded(true);
}
}, []);
}, [commentCount]);

useEffect(() => {
const pendingElements = document.querySelectorAll<HTMLElement>(
Expand Down
53 changes: 27 additions & 26 deletions dotcom-rendering/src/components/Discussion/Comments.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { lightDecorator } from '../../../.storybook/decorators/themeDecorator';
import { discussion as discussionMock } from '../../../fixtures/manual/discussion';
import { discussionWithTwoComments } from '../../../fixtures/manual/discussionWithTwoComments';
import { legacyDiscussionWithoutThreading } from '../../../fixtures/manual/legacyDiscussionWithoutThreading';
import type { FilterOptions, SignedInUser } from '../../types/discussion';
import { Comments } from './Comments';

export default { component: Comments, title: 'Discussion/App' };

const { discussion, pages } = discussionMock;

const aUser: SignedInUser = {
profile: {
userId: 'abc123',
Expand Down Expand Up @@ -49,7 +48,7 @@ export const LoggedOutHiddenPicks = () => (
`}
>
<Comments
shortUrl={discussion.key}
shortUrl={discussionMock.discussion.key}
baseUrl="https://discussion.theguardian.com/discussion-api"
isClosedForComments={false}
additionalHeaders={{
Expand All @@ -65,10 +64,10 @@ export const LoggedOutHiddenPicks = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={discussionMock.pages}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand All @@ -91,7 +90,7 @@ export const InitialPage = () => (
`}
>
<Comments
shortUrl={discussion.key}
shortUrl={discussionMock.discussion.key}
baseUrl="https://discussion.theguardian.com/discussion-api"
isClosedForComments={false}
additionalHeaders={{
Expand All @@ -107,10 +106,10 @@ export const InitialPage = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={discussionMock.pages}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand Down Expand Up @@ -150,10 +149,10 @@ export const LoggedInHiddenNoPicks = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={discussionMock.pages}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand Down Expand Up @@ -187,10 +186,10 @@ export const LoggedIn = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={discussionMock.pages}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand Down Expand Up @@ -258,10 +257,10 @@ export const LoggedOutHiddenNoPicks = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={0}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={0}
comments={[]}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand All @@ -285,7 +284,7 @@ export const Closed = () => (
`}
>
<Comments
shortUrl={discussion.key}
shortUrl={discussionMock.discussion.key}
baseUrl="https://discussion.theguardian.com/discussion-api"
isClosedForComments={true}
user={aUser}
Expand All @@ -302,10 +301,10 @@ export const Closed = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={discussionMock.discussion.commentCount}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={discussionMock.pages}
comments={discussionMock.discussion.comments}
setComments={() => {}}
/>
</div>
Expand Down Expand Up @@ -370,7 +369,7 @@ export const LegacyDiscussion = () => (
`}
>
<Comments
shortUrl="p/32255" // A 'legacy' discussion that doesn't allow threading
shortUrl={legacyDiscussionWithoutThreading.discussion.key} // A 'legacy' discussion that doesn't allow threading
baseUrl="https://discussion.theguardian.com/discussion-api"
isClosedForComments={false}
additionalHeaders={{
Expand All @@ -386,10 +385,12 @@ export const LegacyDiscussion = () => (
setPage={() => {}}
filters={filters}
setFilters={() => {}}
commentCount={discussion.commentCount}
commentCount={
legacyDiscussionWithoutThreading.discussion.commentCount
}
loading={false}
totalPages={pages}
comments={discussion.comments}
totalPages={legacyDiscussionWithoutThreading.pages}
comments={legacyDiscussionWithoutThreading.discussion.comments}
setComments={() => {}}
/>
</div>
Expand Down

0 comments on commit 855126e

Please sign in to comment.