mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-24 11:24:08 +03:00
feat(storybook): avoid refresh (#3841)
This commit is contained in:
parent
37c1d9bab1
commit
956cde308e
@ -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;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -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 = {
|
||||||
|
3
tests/fixtures/tsconfig.json
vendored
3
tests/fixtures/tsconfig.json
vendored
@ -8,5 +8,6 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": [".", "./*.json"]
|
"include": [".", "./*.json"],
|
||||||
|
"exclude": ["./tsconfig.json"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user