mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
feat: add e2e test for creating multi workspaces
This commit is contained in:
@@ -23,6 +23,7 @@ export const WorkspaceCard = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<StyledCard
|
<StyledCard
|
||||||
|
data-testid="workspace-card"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onClick(workspaceData);
|
onClick(workspaceData);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const config: PlaywrightTestConfig = {
|
|||||||
browserName: 'chromium',
|
browserName: 'chromium',
|
||||||
viewport: { width: 1440, height: 800 },
|
viewport: { width: 1440, height: 800 },
|
||||||
actionTimeout: 5 * 1000,
|
actionTimeout: 5 * 1000,
|
||||||
|
locale: 'en-US',
|
||||||
// Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer
|
// Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer
|
||||||
// You can open traces locally(`npx playwright show-trace trace.zip`)
|
// You can open traces locally(`npx playwright show-trace trace.zip`)
|
||||||
// or in your browser on [Playwright Trace Viewer](https://trace.playwright.dev/).
|
// or in your browser on [Playwright Trace Viewer](https://trace.playwright.dev/).
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { Page } from '@playwright/test';
|
||||||
|
interface CreateWorkspaceParams {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
export async function createWorkspace(
|
||||||
|
params: CreateWorkspaceParams,
|
||||||
|
page: Page
|
||||||
|
) {
|
||||||
|
// open workspace list modal
|
||||||
|
const workspaceName = page.getByTestId('workspace-name');
|
||||||
|
await workspaceName.click();
|
||||||
|
|
||||||
|
// open create workspace modal
|
||||||
|
await page.locator('.add-icon').click();
|
||||||
|
|
||||||
|
// input workspace name
|
||||||
|
await page.getByPlaceholder('Set a Workspace name').click();
|
||||||
|
await page.getByPlaceholder('Set a Workspace name').fill(params.name);
|
||||||
|
|
||||||
|
// click create button
|
||||||
|
await page.getByRole('button', { name: 'Create' }).click();
|
||||||
|
|
||||||
|
return page.waitForTimeout(300);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { expect } from '@playwright/test';
|
||||||
|
import { test } from './libs/playwright.js';
|
||||||
|
import { loadPage } from './libs/load-page.js';
|
||||||
|
import { createWorkspace } from './libs/workspace-logic.js';
|
||||||
|
loadPage();
|
||||||
|
|
||||||
|
test.describe('Local first workspace list', () => {
|
||||||
|
test('just one item in the workspace list at first', async ({ page }) => {
|
||||||
|
const workspaceName = page.getByTestId('workspace-name');
|
||||||
|
await workspaceName.click();
|
||||||
|
expect(
|
||||||
|
page
|
||||||
|
.locator('div')
|
||||||
|
.filter({ hasText: 'AFFiNE TestLocal WorkspaceAvailable Offline' })
|
||||||
|
.nth(3)
|
||||||
|
).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('create one workspace in the workspace list', async ({ page }) => {
|
||||||
|
const newWorkspaceNameStr = 'New Workspace';
|
||||||
|
await createWorkspace({ name: newWorkspaceNameStr }, page);
|
||||||
|
|
||||||
|
// check new workspace name
|
||||||
|
const newWorkspaceName = page.getByTestId('workspace-name');
|
||||||
|
expect(await newWorkspaceName.textContent()).toBe(newWorkspaceNameStr);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('create multi workspace in the workspace list', async ({ page }) => {
|
||||||
|
await createWorkspace({ name: 'New Workspace 2' }, page);
|
||||||
|
await createWorkspace({ name: 'New Workspace 3' }, page);
|
||||||
|
|
||||||
|
// show workspace list
|
||||||
|
const workspaceName = page.getByTestId('workspace-name');
|
||||||
|
await workspaceName.click();
|
||||||
|
|
||||||
|
//check workspace list length
|
||||||
|
const workspaceCards = await page.$$('data-testid=workspace-card');
|
||||||
|
expect(workspaceCards.length).toBe(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user