Skip to content

Commit 4904969

Browse files
authored
fix: flaky test case with raw enter press (#730)
1 parent 77e519c commit 4904969

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

tests/clipboard.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './utils/declare-test-window.js';
22
import { test } from '@playwright/test';
33
import {
44
SHORT_KEY,
5-
backsapce,
5+
pressBackspace,
66
copyByKeyboard,
77
dragBetweenCoords,
88
enterPlaygroundRoom,
@@ -18,6 +18,7 @@ import {
1818
setQuillSelection,
1919
setSelection,
2020
undoByClick,
21+
pressSpace,
2122
} from './utils/actions/index.js';
2223
import {
2324
assertBlockTypes,
@@ -316,7 +317,7 @@ test('should keep first line format when pasted into a new line', async ({
316317
await initEmptyParagraphState(page);
317318
await focusRichText(page);
318319
await page.keyboard.type('-');
319-
await page.keyboard.press('Space', { delay: 50 });
320+
await pressSpace(page);
320321
await page.keyboard.type('1');
321322
await pressEnter(page);
322323
await pressTab(page);
@@ -364,7 +365,7 @@ test('should keep first line format when pasted into a new line', async ({
364365

365366
await focusRichText(page, 3);
366367
await pressEnter(page);
367-
await backsapce(page);
368+
await pressBackspace(page);
368369
await pasteByKeyboard(page);
369370

370371
await assertStoreMatchJSX(

tests/code.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ test('press enter twice at end of code block can jump out', async ({
288288
await initEmptyCodeBlockState(page);
289289
await focusRichText(page);
290290

291-
await page.keyboard.press('Enter');
292-
await page.keyboard.press('Enter');
291+
await pressEnter(page);
292+
await pressEnter(page);
293293

294294
const locator = page.locator('affine-paragraph');
295295
await expect(locator).toBeVisible();
@@ -302,7 +302,7 @@ test('press ArrowDown before code block can select code block', async ({
302302
await initEmptyParagraphState(page);
303303
await focusRichText(page);
304304

305-
await page.keyboard.press('Enter');
305+
await pressEnter(page);
306306
await addCodeBlock(page);
307307
await page.keyboard.press('ArrowUp');
308308
await page.keyboard.press('ArrowDown');
@@ -318,8 +318,8 @@ test('press backspace after code block can select code block', async ({
318318
await initEmptyCodeBlockState(page);
319319
await focusRichText(page);
320320

321-
await page.keyboard.press('Enter');
322-
await page.keyboard.press('Enter');
321+
await pressEnter(page);
322+
await pressEnter(page);
323323
await page.keyboard.press('Backspace');
324324

325325
const locator = page.locator('.affine-page-selected-rects-container');
@@ -333,8 +333,8 @@ test('press ArrowUp after code block can select code block', async ({
333333
await initEmptyCodeBlockState(page);
334334
await focusRichText(page);
335335

336-
await page.keyboard.press('Enter');
337-
await page.keyboard.press('Enter');
336+
await pressEnter(page);
337+
await pressEnter(page);
338338
await page.keyboard.press('ArrowUp');
339339

340340
const locator = page.locator('.affine-page-selected-rects-container');

tests/list.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
pressTab,
2222
initEmptyParagraphState,
2323
clickBlockTypeMenuItem,
24+
pressSpace,
2425
} from './utils/actions/index.js';
2526

2627
test('add new bulleted list', async ({ page }) => {
@@ -291,8 +292,10 @@ test('should indent todo block preserve todo status', async ({ page }) => {
291292
await focusRichText(page);
292293
await page.keyboard.type('text1');
293294
await pressEnter(page);
294-
await page.keyboard.type('[x] ');
295-
await page.waitForTimeout(10);
295+
296+
await page.keyboard.type('[x]');
297+
await pressSpace(page);
298+
296299
await page.keyboard.type('todo item');
297300
await pressTab(page);
298301
await assertStoreMatchJSX(

tests/selection.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ test('Delete the blank line between two dividers', async ({ page }) => {
587587
await focusRichText(page);
588588
await page.keyboard.type('--- ');
589589
await assertDivider(page, 1);
590-
await page.keyboard.press('Enter');
590+
591+
await pressEnter(page);
591592
await page.keyboard.type('--- ');
592593
await page.keyboard.press('ArrowUp');
593594
await page.keyboard.press('ArrowUp');

tests/utils/actions/keyboard.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ export const withPressKey = async (
7575
await page.keyboard.up(key);
7676
};
7777

78-
export async function backsapce(page: Page) {
78+
export async function pressBackspace(page: Page) {
7979
await page.keyboard.press('Backspace', { delay: 50 });
8080
}
8181

82+
export async function pressSpace(page: Page) {
83+
await page.keyboard.press('Space', { delay: 50 });
84+
}
85+
8286
export async function pressEnter(page: Page) {
8387
// avoid flaky test by simulate real user input
8488
await page.keyboard.press('Enter', { delay: 50 });

0 commit comments

Comments
 (0)