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

Editor: Make sure that all edits after saving are considered "persistent". #17888

Merged

Conversation

epiqueras
Copy link
Contributor

Fixes #17852

Description

This PR fixes the issue discussed in #17852, by making sure that any change after a save is considered as persistent for undo level creation and change detection.

How has this been tested?

It was verified that #17852 was fixed and all the tests pass.

Types of Changes

Bug Fix: Fix an issue where editing the same block attribute after saving would not dirty the post again.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@epiqueras epiqueras added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention [Package] Editor /packages/editor labels Oct 10, 2019
@epiqueras epiqueras added this to the Gutenberg 6.7 milestone Oct 10, 2019
@epiqueras epiqueras requested a review from talldan as a code owner October 10, 2019 16:10
@epiqueras epiqueras self-assigned this Oct 10, 2019
Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it may be worth including the e2e test @mcsf provided?

@mcsf
Copy link
Contributor

mcsf commented Oct 11, 2019

Do you think it may be worth including the e2e test @mcsf provided?

I'd like to, but when I tested last night I noticed that the test always passed if Puppeteer ran headless and with no SLOWMO factor. The test only worked (i.e. failing on master, passing here) when run more slowly.

It's always preferable to add a test along with these fixes, so — if you can timebox it — adding a properly working test would be good, otherwise just get the fix in. :)

For other readers: this is the test in question: #17852 (comment)

I then tried a different version, relying on waitForSelector so that it would work on fast test runners, but it still has issues. Sharing in case it's useful (and Ella has more experience writing these and might know what's up):

diff --git a/packages/e2e-tests/specs/change-detection.test.js b/packages/e2e-tests/specs/change-detection.test.js
index 0f384d7c3..9d0d7208b 100644
--- a/packages/e2e-tests/specs/change-detection.test.js
+++ b/packages/e2e-tests/specs/change-detection.test.js
@@ -6,6 +6,7 @@ import {
 	createNewPost,
 	pressKeyWithModifier,
 	ensureSidebarOpened,
+	openDocumentSettingsSidebar,
 	publishPost,
 } from '@wordpress/e2e-test-utils';
 
@@ -204,6 +205,50 @@ describe( 'Change detection', () => {
 		expect( hadInterceptedSave ).toBe( false );
 	} );
 
+	it( 'Should mark consecutive edits of a same attribute dirty if there was a save in between', async () => {
+		await clickBlockAppender();
+		await page.keyboard.type( 'Hello, World' );
+
+		// Save and wait for "Saved" to confirm save complete.
+		await Promise.all( [
+			page.waitForSelector( '.editor-post-saved-state.is-saved' ),
+			pressKeyWithModifier( 'primary', 'S' ),
+		] );
+
+		// Assert clean editor
+		expect( await page.$( '.editor-post-saved-state.is-saved' ) )
+			.toBeTruthy();
+
+		// Open the sidebar, switch to block settings
+		await openDocumentSettingsSidebar();
+		await page.click( '.edit-post-sidebar__panel-tab[data-label="Block"]' );
+
+		// Make sure our paragraph is selected
+		await page.click( '[data-type="core/paragraph"]' );
+
+		// In the block's inspector controls, increase the font size
+		await page.select( '.components-select-control__input', 'large' );
+		await page.click( '[data-type="core/paragraph"]' );
+
+		// Assert dirtiness
+		await page.waitForSelector( '.editor-post-save-draft' );
+		expect( await page.$( '.editor-post-saved-state.is-saved' ) ).toBeNull();
+
+		// Save and wait for "Saved" to confirm save complete.
+		await Promise.all( [
+			page.waitForSelector( '.editor-post-saved-state.is-saved' ),
+			pressKeyWithModifier( 'primary', 'S' ),
+		] );
+
+		// Increase the font size one more level
+		await page.select( '.components-select-control__input', 'larger' );
+		await page.click( '[data-type="core/paragraph"]' );
+
+		// Assert dirtiness
+		await page.waitForSelector( '.editor-post-save-draft' );
+		expect( await page.$( '.editor-post-saved-state.is-saved' ) ).toBeNull();
+	} );
+
 	it( 'Should prompt if save failed', async () => {
 		await page.type( '.editor-post-title__input', 'Hello World' );

@youknowriad
Copy link
Contributor

I'm merging but please consider a test for this as a follow-up

@youknowriad youknowriad merged commit 657124c into master Oct 11, 2019
@youknowriad youknowriad deleted the fix/all-changes-after-saving-should-be-meaningful branch October 11, 2019 11:10
@mcsf
Copy link
Contributor

mcsf commented Oct 11, 2019 via email

@epiqueras
Copy link
Contributor Author

#17914

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Editor /packages/editor [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WP 5.3b2 / GB 6.6: changing + saving same inspector setting (diff. values) twice is no longer possible
4 participants