From 29c0c20625ba5fb4eefdce717d4f09ba22a9796a Mon Sep 17 00:00:00 2001 From: epiqueras Date: Tue, 5 Nov 2019 08:10:06 -0800 Subject: [PATCH 1/4] Change Detection: Add a test case for post trashing. --- .../editor/various/change-detection.test.js | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/change-detection.test.js b/packages/e2e-tests/specs/editor/various/change-detection.test.js index 0f384d7c3efd5..f4e125e2b01df 100644 --- a/packages/e2e-tests/specs/editor/various/change-detection.test.js +++ b/packages/e2e-tests/specs/editor/various/change-detection.test.js @@ -7,6 +7,8 @@ import { pressKeyWithModifier, ensureSidebarOpened, publishPost, + saveDraft, + openDocumentSettingsSidebar, } from '@wordpress/e2e-test-utils'; describe( 'Change detection', () => { @@ -159,13 +161,7 @@ describe( 'Change detection', () => { it( 'Should not prompt if changes saved', async () => { await page.type( '.editor-post-title__input', 'Hello World' ); - await Promise.all( [ - // Wait for "Saved" to confirm save complete. - page.waitForSelector( '.editor-post-saved-state.is-saved' ), - - // Keyboard shortcut Ctrl+S save. - pressKeyWithModifier( 'primary', 'S' ), - ] ); + await saveDraft(); await assertIsDirty( false ); } ); @@ -174,13 +170,7 @@ describe( 'Change detection', () => { await clickBlockAppender(); await page.keyboard.type( 'Hello World' ); - await Promise.all( [ - // Wait for "Saved" to confirm save complete. - page.waitForSelector( '.editor-post-saved-state.is-saved' ), - - // Keyboard shortcut Ctrl+S save. - pressKeyWithModifier( 'primary', 'S' ), - ] ); + await saveDraft(); await assertIsDirty( false ); } ); @@ -188,13 +178,7 @@ describe( 'Change detection', () => { it( 'Should not save if all changes saved', async () => { await page.type( '.editor-post-title__input', 'Hello World' ); - await Promise.all( [ - // Wait for "Saved" to confirm save complete. - page.waitForSelector( '.editor-post-saved-state.is-saved' ), - - // Keyboard shortcut Ctrl+S save. - pressKeyWithModifier( 'primary', 'S' ), - ] ); + await saveDraft(); await interceptSave(); @@ -330,13 +314,7 @@ describe( 'Change detection', () => { await page.keyboard.type( 'Paragraph' ); // Save - await Promise.all( [ - // Wait for "Saved" to confirm save complete. - page.waitForSelector( '.editor-post-saved-state.is-saved' ), - - // Keyboard shortcut Ctrl+S save. - pressKeyWithModifier( 'primary', 'S' ), - ] ); + await saveDraft(); // Verify that the title is empty. const title = await page.$eval( @@ -348,4 +326,22 @@ describe( 'Change detection', () => { // Verify that the post is not dirty. await assertIsDirty( false ); } ); + + it( 'should not prompt to confirm unsaved changes when trashing an existing post', async () => { + // Enter title. + await page.type( '.editor-post-title__input', 'Hello World' ); + + // Save + await saveDraft(); + + // Trash post. + await openDocumentSettingsSidebar(); + await page.click( '.editor-post-trash.components-button' ); + + // Wait for "Saved" to confirm save complete. + await page.waitForSelector( '.editor-post-saved-state.is-saved' ); + + // Check that the dialog didn't show. + await assertIsDirty( false ); + } ); } ); From 42fc79c49b974fdebbb05243a324e4bd710f56d2 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Tue, 5 Nov 2019 14:14:48 -0800 Subject: [PATCH 2/4] Change Detection: Fix the way redirection is asserted. --- .../e2e-tests/specs/editor/various/change-detection.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/change-detection.test.js b/packages/e2e-tests/specs/editor/various/change-detection.test.js index f4e125e2b01df..7c9e6246393f1 100644 --- a/packages/e2e-tests/specs/editor/various/change-detection.test.js +++ b/packages/e2e-tests/specs/editor/various/change-detection.test.js @@ -9,6 +9,7 @@ import { publishPost, saveDraft, openDocumentSettingsSidebar, + isCurrentURL, } from '@wordpress/e2e-test-utils'; describe( 'Change detection', () => { @@ -341,7 +342,8 @@ describe( 'Change detection', () => { // Wait for "Saved" to confirm save complete. await page.waitForSelector( '.editor-post-saved-state.is-saved' ); - // Check that the dialog didn't show. - await assertIsDirty( false ); + // Make sure redirection happens. + await page.waitForNavigation(); + isCurrentURL( 'edit.php' ); } ); } ); From 236c43ba4c0276801d2ecbc4bc2081e9f5621fea Mon Sep 17 00:00:00 2001 From: Enrique Piqueras Date: Wed, 6 Nov 2019 10:07:29 -0800 Subject: [PATCH 3/4] Update packages/e2e-tests/specs/editor/various/change-detection.test.js Co-Authored-By: Andrew Duthie --- .../e2e-tests/specs/editor/various/change-detection.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/editor/various/change-detection.test.js b/packages/e2e-tests/specs/editor/various/change-detection.test.js index 7c9e6246393f1..52517517cd9f9 100644 --- a/packages/e2e-tests/specs/editor/various/change-detection.test.js +++ b/packages/e2e-tests/specs/editor/various/change-detection.test.js @@ -344,6 +344,6 @@ describe( 'Change detection', () => { // Make sure redirection happens. await page.waitForNavigation(); - isCurrentURL( 'edit.php' ); + expect( isCurrentURL( 'edit.php' ) ).toBe( true ); } ); } ); From 721f5c94a9153c905a4be753b0ab6f4a1c18746b Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 6 Nov 2019 10:26:34 -0800 Subject: [PATCH 4/4] Change Detection: Fix test race condition. --- packages/e2e-test-utils/src/is-current-url.js | 2 +- .../editor/various/change-detection.test.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/e2e-test-utils/src/is-current-url.js b/packages/e2e-test-utils/src/is-current-url.js index 6062f241d4854..80058d1225281 100644 --- a/packages/e2e-test-utils/src/is-current-url.js +++ b/packages/e2e-test-utils/src/is-current-url.js @@ -20,5 +20,5 @@ export function isCurrentURL( WPPath, query = '' ) { currentURL.search = query; - return createURL( WPPath ) === currentURL.href; + return createURL( WPPath, query ) === currentURL.href; } diff --git a/packages/e2e-tests/specs/editor/various/change-detection.test.js b/packages/e2e-tests/specs/editor/various/change-detection.test.js index 52517517cd9f9..947508d10e2e0 100644 --- a/packages/e2e-tests/specs/editor/various/change-detection.test.js +++ b/packages/e2e-tests/specs/editor/various/change-detection.test.js @@ -334,16 +334,22 @@ describe( 'Change detection', () => { // Save await saveDraft(); + const postId = await page.evaluate( + () => window.wp.data.select( 'core/editor' ).getCurrentPostId() + ); // Trash post. await openDocumentSettingsSidebar(); await page.click( '.editor-post-trash.components-button' ); - // Wait for "Saved" to confirm save complete. - await page.waitForSelector( '.editor-post-saved-state.is-saved' ); + await Promise.all( [ + // Wait for "Saved" to confirm save complete. + await page.waitForSelector( '.editor-post-saved-state.is-saved' ), + + // Make sure redirection happens. + await page.waitForNavigation(), + ] ); - // Make sure redirection happens. - await page.waitForNavigation(); - expect( isCurrentURL( 'edit.php' ) ).toBe( true ); + expect( isCurrentURL( '/wp-admin/edit.php', `post_type=post&ids=${ postId }` ) ).toBe( true ); } ); } );