Skip to content

Commit

Permalink
fix(storybook): fix test (#5325)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Dec 18, 2023
1 parent a1c9ac8 commit cef9e05
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function AddPageButton({

return (
<button
data-testid="new-page-button"
data-testid="sidebar-new-page-button"
style={style}
className={clsx([styles.root, className])}
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export const NewPageButton = ({
>
<DropdownButton
size={size}
data-testid="new-page-button"
onClick={useCallback(() => {
createNewPage();
setOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const PageListHeader = () => {
return (
<div className={styles.allPagesHeader}>
<div className={styles.allPagesHeaderTitle}>{title}</div>
<NewPageButton>{t['New Page']()}</NewPageButton>
<NewPageButton testId="new-page-button-trigger">
{t['New Page']()}
</NewPageButton>
</div>
);
};
Expand Down Expand Up @@ -180,16 +182,18 @@ const NewPageButton = ({
className,
children,
size,
testId,
}: PropsWithChildren<{
className?: string;
size?: 'small' | 'default';
testId?: string;
}>) => {
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
const { importFile, createEdgeless, createPage } = usePageHelper(
currentWorkspace.blockSuiteWorkspace
);
return (
<div className={className}>
<div className={className} data-testid={testId}>
<PureNewPageButton
size={size}
importFile={importFile}
Expand Down
8 changes: 4 additions & 4 deletions tests/affine-desktop/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const historyShortcut = async (page: Page, command: 'goBack' | 'goForward') => {
};

test('new page', async ({ page, workspace }) => {
await page.getByTestId('new-page-button').click({
await page.getByTestId('sidebar-new-page-button').click({
delay: 100,
});
await page.waitForSelector('v-line');
Expand All @@ -32,7 +32,7 @@ test('app sidebar router forward/back', async ({ page }) => {
{
// create pages
await page.waitForTimeout(500);
await page.getByTestId('new-page-button').click({
await page.getByTestId('sidebar-new-page-button').click({
delay: 100,
});
await page.waitForSelector('v-line');
Expand All @@ -42,7 +42,7 @@ test('app sidebar router forward/back', async ({ page }) => {
delay: 100,
});
await page.waitForTimeout(500);
await page.getByTestId('new-page-button').click({
await page.getByTestId('sidebar-new-page-button').click({
delay: 100,
});
await page.waitForSelector('v-line');
Expand All @@ -52,7 +52,7 @@ test('app sidebar router forward/back', async ({ page }) => {
delay: 100,
});
await page.waitForTimeout(500);
await page.getByTestId('new-page-button').click({
await page.getByTestId('sidebar-new-page-button').click({
delay: 100,
});
await page.waitForSelector('v-line');
Expand Down
7 changes: 4 additions & 3 deletions tests/affine-local/e2e/all-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';

function getAllPage(page: Page) {
const newPageButton = page.getByTestId('new-page-button');
const newPageButton = page.getByTestId('new-page-button-trigger');
const newPageDropdown = newPageButton.locator('svg');
const edgelessBlockCard = page.getByTestId('switch-edgeless-mode-button');
const edgelessBlockCard = page.getByTestId('new-edgeless-button-in-all-page');

async function clickNewPageButton() {
return newPageButton.click();
const newPageButton = page.getByTestId('new-page-button-trigger');
return await newPageButton.click();
}

async function clickNewEdgelessDropdown() {
Expand Down
2 changes: 1 addition & 1 deletion tests/kit/utils/page-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function waitForAllPagesLoad(page: Page) {

export async function clickNewPageButton(page: Page) {
// fixme(himself65): if too fast, the page will crash
await page.getByTestId('new-page-button').first().click({
await page.getByTestId('sidebar-new-page-button').click({
delay: 100,
});
await waitForEditorLoad(page);
Expand Down
2 changes: 1 addition & 1 deletion tests/kit/utils/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export async function clickSideBarCurrentWorkspaceBanner(page: Page) {
}

export async function clickNewPageButton(page: Page) {
return page.getByTestId('new-page-button').click();
return page.getByTestId('sidebar-new-page-button').click();
}
1 change: 1 addition & 0 deletions tests/storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ bootstrapPluginSystem(store).catch(err => {
workspaceManager
.createWorkspace(WorkspaceFlavour.LOCAL, async w => {
w.meta.setName('test-workspace');
w.meta.writeVersion(w);
})
.then(id => {
store.set(
Expand Down
40 changes: 23 additions & 17 deletions tests/storybook/src/stories/core.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export const SettingPage: StoryFn = () => {
};
SettingPage.play = async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
await waitFor(
() => {
assertExists(canvasElement.querySelector('v-line'));
},
{
timeout: 10000,
}
);
await waitFor(async () => {
assertExists(
document.body.querySelector(
'[data-testid="slider-bar-workspace-setting-button"]'
)
);
});
await step('click setting modal button', async () => {
await userEvent.click(canvas.getByTestId('settings-modal-trigger'));
await userEvent.click(
canvas.getByTestId('slider-bar-workspace-setting-button')
);
});
await waitFor(async () => {
assertExists(
Expand Down Expand Up @@ -120,14 +121,13 @@ export const SearchPage: StoryFn = () => {
};
SearchPage.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await waitFor(
() => {
assertExists(canvasElement.querySelector('v-line'));
},
{
timeout: 10000,
}
);
await waitFor(async () => {
assertExists(
document.body.querySelector(
'[data-testid="slider-bar-quick-search-button"]'
)
);
});
await userEvent.click(canvas.getByTestId('slider-bar-quick-search-button'));
await waitFor(
() => {
Expand All @@ -153,6 +153,12 @@ export const ImportPage: StoryFn = () => {
};
ImportPage.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await waitFor(async () => {
assertExists(
document.body.querySelector('[data-testid="sidebar-new-page-button"]')
);
});
await userEvent.click(canvas.getByTestId('sidebar-new-page-button'));
await waitFor(
() => {
assertExists(canvasElement.querySelector('v-line'));
Expand Down

0 comments on commit cef9e05

Please sign in to comment.