Skip to content

Add end-to-end tests for Navigation block#18929

Merged
talldan merged 9 commits intomasterfrom
add/nav-block-e2e-tests
Dec 13, 2019
Merged

Add end-to-end tests for Navigation block#18929
talldan merged 9 commits intomasterfrom
add/nav-block-e2e-tests

Conversation

@talldan
Copy link
Copy Markdown
Contributor

@talldan talldan commented Dec 5, 2019

Description

Closes #18451

Adds e2e tests for the Navigation Block.

How has this been tested?

It is tests.

Types of changes

Tests

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.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

@talldan talldan added [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Status] Blocked Used to indicate that a current effort isn't able to move forward [Block] Navigation Affects the Navigation Block labels Dec 5, 2019
@talldan talldan self-assigned this Dec 5, 2019
@talldan talldan force-pushed the add/nav-block-e2e-tests branch from 8fb7855 to 2df0378 Compare December 5, 2019 10:03
@talldan talldan force-pushed the add/nav-block-e2e-tests branch 3 times, most recently from 0e0bb4e to 3db847b Compare December 6, 2019 09:32
@talldan talldan removed the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Dec 12, 2019
@talldan talldan force-pushed the add/nav-block-e2e-tests branch 7 times, most recently from 31f7d9a to 2216684 Compare December 12, 2019 04:44
@talldan talldan force-pushed the add/nav-block-e2e-tests branch from 2216684 to e70e35d Compare December 12, 2019 06:20
@talldan talldan marked this pull request as ready for review December 12, 2019 06:20
Copy link
Copy Markdown
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Looks good! Left a couple minor comments/questions.

keyCode: isMac ? 93 : 17,
which: isMac ? 93 : 17,
} ),
} )
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.

Was this an auto lint change? I thought we used trailing commas in our JS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only for arrays/objects, but this is a function parameter list. It wasn't a lint fix, but thought I'd tidy it while I was looking at it.

// Ideally this would be `await pressKeyWithModifier( 'primary', 'a' )`
// to select all text like other tests do.
// Unfortunately, these tests don't seem to pass on Travis CI when
// using that approach, while using `Home` and `End` they do pass.
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.

That's odd. What did the failure look like?

Copy link
Copy Markdown
Contributor Author

@talldan talldan Dec 13, 2019

Choose a reason for hiding this comment

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

Yeah, really strange. The call to the function didn't have any effect so the snapshots were failing—where I expected the new text to replace the existing text, instead it was typed into the middle of the field:
"Contact Us" became "ContGet In Touchct Us", but was expected to be "Get In Touch".

Changing the label seems like an important part of the block, so I didn't want to exclude it from the test.

Copy link
Copy Markdown
Contributor Author

@talldan talldan Dec 13, 2019

Choose a reason for hiding this comment

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

Again, worked fine locally, just travis that had the difficulties. 🤷‍♂

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.

I wonder if the keyboard travis uses is different from what we expect. The bit that's failing is all about simulating keypresses.

// Create an empty nav block. The 'create' button is disabled until pages are loaded,
// so we must wait for it to become not-disabled.
await page.waitForXPath( '//button[text()="Create from all top pages"][not(@disabled)]' );
const [ createFromExistingButton ] = await page.$x( '//button[text()="Create from all top pages"][not(@disabled)]' );
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.

If we already awaited for that selector to become available above, do we need to await again?

Copy link
Copy Markdown
Contributor Author

@talldan talldan Dec 13, 2019

Choose a reason for hiding this comment

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

The first function waits for the selector to be present. The next one selects the element so that it can be clicked, that part has to be awaited as well, just how the puppeteer api works.

await createFromExistingButton.click();

// Snapshot should contain the mocked pages.
expect( await getEditedPostContent() ).toMatchSnapshot();
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.

Just curious, did you choose to use snapshots here because the nav item URLs are not shown in the page markup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The snapshots mean the test can check all the relevant attributes are being set correctly. The main shortcoming is that for dynamic blocks it doesn't actually check the markup in the post.

// Add a link to the default Navigation Link block.
await updateActiveNavigationLink( { url: 'https://wordpress.org', label: 'WP' } );

// Move the mouse to reveal the block movers. Without this the test seems to fail.
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.

That's weird, the element is definitely visible on the page and it's focusable too, wonder why page.click doesn't work 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, there were a few curiosities with these tests 😄

It looks like there's a chance the movers will be moved to the toolbar (#18685), so hopefully this won't be a problem for too much longer!

@talldan
Copy link
Copy Markdown
Contributor Author

talldan commented Dec 13, 2019

Thanks for reviewing @tellthemachines!

@talldan talldan merged commit d6b3601 into master Dec 13, 2019
@talldan talldan deleted the add/nav-block-e2e-tests branch December 13, 2019 06:25
@ellatrix
Copy link
Copy Markdown
Member

This is causing failing e2e tests in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Task Issues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation Block: add automated tests

4 participants