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

Core Data: Fix redo behavior and expand test coverage. #17827

Merged
merged 2 commits into from
Oct 8, 2019

Conversation

epiqueras
Copy link
Contributor

Fixes #17825

Description

This PR fixes an issue where explicit undo level creation was being ignored when the last recorded edit had no non-transient edits, i.e. not the blocks property. These explicit undo level actions were also creating an extra undo level, because of some conflicting logic with regular edit actions. This PR also fixes that.

How has this been tested?

E2E tests were expanded to verify that undoing and redoing creates and uses undo levels correctly.

Types of Changes

Bug Fix: Fix redo levels inconsistencies.

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 [Package] Core data /packages/core-data [Feature] History History, undo, redo, revisions, autosave. labels Oct 7, 2019
@epiqueras epiqueras added this to the Gutenberg 6.7 milestone Oct 7, 2019
@epiqueras epiqueras self-assigned this Oct 7, 2019
await clickBlockAppender();

await page.keyboard.type( 'This' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'is' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'test' );
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );
Copy link
Member

Choose a reason for hiding this comment

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

Why is this timeout added? Can't we add a separate test case with the timeout? Are we still testing without the timeout if we add it here?

Copy link
Member

Choose a reason for hiding this comment

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

The test fail when this is removed, which is curious. This line shouldn't be necessary for it to pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need it to make sure the timeout after typing for the undo level creation fires.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, this shouldn't be necessary. You should be able to undo and redo without waiting a second.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does the last level get created otherwise? It's implemented with a timeout.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but when you undo, and there is content in the undo buffer, the buffer should be undone first, then the undo level. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but that's not how it currently works. I'll add that.

Copy link
Member

Choose a reason for hiding this comment

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

This is something that was previously tested with withHistory unit tests. Do you think it's possible to add unit tests for this new reducer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ellatrix
Copy link
Member

ellatrix commented Oct 8, 2019

I adjusted the test a bit so it also tests if the content is the same. It's still weird that the timeout at the start is needed now, but let's try to resolve that in a separate PR. This is already a vast improvement.

@ellatrix ellatrix merged commit 9de487d into master Oct 8, 2019
@ellatrix ellatrix deleted the fix/undo-redo-inconsistency branch October 8, 2019 08:10
@epiqueras
Copy link
Contributor Author

I adjusted the test a bit so it also tests if the content is the same.

We should bring back the snapshots I added. If we only compare the content against itself like that, we are not actually testing that the levels are being created at the right places, just that the total number of levels is correct. The snapshots actually tested that // Undo 2nd paragraph text., does exactly that and nothing else.

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

We should bring back the snapshots I added. If we only compare the content against itself like that, we are not actually testing that the levels are being created at the right places, just that the total number of levels is correct. The snapshots actually tested that // Undo 2nd paragraph text., does exactly that and nothing else.

It doesn't just test the total number of levels? It compares the content to make sure it's restored correctly. We take snapshots during the creation of the content and compare it to the content produced after undoing and redoing changes.

@ellatrix ellatrix mentioned this pull request Oct 9, 2019
5 tasks
@epiqueras
Copy link
Contributor Author

Yes, exactly, but it doesn't care about what that content is, so you're just testing the number of levels of content.

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

That's not just testing the number of levels? We don't care what the content is, we only care that the content is correctly undone and redone.

@epiqueras
Copy link
Contributor Author

With the snapshots we also test that // Undo 2nd paragraph text. is actually undoing the 2nd paragraph text. With these comparisons, we only test that there are a total number of undos and redos and that the state before // Undo 2nd paragraph text. is equal to the state after // Redo 2nd paragraph text..

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

and that the state before // Undo 2nd paragraph text. is equal to the state after // Redo 2nd paragraph text..

So not just the number. 😉 It also tests that the state is equal to the one before any redo or undo actions occurred. We are saving the content while it's being created:

const firstBlock = await getEditedPostContent();
await page.keyboard.type( 'This' );
const firstText = await getEditedPostContent();
await page.keyboard.press( 'Enter' );
const secondBlock = await getEditedPostContent();
await page.keyboard.type( 'is' );
const secondText = await getEditedPostContent();
await page.keyboard.press( 'Enter' );
const thirdBlock = await getEditedPostContent();
await page.keyboard.type( 'test' );
const thirdText = await getEditedPostContent();

@epiqueras
Copy link
Contributor Author

Yes, but that code won't detect if the behavior regresses from something like:

This(Undo Level)is(Undo Level)test

to

T(Undo Level)hisi(Undo Level)stest.

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

It would? It would not be the same as the content first created.

@epiqueras
Copy link
Contributor Author

They would be the same, undo levels === redo levels, that's why I used snapshots.

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

Huh, we are not just comparing the amount of levels...

expect( await getEditedPostContent() ).toBe( firstText );

We are verifying if the content is the correct after undo/redo. If levels would be created in the wrong place, these checks would fail.

@ellatrix
Copy link
Member

ellatrix commented Oct 9, 2019

To me this is much clearer than snapshots, as we are explicitly comparing the initially created text with the changes after undo/redo.

@epiqueras
Copy link
Contributor Author

Oh because the levels are created right after every .type. I see what you mean. Yeah this makes sense, sorry for the confusion.

gziolo pushed a commit that referenced this pull request Oct 15, 2019
* Core Data: Fix redo behavior and expand test coverage.

* e2e test: compare text content instead of matching snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] History History, undo, redo, revisions, autosave. [Package] Core data /packages/core-data [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redoing changes fails
2 participants