2023-04-25 06:12:48 +03:00
|
|
|
import { test } from '@affine-test/kit/playwright';
|
2023-11-02 17:21:01 +03:00
|
|
|
import { getPagesCount } from '@affine-test/kit/utils/filter';
|
2023-07-13 12:05:01 +03:00
|
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
2023-09-02 06:31:07 +03:00
|
|
|
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
|
2023-07-13 12:05:01 +03:00
|
|
|
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
|
|
|
import {
|
2023-09-02 08:57:04 +03:00
|
|
|
createLocalWorkspace,
|
2023-07-13 12:05:01 +03:00
|
|
|
openWorkspaceListModal,
|
|
|
|
} from '@affine-test/kit/utils/workspace';
|
2023-02-06 17:26:01 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2023-02-17 10:33:32 +03:00
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
test('just one item in the workspace list at first', async ({
|
|
|
|
page,
|
|
|
|
workspace,
|
|
|
|
}) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
const workspaceName = page.getByTestId('workspace-name');
|
|
|
|
await workspaceName.click();
|
|
|
|
expect(
|
|
|
|
page
|
|
|
|
.locator('div')
|
|
|
|
.filter({ hasText: 'AFFiNE TestLocal WorkspaceAvailable Offline' })
|
|
|
|
.nth(3)
|
|
|
|
).not.toBeNull();
|
2023-07-13 15:41:46 +03:00
|
|
|
const currentWorkspace = await workspace.current();
|
|
|
|
|
2023-12-15 10:20:50 +03:00
|
|
|
expect(currentWorkspace.meta.flavour).toContain('local');
|
2023-04-17 00:02:41 +03:00
|
|
|
});
|
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
test('create one workspace in the workspace list', async ({
|
|
|
|
page,
|
|
|
|
workspace,
|
|
|
|
}) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
const newWorkspaceNameStr = 'New Workspace';
|
2023-09-02 08:57:04 +03:00
|
|
|
await createLocalWorkspace({ name: newWorkspaceNameStr }, page);
|
2023-04-17 00:02:41 +03:00
|
|
|
|
|
|
|
// 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
|
2023-08-17 01:18:43 +03:00
|
|
|
await page.keyboard.press('Escape');
|
2023-04-17 00:02:41 +03:00
|
|
|
await clickSideBarAllPageButton(page);
|
2023-10-27 12:06:59 +03:00
|
|
|
await page.waitForTimeout(2000);
|
2023-11-02 17:21:01 +03:00
|
|
|
const result = await getPagesCount(page);
|
2024-02-21 15:57:18 +03:00
|
|
|
expect(result).toBe(1);
|
2023-04-17 00:02:41 +03:00
|
|
|
await page.reload();
|
2023-10-27 12:06:59 +03:00
|
|
|
await page.waitForTimeout(4000);
|
2023-11-02 17:21:01 +03:00
|
|
|
const result1 = await getPagesCount(page);
|
2024-02-21 15:57:18 +03:00
|
|
|
expect(result1).toBe(1);
|
2023-07-13 15:41:46 +03:00
|
|
|
const currentWorkspace = await workspace.current();
|
|
|
|
|
2023-12-15 10:20:50 +03:00
|
|
|
expect(currentWorkspace.meta.flavour).toContain('local');
|
2023-04-17 00:02:41 +03:00
|
|
|
});
|
|
|
|
|
2024-04-30 17:57:38 +03:00
|
|
|
test.skip('create multi workspace in the workspace list', async ({
|
2023-07-13 15:41:46 +03:00
|
|
|
page,
|
|
|
|
workspace,
|
|
|
|
}) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await createLocalWorkspace({ name: 'New Workspace 2' }, page);
|
|
|
|
await createLocalWorkspace({ 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-08-30 02:21:18 +03:00
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
{
|
2024-04-15 08:31:32 +03:00
|
|
|
// check workspace list length
|
|
|
|
const workspaceCards = page.getByTestId('workspace-card');
|
|
|
|
await expect(workspaceCards).toHaveCount(3);
|
2023-04-17 00:02:41 +03:00
|
|
|
}
|
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();
|
2023-06-07 12:31:54 +03:00
|
|
|
await page.waitForTimeout(500);
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
const currentWorkspace = await workspace.current();
|
|
|
|
|
2023-12-15 10:20:50 +03:00
|
|
|
expect(currentWorkspace.meta.flavour).toContain('local');
|
2023-04-06 21:21:45 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await openWorkspaceListModal(page);
|
2023-08-17 01:18:43 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-06-07 12:31:54 +03:00
|
|
|
const sourceElement = page.getByTestId('draggable-item').nth(2);
|
|
|
|
const targetElement = 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();
|
2024-04-15 08:31:32 +03:00
|
|
|
|
|
|
|
// check workspace list order
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => {
|
|
|
|
const cards = document.querySelectorAll('[data-testid="workspace-card"]');
|
|
|
|
return (
|
|
|
|
cards[1].textContent?.includes('New Workspace 3') &&
|
|
|
|
cards[2].textContent?.includes('New Workspace 2')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
{ timeout: 5000 }
|
|
|
|
);
|
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await page.reload();
|
|
|
|
await openWorkspaceListModal(page);
|
|
|
|
|
2023-07-07 17:15:27 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-06-08 11:18:10 +03:00
|
|
|
// check workspace list length
|
2023-04-17 00:02:41 +03:00
|
|
|
{
|
2023-08-29 13:07:05 +03:00
|
|
|
const workspaceCards = page.getByTestId('workspace-card');
|
2024-04-15 08:31:32 +03:00
|
|
|
await expect(workspaceCards).toHaveCount(3);
|
2023-04-17 00:02:41 +03:00
|
|
|
}
|
|
|
|
|
2023-06-08 11:18:10 +03:00
|
|
|
const workspaceChangePromise = page.evaluate(() => {
|
|
|
|
new Promise(resolve => {
|
|
|
|
window.addEventListener('affine:workspace:change', resolve, {
|
|
|
|
once: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-04-17 00:02:41 +03:00
|
|
|
await page.getByTestId('draggable-item').nth(2).click();
|
2023-06-08 11:18:10 +03:00
|
|
|
await workspaceChangePromise;
|
2023-04-17 00:02:41 +03:00
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
const nextWorkspace = await workspace.current();
|
|
|
|
|
2023-12-15 10:20:50 +03:00
|
|
|
expect(currentWorkspace.meta.id).toBe(nextWorkspace.meta.id);
|
2023-02-06 17:26:01 +03:00
|
|
|
});
|