Skip to content

Commit f074f0c

Browse files
committed
fix(eslint-config-fuf): add test for storybook rules order
1 parent a705353 commit f074f0c

File tree

4 files changed

+136
-4
lines changed

4 files changed

+136
-4
lines changed

packages/eslint-config-fuf/react.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export default [
2525
// Strict React Config
2626
rules.react.strict,
2727

28-
// FUF React Configs
29-
fufReact,
30-
fufStorybook,
31-
3228
// Ensure FUF base rules have final precedence over upstream configs
3329
...baseConfig,
30+
31+
// FUF React Config must come after base to override rules for React files
32+
fufReact,
33+
// FUF Storybook Config must come after base to override rules for story files
34+
fufStorybook,
3435
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// This fixture tests that storybook-specific rules are properly disabled
2+
3+
/* eslint-disable import-x/no-unresolved */
4+
// Disable import-x/no-unresolved since Storybook packages aren't installed
5+
// But we want to test with real Storybook imports that users would use
6+
import type { Meta, StoryObj } from '@storybook/react';
7+
8+
import { action } from '@storybook/addon-actions';
9+
import { expect, userEvent, waitFor, within } from '@storybook/test';
10+
/* eslint-enable import-x/no-unresolved */
11+
12+
// Test that import-x/no-extraneous-dependencies is disabled for devDependencies
13+
// tailwindcss is a devDependency and would normally trigger an error in production code
14+
import tailwindPlugin from 'tailwindcss/plugin';
15+
16+
import Button from './support/Button';
17+
18+
// just to avoid unused variable error
19+
const _customPlugin = tailwindPlugin(() => {
20+
return null;
21+
}, {});
22+
23+
const meta: Meta<typeof Button> = {
24+
title: 'Button',
25+
component: Button,
26+
};
27+
28+
export default meta;
29+
type Story = StoryObj<typeof Button>;
30+
31+
export const WithPropSpreading: Story = {
32+
render: (args) => {
33+
return <Button {...args} />;
34+
},
35+
args: {
36+
label: 'Button',
37+
},
38+
};
39+
40+
export const Primary: Story = {
41+
args: {
42+
primary: true,
43+
label: 'Button',
44+
onClick: action('button-clicked'),
45+
},
46+
};
47+
48+
// Test that Storybook testing utilities work in play functions
49+
export const WithInteraction: Story = {
50+
args: {
51+
primary: true,
52+
label: 'Click me',
53+
},
54+
play: async ({ canvasElement }) => {
55+
const canvas = within(canvasElement);
56+
const button = canvas.getByRole('button');
57+
58+
await waitFor(() => {
59+
expect(button).toBeInTheDocument();
60+
});
61+
await userEvent.click(button);
62+
await expect(button).toHaveTextContent('Click me');
63+
},
64+
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* eslint-disable */
2+
3+
// This fixture tests that storybook-specific rules are properly disabled
4+
5+
/* eslint-disable import-x/no-unresolved */
6+
// Disable import-x/no-unresolved since Storybook packages aren't installed
7+
// But we want to test with real Storybook imports that users would use
8+
import type { Meta, StoryObj } from '@storybook/react';
9+
10+
import { action } from '@storybook/addon-actions';
11+
import { expect, userEvent, waitFor, within } from '@storybook/test';
12+
/* eslint-enable import-x/no-unresolved */
13+
14+
// Test that import-x/no-extraneous-dependencies is disabled for devDependencies
15+
// tailwindcss is a devDependency and would normally trigger an error in production code
16+
import tailwindPlugin from 'tailwindcss/plugin';
17+
18+
import Button from './support/Button';
19+
20+
// just to avoid unused variable error
21+
const _customPlugin = tailwindPlugin(() => {
22+
return null;
23+
}, {});
24+
25+
const meta: Meta<typeof Button> = {
26+
title: 'Button',
27+
component: Button,
28+
};
29+
30+
export default meta;
31+
type Story = StoryObj<typeof Button>;
32+
33+
export const WithPropSpreading: Story = {
34+
render: (args) => {
35+
return <Button {...args} />;
36+
},
37+
args: {
38+
label: 'Button',
39+
},
40+
};
41+
42+
export const Primary: Story = {
43+
args: {
44+
primary: true,
45+
label: 'Button',
46+
onClick: action('button-clicked'),
47+
},
48+
};
49+
50+
// Test that Storybook testing utilities work in play functions
51+
export const WithInteraction: Story = {
52+
args: {
53+
primary: true,
54+
label: 'Click me',
55+
},
56+
play: async ({ canvasElement }) => {
57+
const canvas = within(canvasElement);
58+
const button = canvas.getByRole('button');
59+
60+
await waitFor(() => {
61+
expect(button).toBeInTheDocument();
62+
});
63+
await userEvent.click(button);
64+
await expect(button).toHaveTextContent('Click me');
65+
},
66+
};

0 commit comments

Comments
 (0)