Skip to content

Stabilise List E2E tests - #17482

Merged
ellatrix merged 2 commits into
masterfrom
try/stabilise-list-e2e-tests
Sep 20, 2019
Merged

ellatrix merged 2 commits into
masterfrom
try/stabilise-list-e2e-tests

Conversation

@ellatrix

@ellatrix ellatrix commented Sep 19, 2019 •

Copy link
Copy Markdown
Member

Description

This is an attempt to stabilise list E2E tests and improves marking automatic changes, which enables undo through Backspace and Escape.

Looking back, it doesn't seem like a good idea to request an idle callback through RichText, as the component will be unmounted after an automatic change. Instead, it's now an effect of MARK_AUTOMATIC_CHANGE to make the marking "final". A problem with marking automatic changes is that there will be async selection changes from other effects, which should be ignored. They were ignored by using requestIdleCallback, so a change was only marked after everything had been completed. Instead of this, an automatic change will immediately be marked, but marked as "pending", during which time selection changes will not unmark it. During the first idle period, the change will be marked as "final", after which any selection changes will unmark the automatic change.

How has this been tested?

Screenshots

Types of changes

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.

@ellatrix
ellatrix requested a review from mcsf September 19, 2019 13:48
@gziolo gziolo added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Bug An existing feature does not function as intended [Package] Rich text /packages/rich-text [Package] Block editor /packages/block-editor and removed [Package] Rich text /packages/rich-text labels Sep 19, 2019
MARK_AUTOMATIC_CHANGE( action, store ) {
const {
setTimeout,
requestIdleCallback = ( callback ) => setTimeout( callback, 100 ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clever.

@ellatrix

Copy link
Copy Markdown
Member Author

Thanks for the review, @epiqueras!

@ellatrix
ellatrix merged commit ef2ea56 into master Sep 20, 2019
@ellatrix
ellatrix deleted the try/stabilise-list-e2e-tests branch September 20, 2019 10:29
if ( state !== 'final' ) {
return state;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • The function signature should be updated so the @return type moves from bool to string. The name should also be changed from the did* boolean form.
  • When action type is SELECTION_CHANGE but state is 'final', the reducer will implicitly return undefined. That value might be fine (though we might prefer null? no strong opinion here), but let's make it explicit by adding a fallback return statement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mcsf What name would you suggest for the reducer? For any other action we also explicitly return undefined. Personally I like it to be undefined. I'm fine with adding an explicit return statement for the action we're handling.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The name could be as plain as automaticChangeStatus, since that's a reflection of what it contains.

For any other action we also explicitly return undefined.

undefined is fine with me, as long as explicit.

Meanwhile, this reducer is a bit particular. For most reducers, the default behaviour is to keep state unchanged. That is, unless the reducer receives a particular action that matters, we always return state in the end. This isn't the case with didAutomaticChange, though, because the default behaviour is now to reset to undefined. So I would add that as something explicit too:

switch ( … ) {
 …
}

// Once we're no longer marking changes or changing selection, reset state.
return undefined;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To me, that was the beauty of of it. By default, a reducer resets any state to undefined, which we make use of here. Returning undefined explicitly here seems a bit strange to me (null sounds better then). A return statement returns undefined by default, so it could be omitted. A function returns undefined by default, so it could be omitted (returning nothing at the end of a function seems strange as well).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could still comment in the reducer though, that by default, we reset state instead of keeping state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As long as there's something that reveals intention, even if just a comment, that's what matters to me.

@mcsf mcsf mentioned this pull request Sep 25, 2019
5 tasks done
ellatrix added a commit that referenced this pull request Sep 26, 2019
@ellatrix ellatrix mentioned this pull request Sep 26, 2019
5 tasks done
ellatrix added a commit that referenced this pull request Sep 26, 2019
@youknowriad youknowriad added this to the Gutenberg 6.6 milestone Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants