Skip to content

Commit 2aa7d68

Browse files
committed
Use extend
1 parent 7c925ac commit 2aa7d68

File tree

11 files changed

+90
-135
lines changed

11 files changed

+90
-135
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868
"@babel/core": "^7.26.9",
6969
"@chromatic-com/storybook": "4.0.0-next.6",
7070
"@eslint/js": "^9.21.0",
71-
"@storybook/addon-a11y": "0.0.0-pr-30601-sha-0cdccd73",
71+
"@storybook/addon-a11y": "0.0.0-pr-30601-sha-40d66b1f",
7272
"@storybook/addon-coverage": "^1.0.5",
7373
"@storybook/addon-designs": "^10.0.1",
74-
"@storybook/addon-docs": "0.0.0-pr-30601-sha-0cdccd73",
75-
"@storybook/addon-themes": "0.0.0-pr-30601-sha-0cdccd73",
76-
"@storybook/addon-vitest": "0.0.0-pr-30601-sha-0cdccd73",
77-
"@storybook/react-vite": "0.0.0-pr-30601-sha-0cdccd73",
74+
"@storybook/addon-docs": "0.0.0-pr-30601-sha-40d66b1f",
75+
"@storybook/addon-themes": "0.0.0-pr-30601-sha-40d66b1f",
76+
"@storybook/addon-vitest": "0.0.0-pr-30601-sha-40d66b1f",
77+
"@storybook/react-vite": "0.0.0-pr-30601-sha-40d66b1f",
7878
"@storybook/test-runner": "^0.22.0",
7979
"@testing-library/jest-dom": "^6.6.3",
8080
"@testing-library/react": "^16.2.0",
@@ -103,7 +103,7 @@
103103
"eslint-plugin-jsx-a11y": "^6.10.2",
104104
"eslint-plugin-prettier": "^5.2.3",
105105
"eslint-plugin-react": "^7.37.4",
106-
"eslint-plugin-storybook": "0.0.0-pr-30601-sha-7813e8c3",
106+
"eslint-plugin-storybook": "0.0.0-pr-30601-sha-40d66b1f",
107107
"eslint-plugin-unicorn": "^57.0.0",
108108
"globals": "^16.0.0",
109109
"happy-dom": "^17.1.8",
@@ -117,7 +117,7 @@
117117
"prettier": "^3.5.2",
118118
"react-is": "^19.0.0",
119119
"react-test-renderer": "^19.0.0",
120-
"storybook": "0.0.0-pr-30601-sha-0cdccd73",
120+
"storybook": "0.0.0-pr-30601-sha-40d66b1f",
121121
"storybook-addon-test-codegen": "^2.0.0",
122122
"typescript-eslint": "^8.25.0",
123123
"vite": "^6.2.0",

