-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2016 from elifesciences/storybook-tests
Storybook tests
- Loading branch information
Showing
7 changed files
with
2,313 additions
and
439 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, userEvent, within } from '@storybook/test'; | ||
|
||
import { Authors } from './authors'; | ||
import { authors } from '../../../utils/mocks'; | ||
|
||
export default { | ||
const meta: Meta<typeof Authors> = { | ||
title: 'Atoms/Authors', | ||
component: Authors, | ||
} as Meta<typeof Authors>; | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Authors>; | ||
|
||
export const AuthorList: Story = { | ||
args: { | ||
authors, | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
await canvas.findByText('show', { exact: false }); | ||
|
||
const initialAuthors = Array.from(document.querySelectorAll('.authors-list li')).filter((node) => node.checkVisibility()); | ||
expect(initialAuthors).toHaveLength(10); | ||
|
||
await userEvent.click(canvas.getByText('show', { exact: false })); | ||
|
||
const expandedAuthors = Array.from(document.querySelectorAll('.authors-list li')).filter((node) => node.checkVisibility()); | ||
expect(expandedAuthors).toHaveLength(15); | ||
|
||
const Template: StoryFn<typeof Authors> = (args) => <Authors {...args} />; | ||
await userEvent.click(canvas.getByText('show', { exact: false })); | ||
|
||
export const AuthorList = Template.bind({}); | ||
AuthorList.args = { | ||
authors, | ||
const collapsedAuthors = Array.from(document.querySelectorAll('.authors-list li')).filter((node) => node.checkVisibility()); | ||
expect(collapsedAuthors).toHaveLength(10); | ||
}, | ||
}; |
51 changes: 35 additions & 16 deletions
51
src/components/atoms/institutions/institutions.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,21 +1,40 @@ | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
|
||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, userEvent, within } from '@storybook/test'; | ||
import { Institutions } from './institutions'; | ||
|
||
export default { | ||
const meta: Meta<typeof Institutions> = { | ||
title: 'Atoms/Institutions', | ||
component: Institutions, | ||
} as Meta<typeof Institutions>; | ||
|
||
const Template: StoryFn<typeof Institutions> = (args) => <Institutions {...args} />; | ||
|
||
export const InstitutionList = Template.bind({}); | ||
InstitutionList.args = { | ||
institutions: [ | ||
{ name: 'Charles Xavier\'s School for Gifted Youngsters', address: { addressCountry: 'West Chester' } }, | ||
{ name: 'Star Labs', address: { addressCountry: 'Star City' } }, | ||
{ name: 'Avengers Tower', address: { addressCountry: 'New York' } }, | ||
{ name: 'Bat Cave', address: { addressCountry: 'Gotham' } }, | ||
{ name: 'Arrow Cave', address: { addressCountry: 'Central City' } }, | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Institutions>; | ||
|
||
export const InstitutionList: Story = { | ||
args: { | ||
institutions: [ | ||
{ name: 'Charles Xavier\'s School for Gifted Youngsters', address: { addressCountry: 'West Chester' } }, | ||
{ name: 'Star Labs', address: { addressCountry: 'Star City' } }, | ||
{ name: 'Avengers Tower', address: { addressCountry: 'New York' } }, | ||
{ name: 'Bat Cave', address: { addressCountry: 'Gotham' } }, | ||
{ name: 'Arrow Cave', address: { addressCountry: 'Central City' } }, | ||
], | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
await canvas.findByText('show', { exact: false }); | ||
|
||
const initialInstitutions = Array.from(document.querySelectorAll('.institutions-list li')).filter((node) => node.checkVisibility()); | ||
expect(initialInstitutions).toHaveLength(3); | ||
|
||
await userEvent.click(canvas.getByText('show', { exact: false })); | ||
|
||
const expandedInstitutions = Array.from(document.querySelectorAll('.institutions-list li')).filter((node) => node.checkVisibility()); | ||
expect(expandedInstitutions).toHaveLength(5); | ||
|
||
await userEvent.click(canvas.getByText('show', { exact: false })); | ||
|
||
const collapsedInstitutions = Array.from(document.querySelectorAll('.institutions-list li')).filter((node) => node.checkVisibility()); | ||
expect(collapsedInstitutions).toHaveLength(3); | ||
}, | ||
}; |
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.