Skip to content

Commit

Permalink
fix: flaky test case with raw enter press (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed Jan 16, 2023
1 parent 77e519c commit 4904969
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
7 changes: 4 additions & 3 deletions tests/clipboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './utils/declare-test-window.js';
import { test } from '@playwright/test';
import {
SHORT_KEY,
backsapce,
pressBackspace,
copyByKeyboard,
dragBetweenCoords,
enterPlaygroundRoom,
Expand All @@ -18,6 +18,7 @@ import {
setQuillSelection,
setSelection,
undoByClick,
pressSpace,
} from './utils/actions/index.js';
import {
assertBlockTypes,
Expand Down Expand Up @@ -316,7 +317,7 @@ test('should keep first line format when pasted into a new line', async ({
await initEmptyParagraphState(page);
await focusRichText(page);
await page.keyboard.type('-');
await page.keyboard.press('Space', { delay: 50 });
await pressSpace(page);
await page.keyboard.type('1');
await pressEnter(page);
await pressTab(page);
Expand Down Expand Up @@ -364,7 +365,7 @@ test('should keep first line format when pasted into a new line', async ({

await focusRichText(page, 3);
await pressEnter(page);
await backsapce(page);
await pressBackspace(page);
await pasteByKeyboard(page);

await assertStoreMatchJSX(
Expand Down
14 changes: 7 additions & 7 deletions tests/code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ test('press enter twice at end of code block can jump out', async ({
await initEmptyCodeBlockState(page);
await focusRichText(page);

await page.keyboard.press('Enter');
await page.keyboard.press('Enter');
await pressEnter(page);
await pressEnter(page);

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

await page.keyboard.press('Enter');
await pressEnter(page);
await addCodeBlock(page);
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowDown');
Expand All @@ -318,8 +318,8 @@ test('press backspace after code block can select code block', async ({
await initEmptyCodeBlockState(page);
await focusRichText(page);

await page.keyboard.press('Enter');
await page.keyboard.press('Enter');
await pressEnter(page);
await pressEnter(page);
await page.keyboard.press('Backspace');

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

await page.keyboard.press('Enter');
await page.keyboard.press('Enter');
await pressEnter(page);
await pressEnter(page);
await page.keyboard.press('ArrowUp');

const locator = page.locator('.affine-page-selected-rects-container');
Expand Down
7 changes: 5 additions & 2 deletions tests/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
pressTab,
initEmptyParagraphState,
clickBlockTypeMenuItem,
pressSpace,
} from './utils/actions/index.js';

test('add new bulleted list', async ({ page }) => {
Expand Down Expand Up @@ -291,8 +292,10 @@ test('should indent todo block preserve todo status', async ({ page }) => {
await focusRichText(page);
await page.keyboard.type('text1');
await pressEnter(page);
await page.keyboard.type('[x] ');
await page.waitForTimeout(10);

await page.keyboard.type('[x]');
await pressSpace(page);

await page.keyboard.type('todo item');
await pressTab(page);
await assertStoreMatchJSX(
Expand Down
3 changes: 2 additions & 1 deletion tests/selection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ test('Delete the blank line between two dividers', async ({ page }) => {
await focusRichText(page);
await page.keyboard.type('--- ');
await assertDivider(page, 1);
await page.keyboard.press('Enter');

await pressEnter(page);
await page.keyboard.type('--- ');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowUp');
Expand Down
6 changes: 5 additions & 1 deletion tests/utils/actions/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ export const withPressKey = async (
await page.keyboard.up(key);
};

export async function backsapce(page: Page) {
export async function pressBackspace(page: Page) {
await page.keyboard.press('Backspace', { delay: 50 });
}

export async function pressSpace(page: Page) {
await page.keyboard.press('Space', { delay: 50 });
}

export async function pressEnter(page: Page) {
// avoid flaky test by simulate real user input
await page.keyboard.press('Enter', { delay: 50 });
Expand Down

2 comments on commit 4904969

@vercel
Copy link

@vercel vercel bot commented on 4904969 Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite – ./packages/playground

blocksuite-toeverything.vercel.app
blocksuite-five.vercel.app
blocksuite-git-master-toeverything.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 4904969 Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite-react – ./packages/react/examples/next

blocksuite-react.vercel.app
blocksuite-react-toeverything.vercel.app
blocksuite-react-git-master-toeverything.vercel.app

Please sign in to comment.