Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 1b0795f

Browse files
committed
Revert CSF3 support
This reverts commit e263e32, reversing changes made to cb0c7b2.
1 parent b835e2a commit 1b0795f

File tree

11 files changed

+635
-1405
lines changed

11 files changed

+635
-1405
lines changed

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,38 +156,6 @@ Primary.args.children;
156156
Primary.args!.children;
157157
```
158158

159-
### CSF3
160-
161-
Storybook released a [new version of CSF](https://storybook.js.org/blog/component-story-format-3-0/), where the story can also be an object. This is supported in @storybook/testing-react. CSF3 also brings a new function called `play`, where you can write automated interactions to the story.
162-
163-
In @storybook/testing-react, the `play` does not run automatically for you, but rather comes in the returned component, and you can execute it as you please.
164-
165-
Consider the following example:
166-
167-
```tsx
168-
export const InputFieldFilled: Story<InputFieldProps> = {
169-
play: async () => {
170-
await userEvent.type(screen.getByRole('textbox'), 'Hello world!');
171-
},
172-
};
173-
```
174-
175-
You can use the play function like this:
176-
177-
```tsx
178-
const { InputFieldFilled } = composeStories(stories);
179-
180-
test('renders with play function', async () => {
181-
render(<InputFieldFilled />);
182-
183-
// play an interaction that fills the input
184-
await InputFieldFilled.play!();
185-
186-
const input = screen.getByRole('textbox') as HTMLInputElement;
187-
expect(input.value).toEqual('Hello world!');
188-
});
189-
```
190-
191159
## Typescript
192160

193161
`@storybook/testing-react` is typescript ready and provides autocompletion to easily detect all stories of your component:

example/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
"typescript": "^3.9.7"
3636
},
3737
"devDependencies": {
38-
"@storybook/addon-essentials": "^6.4.0-alpha.17",
39-
"@storybook/react": "^6.4.0-alpha.17",
40-
"@storybook/components": "^6.4.0-alpha.17",
41-
"@storybook/theming": "^6.4.0-alpha.17",
38+
"@storybook/addon-essentials": "^6.3.0",
39+
"@storybook/react": "^6.3.0",
40+
"@storybook/components": "^6.3.0",
41+
"@storybook/theming": "^6.3.0",
4242
"@storybook/preset-create-react-app": "^3.1.5",
4343
"@testing-library/react": "^11.2.5",
4444
"@testing-library/user-event": "^13.1.9"

example/src/components/Button.stories.tsx

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from 'react';
22
import { Story, Meta } from '@storybook/react';
3-
import { screen } from '@testing-library/react';
4-
import userEvent from '@testing-library/user-event';
53

64
import { Button, ButtonProps } from './Button';
75

@@ -53,32 +51,9 @@ export const StoryWithParamsAndDecorator: Story<ButtonProps> = (args) => {
5351
return <Button {...args} />;
5452
};
5553
StoryWithParamsAndDecorator.args = {
56-
children: 'foo',
57-
};
54+
children: 'foo'
55+
}
5856
StoryWithParamsAndDecorator.parameters = {
59-
layout: 'centered',
60-
};
61-
StoryWithParamsAndDecorator.decorators = [(StoryFn) => <StoryFn />];
62-
63-
export const CSF3Button: Story<ButtonProps> = {
64-
args: { children: 'foo' },
65-
};
66-
67-
export const CSF3ButtonWithRender: Story<ButtonProps> = {
68-
...CSF3Button,
69-
render: (args: ButtonProps) => (
70-
<div>
71-
<p data-testid="custom-render">I am a custom render function</p>
72-
<Button {...args} />
73-
</div>
74-
),
75-
};
76-
77-
export const InputFieldFilled: Story = {
78-
render: () => {
79-
return <input />
80-
},
81-
play: async () => {
82-
await userEvent.type(screen.getByRole('textbox'), 'Hello world!');
83-
}
84-
};
57+
layout: 'centered'
58+
}
59+
StoryWithParamsAndDecorator.decorators = [(StoryFn) => <StoryFn />]

example/src/components/Button.test.tsx

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,3 @@ describe('GlobalConfig', () => {
6060
expect(buttonElement).not.toBeNull();
6161
});
6262
});
63-
64-
describe('CSF3', () => {
65-
test('renders with inferred globalRender', () => {
66-
const Primary = composeStory(
67-
stories.CSF3Button,
68-
stories.default
69-
);
70-
71-
render(<Primary>Hello world</Primary>);
72-
const buttonElement = screen.getByText(/Hello world/i);
73-
expect(buttonElement).not.toBeNull();
74-
});
75-
76-
test('renders with custom render function', () => {
77-
const Primary = composeStory(
78-
stories.CSF3ButtonWithRender,
79-
stories.default
80-
);
81-
82-
render(<Primary />);
83-
expect(screen.getByTestId("custom-render")).not.toBeNull();
84-
});
85-
86-
test('renders with play function', async () => {
87-
const InputFieldFilled = composeStory(
88-
stories.InputFieldFilled,
89-
stories.default
90-
);
91-
92-
render(<InputFieldFilled />);
93-
94-
await InputFieldFilled.play!();
95-
96-
const input = screen.getByRole('textbox') as HTMLInputElement;
97-
expect(input.value).toEqual('Hello world!');
98-
});
99-
});

example/src/internals.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ test('returns composed parameters from story', () => {
1313
expect(StoryWithParamsAndDecorator.args).toEqual(stories.StoryWithParamsAndDecorator.args);
1414
expect(StoryWithParamsAndDecorator.parameters).toEqual({
1515
...stories.StoryWithParamsAndDecorator.parameters,
16-
...globalConfig.parameters,
17-
component: stories.default.component
16+
...globalConfig.parameters
1817
});
1918
expect(StoryWithParamsAndDecorator.decorators).toEqual([
2019
...stories.StoryWithParamsAndDecorator.decorators!,

0 commit comments

Comments
 (0)