feat: add e2e test for creating multi workspaces

This commit is contained in:
tzhangchi 2023-02-06 22:26:01 +08:00
parent 274505590c
commit 9548cc1ed1
4 changed files with 66 additions and 0 deletions

View File

@ -23,6 +23,7 @@ export const WorkspaceCard = ({
const { t } = useTranslation();
return (
<StyledCard
data-testid="workspace-card"
onClick={() => {
onClick(workspaceData);
}}

View File

@ -17,6 +17,7 @@ const config: PlaywrightTestConfig = {
browserName: 'chromium',
viewport: { width: 1440, height: 800 },
actionTimeout: 5 * 1000,
locale: 'en-US',
// 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`)
// or in your browser on [Playwright Trace Viewer](https://trace.playwright.dev/).

View File

@ -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);
}

View File

@ -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);
});
});