2023-04-25 06:12:48 +03:00
|
|
|
import { test } from '@affine-test/kit/playwright';
|
2023-02-06 17:26:01 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2023-02-17 10:33:32 +03:00
|
|
|
|
2023-03-24 01:15:40 +03:00
|
|
|
import { openHomePage } from '../libs/load-page';
|
2023-03-28 08:25:16 +03:00
|
|
|
import { waitMarkdownImported } from '../libs/page-logic';
|
2023-03-24 01:15:40 +03:00
|
|
|
import { clickSideBarAllPageButton } from '../libs/sidebar';
|
2023-04-06 21:21:45 +03:00
|
|
|
import { createWorkspace, openWorkspaceListModal } from '../libs/workspace';
|
2023-02-06 17:26:01 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('just one item in the workspace list at first', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitMarkdownImported(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 }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitMarkdownImported(page);
|
|
|
|
const newWorkspaceNameStr = 'New Workspace';
|
|
|
|
await createWorkspace({ name: newWorkspaceNameStr }, page);
|
|
|
|
|
|
|
|
// check new workspace name
|
|
|
|
const newWorkspaceName = page.getByTestId('workspace-name');
|
|
|
|
await newWorkspaceName.click();
|
|
|
|
|
|
|
|
//check workspace list length
|
|
|
|
const workspaceCards = await page.$$('data-testid=workspace-card');
|
|
|
|
expect(workspaceCards.length).toBe(2);
|
|
|
|
|
|
|
|
//check page list length
|
|
|
|
const closeWorkspaceModal = page.getByTestId('close-workspace-modal');
|
|
|
|
await closeWorkspaceModal.click();
|
|
|
|
await clickSideBarAllPageButton(page);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
const pageList = page.locator('[data-testid=page-list-item]');
|
|
|
|
const result = await pageList.count();
|
|
|
|
expect(result).toBe(0);
|
|
|
|
await page.reload();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
const pageList1 = page.locator('[data-testid=page-list-item]');
|
|
|
|
const result1 = await pageList1.count();
|
|
|
|
expect(result1).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('create multi workspace in the workspace list', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitMarkdownImported(page);
|
|
|
|
await createWorkspace({ name: 'New Workspace 2' }, page);
|
|
|
|
await createWorkspace({ name: 'New Workspace 3' }, page);
|
2023-02-08 12:48:03 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
// show workspace list
|
|
|
|
const workspaceName = page.getByTestId('workspace-name');
|
|
|
|
await workspaceName.click();
|
|
|
|
|
|
|
|
{
|
2023-02-08 12:48:03 +03:00
|
|
|
//check workspace list length
|
|
|
|
const workspaceCards = await page.$$('data-testid=workspace-card');
|
2023-04-17 00:02:41 +03:00
|
|
|
expect(workspaceCards.length).toBe(3);
|
|
|
|
}
|
2023-02-06 17:26:01 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await page.reload();
|
|
|
|
await openWorkspaceListModal(page);
|
|
|
|
await page.getByTestId('draggable-item').nth(1).click();
|
|
|
|
await page.waitForTimeout(50);
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
// @ts-expect-error
|
|
|
|
const currentId: string = await page.evaluate(() => currentWorkspace.id);
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await openWorkspaceListModal(page);
|
|
|
|
const sourceElement = await page.getByTestId('draggable-item').nth(2);
|
|
|
|
const targetElement = await page.getByTestId('draggable-item').nth(1);
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
const sourceBox = await sourceElement.boundingBox();
|
|
|
|
const targetBox = await targetElement.boundingBox();
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
if (!sourceBox || !targetBox) {
|
|
|
|
throw new Error('sourceBox or targetBox is null');
|
|
|
|
}
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await page.mouse.move(
|
|
|
|
sourceBox.x + sourceBox.width / 2,
|
|
|
|
sourceBox.y + sourceBox.height / 2,
|
|
|
|
{
|
|
|
|
steps: 5,
|
2023-04-06 21:21:45 +03:00
|
|
|
}
|
2023-04-17 00:02:41 +03:00
|
|
|
);
|
|
|
|
await page.mouse.down();
|
|
|
|
await page.mouse.move(
|
|
|
|
targetBox.x + targetBox.width / 2,
|
|
|
|
targetBox.y + targetBox.height / 2,
|
2023-04-06 21:21:45 +03:00
|
|
|
{
|
2023-04-17 00:02:41 +03:00
|
|
|
steps: 5,
|
2023-04-06 21:21:45 +03:00
|
|
|
}
|
2023-04-17 00:02:41 +03:00
|
|
|
);
|
|
|
|
await page.mouse.up();
|
|
|
|
await page.waitForTimeout(50);
|
|
|
|
await page.reload();
|
|
|
|
await openWorkspaceListModal(page);
|
|
|
|
|
|
|
|
//check workspace list length
|
|
|
|
{
|
|
|
|
const workspaceCards1 = await page.$$('data-testid=workspace-card');
|
|
|
|
expect(workspaceCards1.length).toBe(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
await page.getByTestId('draggable-item').nth(2).click();
|
|
|
|
|
|
|
|
// @ts-expect-error
|
|
|
|
const nextId: string = await page.evaluate(() => currentWorkspace.id);
|
|
|
|
expect(currentId).toBe(nextId);
|
2023-02-06 17:26:01 +03:00
|
|
|
});
|