Skip to content

Commit

Permalink
Fix route interception
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 9, 2024
1 parent 7ad27c8 commit a23241e
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions test/e2e/specs/editor/various/change-detection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const test = base.extend( {
},
} );

const POST_URLS = [
'/wp/v2/posts',
`rest_route=${ encodeURIComponent( '/wp/v2/posts' ) }`,
];

test.describe( 'Change detection', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
Expand Down Expand Up @@ -276,7 +281,6 @@ test.describe( 'Change detection', () => {
} );

test( 'Should prompt if changes made while save is in-flight', async ( {
page,
editor,
pageUtils,
changeDetectionUtils,
Expand All @@ -295,12 +299,7 @@ test.describe( 'Change detection', () => {

await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.type( '!' );
await expect(
page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Save draft' } )
).toBeEnabled();
.fill( 'Hello World!' );

await changeDetectionUtils.releaseSaveIntercept();

Expand Down Expand Up @@ -539,18 +538,24 @@ class ChangeDetectionUtils {
this.#continueInterceptedSave = res;
} );

await this.#page.route( '**/wp/v2/posts', async ( route ) => {
hadInterceptedSave = true;
await deferred;
await route.continue();
} );
await this.#page.route(
( url ) =>
POST_URLS.some( ( postUrl ) => url.href.includes( postUrl ) ),
async ( route ) => {
hadInterceptedSave = true;
await deferred;
await route.continue();
}
);

return () => hadInterceptedSave;
};

releaseSaveIntercept = async () => {
this.#continueInterceptedSave?.();
await this.#page.unroute( '**/wp/v2/posts' );
await this.#page.unroute( ( url ) =>
POST_URLS.some( ( postUrl ) => url.href.includes( postUrl ) )
);
this.#continueInterceptedSave = null;
};
}

0 comments on commit a23241e

Please sign in to comment.