-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Add stories for the current and past proposals pages (#4465)
* Enable linking stories with the Router * Create current and past proposal stories * Fix the `RecursivePartial` type * Improve the type of mock resolvers * Warn of missing chain data * Generate current proposals * Generate past proposals * Reorganize the proposal stories in the navigation * Simplify api mocks code
- Loading branch information
Showing
25 changed files
with
449 additions
and
101 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
110 changes: 110 additions & 0 deletions
110
packages/ui/src/app/pages/Proposals/CurrentProposals.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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { linkTo } from '@storybook/addon-links' | ||
import { Meta, StoryContext, StoryObj } from '@storybook/react' | ||
import { userEvent, within } from '@storybook/testing-library' | ||
import { random } from 'faker' | ||
import { FC } from 'react' | ||
|
||
import { member } from '@/mocks/data/members' | ||
import { generateProposals, MAX_ACTIVE_PROPOSAL, proposalsPagesChain } from '@/mocks/data/proposals' | ||
import { getButtonByText } from '@/mocks/helpers' | ||
import { MocksParameters } from '@/mocks/providers' | ||
import { GetProposalVotesDocument, GetProposalsCountDocument, GetProposalsDocument } from '@/proposals/queries' | ||
|
||
import { Proposals } from './Proposals' | ||
|
||
import { randomMarkdown } from '@/../dev/query-node-mocks/generators/utils' | ||
|
||
const PROPOSAL_DATA = { | ||
title: random.words(4), | ||
description: randomMarkdown(), | ||
} | ||
|
||
type Args = { | ||
isCouncilMember: boolean | ||
proposalCount: number | ||
onVote: CallableFunction | ||
} | ||
type Story = StoryObj<FC<Args>> | ||
|
||
export default { | ||
title: 'Pages/Proposals/ProposalList/Current', | ||
component: Proposals, | ||
|
||
argTypes: { | ||
proposalCount: { control: { type: 'range', max: MAX_ACTIVE_PROPOSAL } }, | ||
onVote: { action: 'Voted' }, | ||
}, | ||
|
||
args: { | ||
isCouncilMember: false, | ||
proposalCount: 15, | ||
}, | ||
|
||
parameters: { | ||
router: { | ||
href: '/proposals/current', | ||
actions: { | ||
'/proposals/past': linkTo('Pages/Proposals/ProposalList/Past'), | ||
}, | ||
}, | ||
|
||
mocks: ({ args }: StoryContext<Args>): MocksParameters => { | ||
const alice = member('alice', { isCouncilMember: args.isCouncilMember }) | ||
|
||
return { | ||
accounts: { active: { member: alice } }, | ||
|
||
chain: proposalsPagesChain(args.proposalCount, { | ||
tx: { | ||
proposalsEngine: { | ||
vote: { event: 'Voted', onSend: args.onVote }, | ||
}, | ||
}, | ||
}), | ||
|
||
queryNode: [ | ||
{ | ||
query: GetProposalsCountDocument, | ||
data: { proposalsConnection: { totalCount: args.proposalCount } }, | ||
}, | ||
|
||
{ | ||
query: GetProposalsDocument, | ||
resolver: ({ variables } = {}) => ({ | ||
loading: false, | ||
data: { | ||
proposals: generateProposals( | ||
{ | ||
title: PROPOSAL_DATA.title, | ||
description: PROPOSAL_DATA.description, | ||
creator: alice, | ||
statuses: ['ProposalStatusGracing', 'ProposalStatusDormant', 'ProposalStatusDeciding'], | ||
limit: variables?.limit, | ||
offset: variables?.offset, | ||
}, | ||
args.proposalCount | ||
), | ||
}, | ||
}), | ||
}, | ||
|
||
{ | ||
query: GetProposalVotesDocument, | ||
data: { | ||
proposalVotedEvents: [], | ||
}, | ||
}, | ||
], | ||
} | ||
}, | ||
}, | ||
} satisfies Meta<Args> | ||
|
||
export const Default: Story = {} | ||
|
||
export const AddNewProposal: Story = { | ||
play: async ({ canvasElement }) => { | ||
const screen = within(canvasElement) | ||
await userEvent.click(getButtonByText(screen, 'Add new proposal')) | ||
}, | ||
} |
91 changes: 91 additions & 0 deletions
91
packages/ui/src/app/pages/Proposals/PastProposals.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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { linkTo } from '@storybook/addon-links' | ||
import { Meta, StoryContext, StoryObj } from '@storybook/react' | ||
import { random } from 'faker' | ||
import { FC } from 'react' | ||
|
||
import { member } from '@/mocks/data/members' | ||
import { generateProposals, proposalsPagesChain } from '@/mocks/data/proposals' | ||
import { MocksParameters } from '@/mocks/providers' | ||
import { GetProposalsCountDocument, GetProposalsDocument } from '@/proposals/queries' | ||
|
||
import { PastProposals } from './PastProposals' | ||
|
||
import { randomMarkdown } from '@/../dev/query-node-mocks/generators/utils' | ||
|
||
const PROPOSAL_DATA = { | ||
title: random.words(4), | ||
description: randomMarkdown(), | ||
} | ||
|
||
const alice = member('alice') | ||
|
||
type Args = { | ||
proposalCount: number | ||
} | ||
type Story = StoryObj<FC<Args>> | ||
|
||
export default { | ||
title: 'Pages/Proposals/ProposalList/Past', | ||
component: PastProposals, | ||
|
||
argTypes: { | ||
proposalCount: { control: { type: 'range', max: 30 } }, | ||
}, | ||
|
||
args: { | ||
proposalCount: 15, | ||
}, | ||
|
||
parameters: { | ||
router: { | ||
href: '/proposals/past', | ||
actions: { | ||
'/proposals/current': linkTo('Pages/Proposals/ProposalList/Current'), | ||
}, | ||
}, | ||
|
||
mocks: ({ args }: StoryContext<Args>): MocksParameters => { | ||
return { | ||
chain: proposalsPagesChain(5), | ||
|
||
queryNode: [ | ||
{ | ||
query: GetProposalsCountDocument, | ||
data: { proposalsConnection: { totalCount: args.proposalCount } }, | ||
}, | ||
|
||
{ | ||
query: GetProposalsDocument, | ||
resolver: ({ variables } = {}) => ({ | ||
loading: false, | ||
data: { | ||
proposals: generateProposals( | ||
{ | ||
title: PROPOSAL_DATA.title, | ||
description: PROPOSAL_DATA.description, | ||
creator: alice, | ||
statuses: [ | ||
'ProposalStatusCanceledByRuntime', | ||
'ProposalStatusCancelled', | ||
'ProposalStatusExecuted', | ||
'ProposalStatusExecutionFailed', | ||
'ProposalStatusExpired', | ||
'ProposalStatusRejected', | ||
'ProposalStatusSlashed', | ||
'ProposalStatusVetoed', | ||
], | ||
limit: variables?.limit, | ||
offset: variables?.offset, | ||
}, | ||
args.proposalCount | ||
), | ||
}, | ||
}), | ||
}, | ||
], | ||
} | ||
}, | ||
}, | ||
} satisfies Meta<Args> | ||
|
||
export const Default: Story = {} |
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
Oops, something went wrong.
2f4d5ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2-storybook β ./
pioneer-2-storybook.vercel.app
pioneer-2-storybook-git-dev-joystream.vercel.app
pioneer-2-storybook-joystream.vercel.app
2f4d5ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2 β ./
pioneer-2-git-dev-joystream.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2.vercel.app