src/components/Button/Button.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('renders button with custom children', async () => {
1313

1414
test('onclick handler is called', async () => {
1515
const onClickSpy = vi.fn()
16-
await Default.run({ args: { ...Default.input.args, onClick: onClickSpy } })
16+
await Default.run({ args: { onClick: onClickSpy } })
1717
const buttonElement = screen.getByRole('button')
1818
buttonElement.click()
1919
expect(onClickSpy).toHaveBeenCalled()

src/components/IconButton/IconButton.stories.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,4 @@ export const Default = meta.story({
2121
},
2222
})
2323

24-
export const Small = meta.story({
25-
args: {
26-
...Default.input.args,
27-
small: true,
28-
},
29-
})
24+
export const Small = Default.extend({ args: { small: true } })

src/components/PageSection/PageSection.stories.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,4 @@ export const Default = meta.story({
1717
},
1818
})
1919

20-
export const WithButtons = meta.story({
21-
args: {
22-
...Default.input.args,
23-
title: 'Asian',
24-
},
25-
})
20+
export const WithButtons = Default.extend({ args: { title: 'Asian' } })

src/components/RestaurantCard/RestaurantCard.stories.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,15 @@ export const Default = meta.story({
2323
},
2424
})
2525

26-
export const New = meta.story({
27-
args: {
28-
...Default.input.args,
29-
isNew: true,
30-
},
31-
})
26+
export const New = Default.extend({ args: { isNew: true } })
3227

33-
export const Closed = meta.story({
34-
args: {
35-
...Default.input.args,
36-
isClosed: true,
37-
},
28+
export const Closed = Default.extend({
29+
args: { isClosed: true },
3830
play: async ({ canvas }) => {
3931
await expect(canvas.getByText('This restaurant is closed.')).toBeInTheDocument()
4032
},
4133
})
4234

43-
export const Loading = meta.story({
44-
args: {
45-
...Default.input.args,
46-
isLoading: true,
47-
},
35+
export const Loading = Default.extend({
36+
args: { isLoading: true },
4837
})

src/components/RestaurantCard/RestaurantCard.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { vi, expect, describe, test } from 'vitest'
22
import { screen } from '@testing-library/react'
3-
import { composeStories } from '@storybook/react-vite'
43
import { axe } from 'vitest-axe'
54

65
import { Default, Loading, New, Closed } from './RestaurantCard.stories'
@@ -36,11 +35,7 @@ describe('RestaurantCard', () => {
3635
})
3736

3837
// Go through every story from composeStories and create a map of StoryName <-> StoryComponent
39-
const testCases = Object.values(composeStories(stories)).map((Story) => [
40-
// The ! is necessary in Typescript only, as the property is part of a partial type
41-
Story.storyName!,
42-
Story,
43-
])
38+
const testCases = Object.entries({ Default, Loading, New, Closed });
4439

4540
// Go through all test cases to batch test accessibility
4641
test.each(testCases)('%s story should be accessible', async (_storyName, Story) => {

src/components/TopBanner/TopBanner.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ export const Default = meta.story({
2020
},
2121
})
2222

23-
export const WithImage = meta.story({
23+
export const WithImage = Default.extend({
2424
args: {
25-
...Default.input.args,
2625
photoUrl:
2726
'https://images.unsplash.com/photo-1426869981800-95ebf51ce900?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=20',
2827
},

src/components/forms/Input.stories.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,9 @@ export const WithLabel = meta.story({
3030
},
3131
})
3232

33-
export const WithHint = meta.story({
34-
args: {
35-
...WithLabel.input.args,
36-
placeholder: 'This is a hint',
37-
},
38-
})
33+
export const WithHint = WithLabel.extend({ args: { placeholder: 'This is a hint' } })
3934

40-
export const Filled = meta.story({
41-
args: {
42-
...WithLabel.input.args,
43-
value: 'Already filled text',
44-
},
45-
})
35+
export const Filled = WithLabel.extend({ args: { value: 'Already filled text' } })
4636

4737
export const ErrorValidation = meta.story({
4838
args: {

src/pages/HomePage/components/RestaurantsSection/RestaurantsSection.stories.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ export const Default = meta.story({
2222
},
2323
})
2424

25-
export const Loading = meta.story({
26-
args: {
27-
...Default.input.args,
28-
},
25+
export const Loading = Default.extend({
2926
parameters: {
3027
msw: {
3128
handlers: [

src/pages/RestaurantDetailPage/components/FoodItem/FoodItem.stories.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const meta = preview.meta({
77
title: 'Pages/RestaurantDetailPage/Components/FoodItem',
88
component: FoodItem,
99
args: {
10-
/*
10+
/*
1111
The following line emulates the event handler that would be passed to the component
1212
Read more about the `fn` utility function at
13-
https://storybook.js.org/docs/essentials/actions#via-storybooktest-fn-spy-function
13+
https://storybook.js.org/docs/essentials/actions#via-storybooktest-fn-spy-function
1414
*/
1515
onClick: fn(),
1616
},
@@ -24,9 +24,4 @@ export const Default = meta.story({
2424
},
2525
})
2626

27-
export const WithQuantity = meta.story({
28-
args: {
29-
...Default.input.args,
30-
quantity: 5,
31-
},
32-
})
27+
export const WithQuantity = Default.extend({ args: { quantity: 5 } })

0 commit comments

Comments
 (0)