Skip to content

Commit

Permalink
test(edgeless): fix lock flaky test by adding waitNextFrame (#8937)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Dec 11, 2024
1 parent b79fd55 commit 592f2df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions tests/edgeless/lock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type,
undoByKeyboard,
} from 'utils/actions/keyboard.js';
import { waitNextFrame } from 'utils/actions/misc.js';
import {
assertCanvasElementsCount,
assertEdgelessElementBound,
Expand Down Expand Up @@ -63,14 +64,14 @@ test.describe('lock', () => {
elementCreateFn: F,
...args: Parameters<F>
) => {
await deleteAll(page);
await elementCreateFn(...args);
await waitNextFrame(page);
await pressEscape(page);
await selectAllByKeyboard(page);

const id = (await getSelectedIds(page))[0];
expect(id).not.toBeUndefined();
const type = await getTypeById(page, id);
const ids = await getSelectedIds(page);
expect(ids).toHaveLength(1);
const type = await getTypeById(page, ids[0]);
const message = `element(${type}) should be able to be (un)locked`;

const { lock, unlock } = getButtons(page);
Expand All @@ -85,6 +86,8 @@ test.describe('lock', () => {
await unlock.click();
await expect(lock, message).toBeVisible();
await expect(unlock, message).toBeHidden();
await deleteAll(page);
await waitNextFrame(page);
};

await wrapTest(createBrushElement, page, [100, 100], [150, 150]);
Expand All @@ -94,6 +97,7 @@ test.describe('lock', () => {
await wrapTest(createMindmap, page, [100, 100]);
await wrapTest(createFrame, page, [100, 100], [150, 150]);
await wrapTest(createNote, page, [100, 100]);

await wrapTest(async () => {
await createShapeElement(page, [100, 100], [150, 150]);
await createShapeElement(page, [150, 150], [200, 200]);
Expand Down
6 changes: 4 additions & 2 deletions tests/utils/actions/edgeless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1851,14 +1851,16 @@ export async function createFrameElement(
export async function createBrushElement(
page: Page,
coord1: number[],
coord2: number[]
coord2: number[],
auto = true
) {
const start = await toViewCoord(page, coord1);
const end = await toViewCoord(page, coord2);
await addBasicBrushElement(
page,
{ x: start[0], y: start[1] },
{ x: end[0], y: end[1] }
{ x: end[0], y: end[1] },
auto
);
}

Expand Down

0 comments on commit 592f2df

Please sign in to comment.