Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Detection: Add a test case for post trashing. #18290

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/is-current-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export function isCurrentURL( WPPath, query = '' ) {

currentURL.search = query;

return createURL( WPPath ) === currentURL.href;
return createURL( WPPath, query ) === currentURL.href;
}
60 changes: 32 additions & 28 deletions packages/e2e-tests/specs/editor/various/change-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
pressKeyWithModifier,
ensureSidebarOpened,
publishPost,
saveDraft,
openDocumentSettingsSidebar,
isCurrentURL,
} from '@wordpress/e2e-test-utils';

describe( 'Change detection', () => {
Expand Down Expand Up @@ -159,13 +162,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 );
} );
Expand All @@ -174,27 +171,15 @@ 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 );
} );

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();

Expand Down Expand Up @@ -330,13 +315,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(
Expand All @@ -348,4 +327,29 @@ 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();
const postId = await page.evaluate(
() => window.wp.data.select( 'core/editor' ).getCurrentPostId()
);

// Trash post.
await openDocumentSettingsSidebar();
await page.click( '.editor-post-trash.components-button' );

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(),
] );

expect( isCurrentURL( '/wp-admin/edit.php', `post_type=post&ids=${ postId }` ) ).toBe( true );
} );
} );