refactor: new provider (#4900)

This commit is contained in:
EYHN
2023-11-17 15:50:01 +08:00
committed by GitHub
parent 9baad36e41
commit aa4c7407de
48 changed files with 1783 additions and 1480 deletions

View File

@@ -62,43 +62,38 @@ test('app sidebar router forward/back', async ({ page }) => {
});
}
{
const title = (await page
.locator('.affine-doc-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('test3');
await expect(page.locator('.affine-doc-page-block-title')).toHaveText(
'test3'
);
}
await page.click('[data-testid="app-sidebar-arrow-button-back"]');
await page.click('[data-testid="app-sidebar-arrow-button-back"]');
{
const title = (await page
.locator('.affine-doc-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('test1');
await expect(page.locator('.affine-doc-page-block-title')).toHaveText(
'test1'
);
}
await page.click('[data-testid="app-sidebar-arrow-button-forward"]');
await page.click('[data-testid="app-sidebar-arrow-button-forward"]');
{
const title = (await page
.locator('.affine-doc-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('test3');
await expect(page.locator('.affine-doc-page-block-title')).toHaveText(
'test3'
);
}
await historyShortcut(page, 'goBack');
await historyShortcut(page, 'goBack');
{
const title = (await page
.locator('.affine-doc-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('test1');
await expect(page.locator('.affine-doc-page-block-title')).toHaveText(
'test1'
);
}
await historyShortcut(page, 'goForward');
await historyShortcut(page, 'goForward');
{
const title = (await page
.locator('.affine-doc-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('test3');
await expect(page.locator('.affine-doc-page-block-title')).toHaveText(
'test3'
);
}
});
// }

View File

@@ -18,5 +18,5 @@ test('Duplicate page should work', async ({ page }) => {
const duplicateButton = page.getByTestId('editor-option-menu-duplicate');
await duplicateButton.click({ delay: 100 });
const title2 = getBlockSuiteEditorTitle(page);
expect(await title2.innerText()).toBe('test(1)');
await expect(title2).toHaveText('test(1)', { timeout: 1000 });
});

View File

@@ -5,7 +5,10 @@ import {
getBlockSuiteEditorTitle,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar';
import {
clickSideBarAllPageButton,
clickSideBarCurrentWorkspaceBanner,
} from '@affine-test/kit/utils/sidebar';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
@@ -76,6 +79,7 @@ test('Show collections items in sidebar', async ({ page }) => {
skipInitialPage: true,
});
expect(await items.count()).toBe(1);
await clickSideBarAllPageButton(page);
await createLocalWorkspace(
{
name: 'Test 1',

View File

@@ -9,9 +9,11 @@ import {
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import { expect, type Page } from '@playwright/test';
const openQuickSearchByShortcut = async (page: Page) => {
const openQuickSearchByShortcut = async (page: Page, checkVisible = true) => {
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
await page.waitForTimeout(1000);
if (checkVisible) {
expect(page.getByTestId('cmdk-quick-search')).toBeVisible();
}
};
const keyboardDownAndSelect = async (page: Page, label: string) => {
@@ -188,7 +190,7 @@ test('Navigate to the 404 page and try to open quick search', async ({
await page.goto('http://localhost:8080/404');
const notFoundTip = page.locator('button >> text=Back to My Content');
await expect(notFoundTip).toBeVisible();
await openQuickSearchByShortcut(page);
await openQuickSearchByShortcut(page, false);
const quickSearch = page.locator('[data-testid=cmdk-quick-search]');
await expect(quickSearch).toBeVisible({ visible: false });
});
@@ -215,6 +217,7 @@ test('Autofocus input after select', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await page.waitForTimeout(500); // wait for new page loaded
await openQuickSearchByShortcut(page);
await page.keyboard.press('ArrowUp');
const locator = page.locator('[cmdk-input]');
@@ -251,8 +254,9 @@ test('assert the recent browse pages are on the recent list', async ({
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('sgtokidoki');
expect(await title.innerText()).toBe('sgtokidoki');
await title.click();
await title.pressSequentially('sgtokidoki', { delay: 100 });
await expect(title).toHaveText('sgtokidoki');
}
// create second page
@@ -262,8 +266,9 @@ test('assert the recent browse pages are on the recent list', async ({
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('theliquidhorse');
expect(await title.innerText()).toBe('theliquidhorse');
await title.click();
await title.pressSequentially('theliquidhorse', { delay: 100 });
await expect(title).toHaveText('theliquidhorse');
}
await page.waitForTimeout(200);
@@ -273,8 +278,9 @@ test('assert the recent browse pages are on the recent list', async ({
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('battlekot');
expect(await title.innerText()).toBe('battlekot');
await title.click();
await title.pressSequentially('battlekot', { delay: 100 });
await expect(title).toHaveText('battlekot');
}
await openQuickSearchByShortcut(page);
@@ -283,9 +289,9 @@ test('assert the recent browse pages are on the recent list', async ({
const quickSearchItems = page.locator(
'[cmdk-item] [data-testid="cmdk-label"]'
);
expect(await quickSearchItems.nth(0).textContent()).toBe('battlekot');
expect(await quickSearchItems.nth(1).textContent()).toBe('theliquidhorse');
expect(await quickSearchItems.nth(2).textContent()).toBe('sgtokidoki');
await expect(quickSearchItems.nth(0)).toHaveText('battlekot');
await expect(quickSearchItems.nth(1)).toHaveText('theliquidhorse');
await expect(quickSearchItems.nth(2)).toHaveText('sgtokidoki');
}
// create forth page, and check does the recent page list only contains three pages
@@ -299,8 +305,9 @@ test('assert the recent browse pages are on the recent list', async ({
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('affine is the best');
expect(await title.innerText()).toBe('affine is the best');
await title.click();
await title.pressSequentially('affine is the best', { delay: 100 });
await expect(title).toHaveText('affine is the best', { timeout: 500 });
}
await page.waitForTimeout(1000);
await openQuickSearchByShortcut(page);
@@ -308,9 +315,7 @@ test('assert the recent browse pages are on the recent list', async ({
const quickSearchItems = page.locator(
'[cmdk-item] [data-testid="cmdk-label"]'
);
expect(await quickSearchItems.nth(0).textContent()).toBe(
'affine is the best'
);
await expect(quickSearchItems.nth(0)).toHaveText('affine is the best');
}
});

View File

@@ -110,11 +110,11 @@ test('Different workspace should have different name in the setting panel', asyn
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(
await expect(page.getByTestId('workspace-name-input')).toHaveValue(
'New Workspace 3'
);
await page.getByText('New Workspace 2').click();
expect(await page.getByTestId('workspace-name-input').inputValue()).toBe(
await expect(page.getByTestId('workspace-name-input')).toHaveValue(
'New Workspace 2'
);
});

View File

@@ -1,4 +1,6 @@
import type { Page } from '@playwright/test';
import { expect, type Page } from '@playwright/test';
import { waitForEditorLoad } from './page-logic';
interface CreateWorkspaceParams {
name: string;
@@ -32,6 +34,10 @@ export async function createLocalWorkspace(
delay: 500,
});
await waitForEditorLoad(page);
await expect(page.getByTestId('workspace-name')).toHaveText(params.name);
// if (isDesktop) {
// await page.getByTestId('create-workspace-continue-button').click();
// }