Skip to content

Commit

Permalink
Replace canvas.waitForFunction with expec.poll
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Sep 28, 2023
1 parent 687d6ea commit a755917
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions test/e2e/specs/editor/various/copy-cut-paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new block at the top of the document to paste there.
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
Expand All @@ -287,9 +291,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new block at the top of the document to paste there.
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
Expand All @@ -314,9 +322,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new block at the top of the document to paste there.
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
Expand All @@ -342,9 +354,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new block at the top of the document to paste there.
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
Expand All @@ -369,9 +385,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new block at the top of the document to paste there.
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
Expand All @@ -396,9 +416,13 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+ArrowLeft' );
// Sometimes the caret has not moved to the correct position before pressing Enter.
// @see https://github.com/WordPress/gutenberg/issues/40303#issuecomment-1109434887
await editor.canvas.waitForFunction(
() => window.getSelection().type === 'Caret'
);
await expect
.poll( async () =>
editor.canvas
.locator( ':root' )
.evaluate( () => window.getSelection().type )
)
.toBe( 'Caret' );
// Create a new code block to paste there.
await editor.insertBlock( { name: 'core/code' } );
await pageUtils.pressKeys( 'primary+v' );
Expand All @@ -420,9 +444,9 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeys( 'primary+v' );
// Expect the span to be filtered out.
expect(
await editor.canvas.evaluate(
() => document.activeElement.innerHTML
)
await editor.canvas
.locator( ':root' )
.evaluate( () => document.activeElement.innerHTML )
).toMatchSnapshot();
} );

Expand All @@ -440,9 +464,9 @@ test.describe( 'Copy/cut/paste', () => {
// Ensure the selection is correct.
await page.keyboard.type( 'y' );
expect(
await editor.canvas.evaluate(
() => document.activeElement.innerHTML
)
await editor.canvas
.locator( ':root' )
.evaluate( () => document.activeElement.innerHTML )
).toBe( 'axyb' );
} );

Expand Down

0 comments on commit a755917

Please sign in to comment.