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

Add end 2 end test sidebar behaviours on mobile and desktop. #6877

Merged
merged 1 commit into from
Jun 25, 2018

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented May 21, 2018

Description

Sometimes I notice regressions on the sidebar behaviors e.g.:#6876. So I'm adding an end to end test that tests simple sidebar behaviors on mobile and desktop.

To execute the test use:

npm run test-e2e test/e2e/specs/sidebar-behaviour.test.js

The tests will fail because currently we have a bug and #6876 should be merged first.

@jorgefilipecosta jorgefilipecosta added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label May 21, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this May 21, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the add/end-to-end-tests-sidebar-bahaviours branch from 2d7945f to aa86234 Compare May 21, 2018 21:01
await setMobileViewPort();
}

export async function setDesktopViewPort() {
await page.setViewport( { width: 1000, height: 700 } );
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

In our case, I think we don't have any difference using emulate. We just test for mobile using the resolution. But besides that, we need after emulating mobile set again the default behavior for the desktop. One option to do that would be using an emulate( DesktopDevice ) but puppeteer only offers mobile devices by default https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js. So we would need to create a desktop mobile device, or change the tests to use a new page in each test case.

Copy link
Member Author

@jorgefilipecosta jorgefilipecosta May 23, 2018

Choose a reason for hiding this comment

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

Creating a desktop mobile device is simple it is a JSON object so maybe it is a good idea.

await setMobileViewPort();

// the page was resized to mobile
const width = await page.evaluate(
Copy link
Member

Choose a reason for hiding this comment

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

Should it be verified inside the setMobileViewPort method?

Copy link
Member Author

Choose a reason for hiding this comment

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

True the code was updated 👍

@@ -81,6 +108,13 @@ export async function getHTMLFromCodeEditor() {
return textEditorContent;
}

export async function clearLocalStorage() {
await page.$eval( 'body', ( body ) => {
Copy link
Member

@aduth aduth May 31, 2018

Choose a reason for hiding this comment

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

We should be able to use page.evaluate here, which is run as within the context of the browser:

await page.evaluate( () => window.localStorage.clear() );

https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageevaluatepagefunction-args

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @aduth, thank you I applied this version and it works great.
Before I tried it and I had problems but I think the problem was related to other error that was meanwhile solved because now it works exactly as expected.

@jorgefilipecosta jorgefilipecosta force-pushed the add/end-to-end-tests-sidebar-bahaviours branch 2 times, most recently from a99920e to 2b399f4 Compare June 4, 2018 10:31
// eslint-disable-next-line no-undef
fail( error );
} );
export async function newMobileBrowserPage() {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this function used?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was not being used I added it to be consistent we had setMobileViewport, setDesktopViewport, and newDesktopBrowserPage so it made sense to create newMobileBrowserPage. I removed it for now if it is required later it can be easily added.

return window.innerWidth;
}
);
expect( width ).toBeLessThan( 782 );
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we expecting this to be guaranteed by setMobileViewPort ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it should be guaranteed, I removed this check.

Copy link
Member Author

Choose a reason for hiding this comment

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

After the removal of this check the test sometimes started to fail. It turns out it was related with puppeteer issue puppeteer/puppeteer#1751.

I added a waitForFunction to address it.

export async function newDesktopBrowserPage() {
global.page = await browser.newPage();
await setDesktopViewPort();
Copy link
Member

Choose a reason for hiding this comment

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

Capitalization should be "Viewport", if even just for consistency with Puppeteer:

https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetviewportviewport

Copy link
Member Author

Choose a reason for hiding this comment

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

Capitalization corrected, thank your for the catch.

@jorgefilipecosta jorgefilipecosta force-pushed the add/end-to-end-tests-sidebar-bahaviours branch from 2b399f4 to ad220c0 Compare June 22, 2018 16:58
@jorgefilipecosta jorgefilipecosta added the [Status] In Progress Tracking issues with work in progress label Jun 22, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the add/end-to-end-tests-sidebar-bahaviours branch from ad220c0 to f84e091 Compare June 22, 2018 17:23
@jorgefilipecosta jorgefilipecosta removed the [Status] In Progress Tracking issues with work in progress label Jun 22, 2018
@jorgefilipecosta
Copy link
Member Author

Hi @gziolo and @aduth thank you for your review, this PR is read for a new look.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

In general, it looks good and tests well. I had 2 minor comments where I feel we could remove some code duplications and increase readability of the code.

await setDesktopViewport();
}

export async function setDesktopViewport() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we generalize this method as follows:

export async function setViewport( type ) {
    const allowedDimensions = { desktop: { width: 1000, height: 700 } };
    const currentDimmension = allowedDimensions[ type ];
    await page.setViewport( currentDimmension );
    await waitForPageDimensions( currentDimmension.width, currentDimmension.height );
}

I'm wondering if also should align the names with what we use for the viewport module.

Copy link
Member Author

Choose a reason for hiding this comment

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

Feedback was addressed. Than you for the review!

} );

