test: add workspace ref in e2e (#3217)

This commit is contained in:
Alex Yang 2023-07-13 20:41:46 +08:00 committed by GitHub
parent 64cf297399
commit d18df12951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 140 additions and 101 deletions

View File

@ -26,10 +26,6 @@ export const test = base.extend<{
appData: string;
sessionData: string;
};
workspace: {
// get current workspace
current: () => Promise<any>; // todo: type
};
router: {
goto: (path: RoutePath) => Promise<void>;
};
@ -121,14 +117,4 @@ export const test = base.extend<{
});
await use(appInfo);
},
workspace: async ({ page }, use) => {
await use({
current: async () => {
return await page.evaluate(async () => {
// @ts-expect-error
return globalThis.currentWorkspace;
});
},
});
},
});

View File

@ -1,8 +0,0 @@
import { test } from '@affine-test/kit/playwright';
import { expect } from '@playwright/test';
test('the link has expired', async ({ page }) => {
await page.goto('http://localhost:8080//invite/abc');
await page.waitForTimeout(1000);
expect(page.getByText('The link has expired')).not.toBeUndefined();
});

View File

@ -3,10 +3,12 @@ import { resolve } from 'node:path';
import { rootDir, test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { newPage, waitEditorLoad } from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('should create a page with a local first avatar', async ({ page }) => {
test('should create a page with a local first avatar', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -35,5 +37,7 @@ test('should create a page with a local first avatar', async ({ page }) => {
.getAttribute('src');
// out user uploaded avatar
expect(blobUrl).toContain('blob:');
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -111,6 +111,7 @@ test('edit collection', async ({ page }) => {
await page.waitForTimeout(100);
expect(await first.textContent()).toBe('123');
});
test('edit collection and change filter date', async ({ page }) => {
await createAndPinCollection(page);
const collections = page.getByTestId('collections');

View File

@ -5,11 +5,11 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('New a page , then delete it in all pages, permanently delete it', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
@ -50,5 +50,7 @@ test('New a page , then delete it in all pages, permanently delete it', async ({
'Tips: Click Add to Favorites/Trash and the page will appear here.'
)
).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -4,10 +4,9 @@ import { waitEditorLoad } from '@affine-test/kit/utils/page-logic';
import { openWorkspaceSettingPanel } from '@affine-test/kit/utils/setting';
import { openSettingModal } from '@affine-test/kit/utils/setting';
import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('Create new workspace, then delete it', async ({ page }) => {
test('Create new workspace, then delete it', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await clickSideBarCurrentWorkspaceBanner(page);
@ -43,7 +42,9 @@ test('Create new workspace, then delete it', async ({ page }) => {
expect(await page.getByTestId('workspace-name').textContent()).toBe(
'Demo Workspace'
);
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('Delete last workspace', async ({ page }) => {

View File

@ -6,10 +6,12 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test.skip('New a page ,then open it and export html', async ({ page }) => {
test.skip('New a page ,then open it and export html', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -37,9 +39,15 @@ test.skip('New a page ,then open it and export html', async ({ page }) => {
expect(download.suggestedFilename()).toBe(
'this is a new page to export html content.html'
);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test.skip('New a page ,then open it and export markdown', async ({ page }) => {
test.skip('New a page ,then open it and export markdown', async ({
page,
workspace,
}) => {
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
await page
@ -64,5 +72,7 @@ test.skip('New a page ,then open it and export markdown', async ({ page }) => {
expect(download.suggestedFilename()).toBe(
'this is a new page to export markdown content.md'
);
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -7,10 +7,12 @@ import {
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { waitForLogMessage } from '@affine-test/kit/utils/utils';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('New a page and open it ,then favorite it', async ({ page }) => {
test('New a page and open it ,then favorite it', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -26,7 +28,9 @@ test('New a page and open it ,then favorite it', async ({ page }) => {
await clickPageMoreActions(page);
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('Export to html, markdown and png', async ({ page }) => {
@ -74,7 +78,7 @@ test.skip('Export to pdf', async ({ page }) => {
}
});
test('Cancel favorite', async ({ page }) => {
test('Cancel favorite', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -115,5 +119,7 @@ test('Cancel favorite', async ({ page }) => {
'Tips: Click Add to Favorites/Trash and the page will appear here.'
)
).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -9,7 +9,7 @@ import {
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
test('Show favorite items in sidebar', async ({ page }) => {
test('Show favorite items in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -32,9 +32,12 @@ test('Show favorite items in sidebar', async ({ page }) => {
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('Show favorite reference in sidebar', async ({ page }) => {
test('Show favorite reference in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -69,10 +72,14 @@ test('Show favorite reference in sidebar', async ({ page }) => {
await expect(
page.locator('[data-type="favorite-list-item"] >> text=Another page')
).toBeVisible();
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test("Deleted page's reference will not be shown in sidebar", async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
@ -116,4 +123,7 @@ test("Deleted page's reference will not be shown in sidebar", async ({
);
await expect(collapseButton).not.toBeVisible();
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -5,20 +5,24 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('click btn new page', async ({ page }) => {
test('click btn new page', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
const originPageId = page.url().split('/').reverse()[0];
await newPage(page);
const newPageId = page.url().split('/').reverse()[0];
expect(newPageId).not.toBe(originPageId);
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('click btn bew page and find it in all pages', async ({ page }) => {
test('click btn bew page and find it in all pages', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -27,5 +31,7 @@ test('click btn bew page and find it in all pages', async ({ page }) => {
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', { name: 'this is a new page' });
expect(cell).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -5,10 +5,9 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('click btn bew page and open in tab', async ({ page }) => {
test('click btn bew page and open in tab', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -30,5 +29,7 @@ test('click btn bew page and open in tab', async ({ page }) => {
]);
expect(newTabPage.url()).toBe(newPageUrl);
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -5,11 +5,11 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('New a page , then delete it in all pages, restore it', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
@ -52,5 +52,7 @@ test('New a page , then delete it in all pages, restore it', async ({
name: 'this is a new page to restore',
});
expect(restoreCell).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -6,10 +6,12 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('New a page ,then open it and show delete modal', async ({ page }) => {
test('New a page ,then open it and show delete modal', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
@ -27,11 +29,14 @@ test('New a page ,then open it and show delete modal', async ({ page }) => {
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');
expect(confirmTip).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('New a page ,then go to all pages and show delete modal', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
@ -54,5 +59,7 @@ test('New a page ,then go to all pages and show delete modal', async ({
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');
expect(confirmTip).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -5,11 +5,11 @@ import {
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('New a page , then delete it in all pages, finally find it in trash', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
@ -39,5 +39,7 @@ test('New a page , then delete it in all pages, finally find it in trash', async
expect(
page.getByRole('cell', { name: 'this is a new page to delete' })
).not.toBeUndefined();
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -8,7 +8,10 @@ import {
} from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('just one item in the workspace list at first', async ({ page }) => {
test('just one item in the workspace list at first', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
const workspaceName = page.getByTestId('workspace-name');
@ -19,9 +22,15 @@ test('just one item in the workspace list at first', async ({ page }) => {
.filter({ hasText: 'AFFiNE TestLocal WorkspaceAvailable Offline' })
.nth(3)
).not.toBeNull();
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('create one workspace in the workspace list', async ({ page }) => {
test('create one workspace in the workspace list', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
const newWorkspaceNameStr = 'New Workspace';
@ -48,9 +57,15 @@ test('create one workspace in the workspace list', async ({ page }) => {
const pageList1 = page.locator('[data-testid=page-list-item]');
const result1 = await pageList1.count();
expect(result1).toBe(0);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('create multi workspace in the workspace list', async ({ page }) => {
test('create multi workspace in the workspace list', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await createWorkspace({ name: 'New Workspace 2' }, page);
@ -71,8 +86,9 @@ test('create multi workspace in the workspace list', async ({ page }) => {
await page.getByTestId('draggable-item').nth(1).click();
await page.waitForTimeout(500);
// @ts-expect-error
const currentId: string = await page.evaluate(() => currentWorkspace.id);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
await openWorkspaceListModal(page);
const sourceElement = page.getByTestId('draggable-item').nth(2);
@ -122,7 +138,7 @@ test('create multi workspace in the workspace list', async ({ page }) => {
await page.getByTestId('draggable-item').nth(2).click();
await workspaceChangePromise;
// @ts-expect-error
const nextId: string = await page.evaluate(() => currentWorkspace.id);
expect(currentId).toBe(nextId);
const nextWorkspace = await workspace.current();
expect(currentWorkspace.id).toBe(nextWorkspace.id);
});

View File

@ -1,25 +1,20 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitEditorLoad } from '@affine-test/kit/utils/page-logic';
import { assertCurrentWorkspaceFlavour } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('preset workspace name', async ({ page }) => {
test('preset workspace name', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
const workspaceName = page.getByTestId('workspace-name');
await page.waitForTimeout(1000);
expect(await workspaceName.textContent()).toBe('Demo Workspace');
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
// test('default workspace avatar', async ({ page }) => {
// const workspaceAvatar = page.getByTestId('workspace-avatar');
// expect(
// await workspaceAvatar.locator('img').getAttribute('src')
// ).not.toBeNull();
// });
test('Open language switch menu', async ({ page }) => {
test('Open language switch menu', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
const editorOptionMenuButton = page.getByTestId('editor-option-menu');
@ -29,5 +24,7 @@ test('Open language switch menu', async ({ page }) => {
await expect(languageMenuButton).toBeVisible();
const actual = await languageMenuButton.innerText();
expect(actual).toEqual('English');
await assertCurrentWorkspaceFlavour('local', page);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});

View File

@ -4,6 +4,7 @@ import fs from 'node:fs';
import path, { resolve } from 'node:path';
import process from 'node:process';
import type { Workspace } from '@blocksuite/store';
import { test as baseTest } from '@playwright/test';
export const rootDir = resolve(__dirname, '..', '..');
@ -26,7 +27,26 @@ function generateUUID() {
export const enableCoverage = !!process.env.CI || !!process.env.COVERAGE;
export const test = baseTest.extend({
type CurrentWorkspace = {
id: string;
flavour: string;
blockSuiteWorkspace: Workspace;
};
export const test = baseTest.extend<{
workspace: {
current: () => Promise<CurrentWorkspace>;
};
}>({
workspace: async ({ page }, use) => {
await use({
current: async () => {
return await page.evaluate(async () => {
return (globalThis as any).currentWorkspace;
});
},
});
},
context: async ({ context }, use) => {
if (enableCoverage) {
await context.addInitScript(() =>

View File

@ -1,8 +1,4 @@
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
import { clickCollaborationPanel } from './setting';
import { clickSideBarSettingButton } from './sidebar';
interface CreateWorkspaceParams {
name: string;
@ -29,23 +25,3 @@ export async function createWorkspace(
// click create button
return page.getByRole('button', { name: 'Create' }).click();
}
export async function assertCurrentWorkspaceFlavour(
flavour: 'affine' | 'local',
page: Page
) {
// @ts-expect-error
const actual = await page.evaluate(() => globalThis.currentWorkspace.flavour);
expect(actual).toBe(flavour);
}
export async function enableAffineCloudWorkspace(page: Page) {
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickCollaborationPanel(page);
await page.getByTestId('local-workspace-enable-cloud-button').click();
await page.getByTestId('confirm-enable-cloud-button').click();
await page.waitForSelector("[data-testid='member-length']", {
timeout: 20000,
});
}