chore: improve test stability

This commit is contained in:
DarkSky
2026-07-07 12:26:56 +08:00
parent fe2a4db76b
commit 9f8e5c0eb3
3 changed files with 122 additions and 36 deletions
+38 -10
View File
@@ -13,6 +13,8 @@ import {
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import { expect } from '@playwright/test';
const SPLIT_VIEW_READY_TIMEOUT = 30_000;
test('open split view', async ({ page }) => {
await clickNewPageButton(page);
await page.waitForTimeout(500);
@@ -23,11 +25,20 @@ test('open split view', async ({ page }) => {
.click({
modifiers: ['ControlOrMeta', 'Alt'],
});
await expect(page.locator('.doc-title-container')).toHaveCount(2);
await expect(page.locator('.doc-title-container')).toHaveCount(2, {
timeout: SPLIT_VIEW_READY_TIMEOUT,
});
// check tab title
await expect(page.getByTestId('split-view-label')).toHaveCount(2);
await expectTabTitle(page, 0, ['Untitled', 'hi from another page']);
await expect(page.getByTestId('split-view-label')).toHaveCount(2, {
timeout: SPLIT_VIEW_READY_TIMEOUT,
});
await expectTabTitle(
page,
0,
['Untitled', 'hi from another page'],
SPLIT_VIEW_READY_TIMEOUT
);
// the first split view should be active
await expectActiveTab(page, 0, 0);
@@ -53,7 +64,12 @@ test('open split view', async ({ page }) => {
true
);
await expectTabTitle(page, 0, ['hi from another page', 'Untitled']);
await expectTabTitle(
page,
0,
['hi from another page', 'Untitled'],
SPLIT_VIEW_READY_TIMEOUT
);
});
test('open split view in all docs (operations button)', async ({ page }) => {
@@ -65,12 +81,17 @@ test('open split view in all docs (operations button)', async ({ page }) => {
.getByTestId('doc-list-operation-button')
.click();
await page.getByRole('menuitem', { name: 'Open in split view' }).click();
await expect(page.getByTestId('split-view-panel')).toHaveCount(2);
await expect(page.getByTestId('split-view-panel')).toHaveCount(2, {
timeout: SPLIT_VIEW_READY_TIMEOUT,
});
const targetPage = page.getByTestId('split-view-panel').last();
await expect(targetPage).toHaveAttribute('data-is-active', 'true');
await expect(targetPage.locator('.doc-title-container')).toBeVisible();
await expect(targetPage.locator('.doc-title-container')).toBeVisible({
timeout: SPLIT_VIEW_READY_TIMEOUT,
});
await expect(targetPage.locator('.doc-title-container')).toContainText(
testTitle
testTitle,
{ timeout: SPLIT_VIEW_READY_TIMEOUT }
);
});
@@ -87,7 +108,12 @@ test('open split view in all docs (drag to resize handle)', async ({
const leftResizeHandle = page.getByTestId('resize-handle').first();
await dragTo(page, pageItem, leftResizeHandle, 'center');
await expectTabTitle(page, 0, ['test-page', 'All docs']);
await expectTabTitle(
page,
0,
['test-page', 'All docs'],
SPLIT_VIEW_READY_TIMEOUT
);
});
test('creating split view by dragging sidebar journals', async ({ page }) => {
@@ -95,7 +121,9 @@ test('creating split view by dragging sidebar journals', async ({ page }) => {
const leftResizeHandle = page.getByTestId('resize-handle').first();
await dragTo(page, journalButton, leftResizeHandle, 'center');
await expect(page.getByTestId('split-view-panel')).toHaveCount(2);
await expect(page.getByTestId('split-view-panel')).toHaveCount(2, {
timeout: SPLIT_VIEW_READY_TIMEOUT,
});
await expect(
page
.getByTestId('split-view-panel')
@@ -103,5 +131,5 @@ test('creating split view by dragging sidebar journals', async ({ page }) => {
has: page.locator('[data-is-first="true"]'),
})
.getByTestId('date-today-label')
).toBeVisible();
).toBeVisible({ timeout: SPLIT_VIEW_READY_TIMEOUT });
});