feat(storybook): avoid refresh (#3841)

This commit is contained in:
Alex Yang 2023-08-19 12:30:24 -05:00 committed by GitHub
parent 37c1d9bab1
commit 956cde308e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 17 deletions

View File

@ -52,15 +52,21 @@ const ThemeChange = () => {
return null; return null;
}; };
const storeMap = new Map<string, ReturnType<typeof createStore>>();
const withContextDecorator: Decorator = (Story, context) => { const withContextDecorator: Decorator = (Story, context) => {
const { data: store } = useSWR( const { data: store } = useSWR(
context.id, context.id,
async () => { async () => {
if (storeMap.has(context.id)) {
return storeMap.get(context.id);
}
localStorage.clear(); localStorage.clear();
const store = createStore(); const store = createStore();
_setCurrentStore(store); _setCurrentStore(store);
await setup(store); await setup(store);
await bootstrapPluginSystem(store); await bootstrapPluginSystem(store);
storeMap.set(context.id, store);
return store; return store;
}, },
{ {

View File

@ -1,7 +1,7 @@
import { routes } from '@affine/core/router'; import { routes } from '@affine/core/router';
import { assertExists } from '@blocksuite/global/utils'; import { assertExists } from '@blocksuite/global/utils';
import type { StoryFn } from '@storybook/react'; import type { StoryFn } from '@storybook/react';
import { userEvent, waitFor } from '@storybook/testing-library'; import { userEvent, waitFor, within } from '@storybook/testing-library';
import { Outlet, useLocation } from 'react-router-dom'; import { Outlet, useLocation } from 'react-router-dom';
import { import {
reactRouterOutlets, reactRouterOutlets,
@ -35,21 +35,26 @@ Index.parameters = {
export const SettingPage: StoryFn = () => { export const SettingPage: StoryFn = () => {
return <FakeApp />; return <FakeApp />;
}; };
SettingPage.play = async ({ canvasElement }) => { SettingPage.play = async ({ canvasElement, step }) => {
await waitFor( const canvas = within(canvasElement);
() => { await waitFor(async () => {
assertExists( assertExists(canvasElement.querySelector('v-line'));
canvasElement.querySelector('[data-testid="settings-modal-trigger"]') });
); await step('click setting modal button', async () => {
}, await userEvent.click(canvas.getByTestId('settings-modal-trigger'));
{ });
timeout: 5000, await waitFor(async () => {
} assertExists(
); document.body.querySelector('[data-testid="language-menu-button"]')
const settingModalBtn = canvasElement.querySelector( );
'[data-testid="settings-modal-trigger"]' });
) as Element; await step('click language menu button', async () => {
await userEvent.click(settingModalBtn); await userEvent.click(
document.body.querySelector(
'[data-testid="language-menu-button"]'
) as HTMLElement
);
});
}; };
SettingPage.decorators = [withRouter]; SettingPage.decorators = [withRouter];
SettingPage.parameters = { SettingPage.parameters = {

View File

@ -8,5 +8,6 @@
"module": "NodeNext", "module": "NodeNext",
"resolveJsonModule": true "resolveJsonModule": true
}, },
"include": [".", "./*.json"] "include": [".", "./*.json"],
"exclude": ["./tsconfig.json"]
} }