it( 'Should have the sidebar closed by default on mobile', async () => {
await setMobileViewport();
Copy link
Member

Choose a reason for hiding this comment

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

Won't it give false positives because we are setting the desktop viewport first?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are setting the desktop viewport first as the default viewport but Gutenberg is not open. We are only opening Gutenberg in the newPost call.


it( 'Should reopen sidebar the sidebar when resizing from mobile to desktop if the sidebar was closed automatically', async () => {
await newPost();
await setMobileViewport();
Copy link
Member

@gziolo gziolo Jun 25, 2018

Choose a reason for hiding this comment

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

Here we have a different order await setDesktopViewport(); and the new post is created and then changed to mobile. Maybe we should always set viewport in the test just before creating a new post for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I totally agree, in this test cases setting the viewport in the tests make things clear.

@jorgefilipecosta jorgefilipecosta force-pushed the add/end-to-end-tests-sidebar-bahaviours branch from f84e091 to acdba6e Compare June 25, 2018 15:36
@gziolo
Copy link
Member

gziolo commented Jun 25, 2018

Cool, thanks for iterating on this one 🚢

@jorgefilipecosta jorgefilipecosta merged commit e222ccb into master Jun 25, 2018
@jorgefilipecosta jorgefilipecosta deleted the add/end-to-end-tests-sidebar-bahaviours branch June 25, 2018 16:13
oxyc added a commit to generoi/gutenberg that referenced this pull request Jun 26, 2018
* 'master' of https://github.com/WordPress/gutenberg: (69 commits)
  fix: Show permalink editor in editor (WordPress#7494)
  Fix text wrapping in Firefox. (WordPress#7472)
  Try another approach to fixing the sibling inserter in Firefox (WordPress#7530)
  fix: Improve "add block" text in NUX onboarding (WordPress#7511)
  Implement core style of including revisions data on Post response (WordPress#7495)
  Testing: Add e2e test for PluginPostStatusInfo (WordPress#7284)
  Add end 2 end test for sidebar behaviours on mobile and desktop. (WordPress#6877)
  Only save metaboxes when it's not an autosave (WordPress#7502)
  Fix broken links in documentation (WordPress#7532)
  Remove post type 'viewable' compatibility shim (WordPress#7496)
  Fix typo. (WordPress#7528)
  Blocks: Remove wrapping div from paragraph block (WordPress#7477)
  fix: change import for InnerBlocks (WordPress#7484)
  Polish library just a teeeeensy bit (WordPress#7522)
  feat: Add snapshot update script (WordPress#7514)
  Display server error message when one exists (WordPress#7434)
  Fix issues with gallery in IE11. (WordPress#7465)
  Polish region focus style (WordPress#7459)
  Fix IE11 formatting toolbar visibility (WordPress#7413)
  Update plugin version to 3.1. (WordPress#7402)
  ...
@jorgefilipecosta jorgefilipecosta added this to the 3.2 milestone Jul 5, 2018
@@ -0,0 +1,80 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

-behaviour is kinda redundant as a suffix, and doesn't add much value. Any test could be called as such, undo-behavior.test.js, writing-flow-behavior.test.js, etc.

Also, typo since it's spelled "behavior", not "behaviour" :trollface: 🇺🇸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants