test: cover share page e2e (#4126)

This commit is contained in:
Alex Yang
2023-09-02 00:57:04 -05:00
committed by GitHub
parent 8825678ca9
commit 4f97ea8a5d
27 changed files with 186 additions and 99 deletions

View File

@@ -48,7 +48,11 @@ export class PermissionService {
return true;
} else {
// check if this is a public subpage
return subpages.map(page => `space:${page}`).includes(id);
// why use `endsWith`?
// because there might have `${wsId}:space:${subpageId}`,
// but subpages only have `${subpageId}`
return subpages.some(subpage => id.endsWith(subpage));
}
}
}

View File

@@ -9,6 +9,7 @@ import type { Page } from '@blocksuite/store';
import { Button } from '@toeverything/components/button';
import { Divider } from '@toeverything/components/divider';
import { useAtom } from 'jotai';
import { useCallback } from 'react';
import { Menu } from '../../ui/menu/menu';
import * as styles from './index.css';
@@ -62,15 +63,15 @@ export const ShareMenu = (props: ShareMenuProps) => {
trigger={['click']}
width={410}
disablePortal={true}
onClickAway={() => {
onClickAway={useCallback(() => {
setOpen(false);
}}
}, [setOpen])}
>
<Button
data-testid="share-menu-button"
onClick={() => {
setOpen(!open);
}}
onClick={useCallback(() => {
setOpen(value => !value);
}, [setOpen])}
type={'plain'}
>
<div

View File

@@ -132,13 +132,18 @@ export const AffineSharePage = (props: ShareMenuProps) => {
readOnly
/>
{isPublic ? (
<Button onClick={onClickCopyLink} style={{ padding: '4px 12px' }}>
<Button
onClick={onClickCopyLink}
data-testid="share-menu-copy-link-button"
style={{ padding: '4px 12px' }}
>
{t.Copy()}
</Button>
) : (
<Button
onClick={onClickCreateLink}
type="primary"
data-testid="share-menu-create-link-button"
style={{ padding: '4px 12px' }}
>
{t.Create()}

View File

@@ -0,0 +1,70 @@
import { test } from '@affine-test/kit/playwright';
import { createRandomUser, loginUser } from '@affine-test/kit/utils/cloud';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
let user: {
name: string;
email: string;
password: string;
};
test.beforeEach(async () => {
user = await createRandomUser();
});
test.beforeEach(async ({ page }) => {
await loginUser(page, user);
});
test.describe('collaboration', () => {
test('can enable share page', async ({ page, browser }) => {
await page.reload();
await waitForEditorLoad(page);
await createLocalWorkspace(
{
name: 'test',
},
page
);
await clickSideBarSettingButton(page);
await page.getByTestId('current-workspace-label').click();
await page.getByTestId('publish-enable-affine-cloud-button').click();
await page.getByTestId('confirm-enable-affine-cloud-button').click();
// wait for upload and delete local workspace
await page.waitForTimeout(2000);
await waitForEditorLoad(page);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.type('TEST TITLE', {
delay: 50,
});
await page.keyboard.press('Enter', { delay: 50 });
await page.keyboard.type('TEST CONTENT', { delay: 50 });
await page.getByTestId('share-menu-button').click();
await page.getByTestId('share-menu-create-link-button').click();
await page.getByTestId('share-menu-copy-link-button').click();
// check share page is accessible
{
const context = await browser.newContext();
const url: string = await page.evaluate(() =>
navigator.clipboard.readText()
);
const page2 = await context.newPage();
await page2.goto(url);
await waitForEditorLoad(page2);
const title = getBlockSuiteEditorTitle(page2);
expect(await title.innerText()).toBe('TEST TITLE');
expect(await page2.textContent('affine-paragraph')).toContain(
'TEST CONTENT'
);
}
});
});

View File

@@ -1,7 +1,10 @@
import { resolve } from 'node:path';
import { test } from '@affine-test/kit/playwright';
import { newPage, waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import {
clickNewPageButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import {
check8080Available,
setupProxyServer,
@@ -17,7 +20,7 @@ test('init page', async ({ page, context }) => {
await check8080Available(context);
await page.goto('http://localhost:8081/');
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const locator = page.locator('v-line').nth(0);
await locator.fill('hello');

View File

@@ -15,8 +15,8 @@ import {
} from '@affine-test/kit/utils/filter';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForAllPagesLoad,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
@@ -88,7 +88,7 @@ test('allow creation of filters by favorite', async ({ page }) => {
test('allow creation of filters by created time', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();
@@ -123,7 +123,7 @@ test('creation of filters by created time, then click date picker to modify the
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();

View File

@@ -1,8 +1,8 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import type { Page } from '@playwright/test';
@@ -20,7 +20,7 @@ const addDatabase = async (page: Page) => {
test('database is useable', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
const title = getBlockSuiteEditorTitle(page);
await title.type('test title');
@@ -31,7 +31,7 @@ test('database is useable', async ({ page }) => {
await expect(database).toBeVisible();
await page.reload();
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
const title2 = getBlockSuiteEditorTitle(page);
await title2.type('test title2');
@@ -46,13 +46,13 @@ test('database is useable', async ({ page }) => {
test('link page is useable', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
const title = await getBlockSuiteEditorTitle(page);
await title.type('page1');
await page.keyboard.press('Enter');
expect(await title.innerText()).toBe('page1');
await newPage(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
const title2 = await getBlockSuiteEditorTitle(page);
await title2.type('page2');

View File

@@ -1,9 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -11,7 +11,7 @@ import { expect } from '@playwright/test';
test('Duplicate page should work', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.type('test');
await clickPageMoreActions(page);

View File

@@ -1,7 +1,7 @@
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import type { Page } from '@playwright/test';
@@ -43,7 +43,7 @@ async function closeImagePreviewModal(page: Page) {
test('image preview should be shown', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
@@ -58,7 +58,7 @@ test('image preview should be shown', async ({ page }) => {
test('image go left and right', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -105,7 +105,7 @@ test('image go left and right', async ({ page }) => {
test('image able to zoom in and out with mouse scroll', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -158,7 +158,7 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => {
test('image able to zoom in and out with button click', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -204,7 +204,7 @@ test('image able to zoom in and out with button click', async ({ page }) => {
test('image should able to go left and right by buttons', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -258,7 +258,7 @@ test('image should able to go left and right by buttons', async ({ page }) => {
test('image able to fit to screen by button', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -315,7 +315,7 @@ test('image able to fit to screen by button', async ({ page }) => {
test('image able to reset zoom to 100%', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -368,7 +368,7 @@ test('image able to reset zoom to 100%', async ({ page }) => {
test('image able to copy to clipboard', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -395,7 +395,7 @@ test('image able to copy to clipboard', async ({ page }) => {
test('image able to download', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -427,7 +427,7 @@ test('image should only able to move when image is larger than viewport', async
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -484,7 +484,7 @@ test('image should able to delete and when delete, it will move to previous/next
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -559,7 +559,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
@@ -654,7 +654,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
test('keypress esc should close the modal', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
@@ -672,7 +672,7 @@ test('when mouse moves outside, the modal should be closed', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
@@ -693,7 +693,7 @@ test('caption should be visible and different styles were applied if image zoome
const sampleCaption = 'affine owns me and all';
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');

View File

@@ -2,7 +2,10 @@ import { resolve } from 'node:path';
import { rootDir, test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { newPage, waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import {
clickNewPageButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
test('should create a page with a local first avatar', async ({
@@ -11,7 +14,7 @@ test('should create a page with a local first avatar', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await page.getByTestId('workspace-name').click();
await page.getByTestId('new-workspace').click({ delay: 50 });
await page

View File

@@ -5,8 +5,8 @@ import {
} from '@affine-test/kit/utils/filter';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import type { Page } from '@playwright/test';
@@ -20,7 +20,7 @@ const createAndPinCollection = async (
) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.getByTestId('all-pages').click();
@@ -141,7 +141,7 @@ test('edit collection and change filter date', async ({ page }) => {
test('create temporary filter by click tag', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.locator('affine-page-meta-data').click();
@@ -163,7 +163,7 @@ test('create temporary filter by click tag', async ({ page }) => {
test('add collection from sidebar', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.getByTestId('all-pages').click();

View File

@@ -1,8 +1,8 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -13,7 +13,7 @@ test('page delete -> refresh page -> it should be disappear', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page delete');
const newPageId = page.url().split('/').reverse()[0];
@@ -56,7 +56,7 @@ test('page delete -> create new page -> refresh page -> new page should be appea
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page delete');
const newPageDeleteId = page.url().split('/').reverse()[0];
@@ -87,12 +87,12 @@ test('page delete -> create new page -> refresh page -> new page should be appea
expect(page.getByText("There's no page here yet")).not.toBeUndefined();
await page.getByTestId('all-pages').click();
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page1');
const newPageId1 = page.url().split('/').reverse()[0];
await page.getByTestId('all-pages').click();
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page2');
const newPageId2 = page.url().split('/').reverse()[0];
@@ -115,13 +115,13 @@ test('delete multiple pages -> create multiple pages -> refresh', async ({
await openHomePage(page);
await waitForEditorLoad(page);
// create 1st page
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page1');
const newPageId1 = page.url().split('/').reverse()[0];
await page.getByTestId('all-pages').click();
// create 2nd page
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page2');
const newPageId2 = page.url().split('/').reverse()[0];

View File

@@ -1,9 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -14,7 +14,7 @@ test.skip('New a page ,then open it and export html', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await page
.getByPlaceholder('Title')
@@ -48,7 +48,7 @@ test.skip('New a page ,then open it and export markdown', async ({
page,
workspace,
}) => {
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await page
.getByPlaceholder('Title')

View File

@@ -1,9 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { waitForLogMessage } from '@affine-test/kit/utils/utils';
@@ -15,7 +15,7 @@ test('New a page and open it ,then favorite it', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
await page.getByTestId('all-pages').click();
@@ -81,7 +81,7 @@ test.skip('Export to pdf', async ({ page }) => {
test('Cancel favorite', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
await page.getByTestId('all-pages').click();

View File

@@ -1,10 +1,10 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
createLinkedPage,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -12,7 +12,7 @@ import { expect } from '@playwright/test';
test('Show favorite items in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
const newPageId = page.url().split('/').reverse()[0];
@@ -40,7 +40,7 @@ test('Show favorite items in sidebar', async ({ page, workspace }) => {
test('Show favorite reference in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
@@ -83,7 +83,7 @@ test("Deleted page's reference will not be shown in sidebar", async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');

View File

@@ -1,8 +1,8 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -11,7 +11,7 @@ test('click btn new page', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
const originPageId = page.url().split('/').reverse()[0];
await newPage(page);
await clickNewPageButton(page);
const newPageId = page.url().split('/').reverse()[0];
expect(newPageId).not.toBe(originPageId);
const currentWorkspace = await workspace.current();
@@ -25,7 +25,7 @@ test('click btn bew page and find it in all pages', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page');
await page.getByTestId('all-pages').click();

View File

@@ -1,8 +1,8 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -10,7 +10,7 @@ import { expect } from '@playwright/test';
test('click btn bew page and open in tab', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page');
const newPageUrl = page.url();

View File

@@ -1,8 +1,8 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -13,7 +13,7 @@ test('New a page , then delete it in all pages, restore it', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to restore');
const newPageId = page.url().split('/').reverse()[0];

View File

@@ -1,9 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -14,7 +14,7 @@ test('New a page ,then open it and show delete modal', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
await page.getByTestId('all-pages').click();
@@ -40,7 +40,7 @@ test('New a page ,then go to all pages and show delete modal', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
const newPageId = page.url().split('/').reverse()[0];

View File

@@ -1,9 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -14,7 +14,7 @@ test('New a page , then delete it in all pages, finally find it in trash', async
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
const newPageId = page.url().split('/').reverse()[0];
@@ -50,7 +50,7 @@ test('New a page , then delete it in page, blockHub and option menu will not app
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.type('test');
await clickPageMoreActions(page);

View File

@@ -3,7 +3,7 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import {
createWorkspace,
createLocalWorkspace,
openWorkspaceListModal,
} from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
@@ -34,7 +34,7 @@ test('create one workspace in the workspace list', async ({
await openHomePage(page);
await waitForEditorLoad(page);
const newWorkspaceNameStr = 'New Workspace';
await createWorkspace({ name: newWorkspaceNameStr }, page);
await createLocalWorkspace({ name: newWorkspaceNameStr }, page);
// check new workspace name
const newWorkspaceName = page.getByTestId('workspace-name');
@@ -67,8 +67,8 @@ test('create multi workspace in the workspace list', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await createWorkspace({ name: 'New Workspace 2' }, page);
await createWorkspace({ name: 'New Workspace 3' }, page);
await createLocalWorkspace({ name: 'New Workspace 2' }, page);
await createLocalWorkspace({ name: 'New Workspace 3' }, page);
// show workspace list
const workspaceName = page.getByTestId('workspace-name');

View File

@@ -1,13 +1,13 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { createWorkspace } from '@affine-test/kit/utils/workspace';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('Open last workspace when back to affine', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await createWorkspace({ name: 'New Workspace 2' }, page);
await createLocalWorkspace({ name: 'New Workspace 2' }, page);
await waitForEditorLoad(page);
// show workspace list
await page.getByTestId('workspace-name').click();

View File

@@ -2,8 +2,8 @@ import { test } from '@affine-test/kit/playwright';
import { withCtrlOrMeta } from '@affine-test/kit/utils/keyboard';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
newPage,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect, type Page } from '@playwright/test';
@@ -39,7 +39,7 @@ async function titleIsFocused(page: Page) {
test('Click slider bar button', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const quickSearchButton = page.locator(
'[data-testid=slider-bar-quick-search-button]'
);
@@ -51,7 +51,7 @@ test('Click slider bar button', async ({ page }) => {
test('Click arrowDown icon after title', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
const quickSearchButton = page.locator(
'[data-testid=slider-bar-quick-search-button]'
);
@@ -63,7 +63,7 @@ test('Click arrowDown icon after title', async ({ page }) => {
test('Press the shortcut key cmd+k', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
const quickSearch = page.locator('[data-testid=quickSearch]');
await expect(quickSearch).toBeVisible();
@@ -72,7 +72,7 @@ test('Press the shortcut key cmd+k', async ({ page }) => {
test('Create a new page without keyword', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
await addNewPage.click();
@@ -83,7 +83,7 @@ test('Create a new page without keyword', async ({ page }) => {
test('Create a new page with keyword', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
@@ -95,7 +95,7 @@ test('Create a new page with keyword', async ({ page }) => {
test('Enter a keyword to search for', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
const actual = await page.locator('[cmdk-input]').inputValue();
@@ -105,7 +105,7 @@ test('Enter a keyword to search for', async ({ page }) => {
test('Create a new page and search this page', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
// input title and create new page
await page.keyboard.insertText('test123456');
@@ -147,7 +147,7 @@ test('Navigate to the 404 page and try to open quick search', async ({
test('Open quick search on local page', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
const publishedSearchResults = page.locator('[publishedSearchResults]');
await expect(publishedSearchResults).toBeVisible({ visible: false });
@@ -156,7 +156,7 @@ test('Open quick search on local page', async ({ page }) => {
test('Autofocus input after opening quick search', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
const locator = page.locator('[cmdk-input]');
await expect(locator).toBeVisible();
@@ -165,7 +165,7 @@ test('Autofocus input after opening quick search', async ({ page }) => {
test('Autofocus input after select', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.press('ArrowUp');
const locator = page.locator('[cmdk-input]');
@@ -175,7 +175,7 @@ test('Autofocus input after select', async ({ page }) => {
test('Focus title after creating a new page', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await newPage(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
await addNewPage.click();
@@ -198,7 +198,7 @@ test('assert the recent browse pages are on the recent list', async ({
await waitForEditorLoad(page);
// create first page
await newPage(page);
await clickNewPageButton(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.type('sgtokidoki', {

View File

@@ -8,7 +8,7 @@ import {
openSettingModal,
openShortcutsPanel,
} from '@affine-test/kit/utils/setting';
import { createWorkspace } from '@affine-test/kit/utils/workspace';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('Open settings modal', async ({ page }) => {
@@ -118,8 +118,8 @@ test('Different workspace should have different name in the setting panel', asyn
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await createWorkspace({ name: 'New Workspace 2' }, page);
await createWorkspace({ name: 'New Workspace 3' }, page);
await createLocalWorkspace({ name: 'New Workspace 2' }, page);
await createLocalWorkspace({ name: 'New Workspace 3' }, page);
await openSettingModal(page);
await page.getByTestId('current-workspace-label').click();
expect(await page.getByTestId('workspace-name-input').inputValue()).toBe(

View File

@@ -1,7 +1,7 @@
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
import { getBlockSuiteEditorTitle, newPage } from './page-logic';
import { clickNewPageButton, getBlockSuiteEditorTitle } from './page-logic';
const monthNames = [
'Jan',
@@ -189,7 +189,7 @@ export const createPageWithTag = async (
}
) => {
await page.getByTestId('all-pages').click();
await newPage(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.locator('affine-page-meta-data').click();

View File

@@ -14,7 +14,7 @@ export async function waitForAllPagesLoad(page: Page) {
});
}
export async function newPage(page: Page) {
export async function clickNewPageButton(page: Page) {
// fixme(himself65): if too fast, the page will crash
await page.getByTestId('new-page-button').click({
delay: 100,

View File

@@ -5,11 +5,12 @@ interface CreateWorkspaceParams {
}
export async function openWorkspaceListModal(page: Page) {
const workspaceName = page.getByTestId('workspace-name');
await workspaceName.click();
await page.getByTestId('workspace-name').click({
delay: 50,
});
}
export async function createWorkspace(
export async function createLocalWorkspace(
params: CreateWorkspaceParams,
page: Page
) {