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 basic e2e tests for amp-list-load-more #21064

Merged
merged 6 commits into from Feb 26, 2019

Conversation

cathyxz
Copy link
Contributor

@cathyxz cathyxz commented Feb 26, 2019

Adds two simple fixtures respectively for the manual load-more and automatic load-more cases. Tests that each case successfully renders all items and load-more visuals, and successfully triggers a load-more on click or on scroll.

const article = await controller.findElement('article');
await controller.scroll(article, {top: 10});

const sixthItem = await controller.findElement(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to wait for load-more to finish?

Choose a reason for hiding this comment

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

I suppose you could also wait for the indicator to go away, then check the number of items (assuming the rendering of items happens at the same time).

Copy link
Contributor

Choose a reason for hiding this comment

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

For now waiting for an element to appear that is not initially present is the best way, IMO

const article = await controller.findElement('article');
await controller.scroll(article, {top: 10});

const sixthItem = await controller.findElement(

Choose a reason for hiding this comment

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

I suppose you could also wait for the indicator to go away, then check the number of items (assuming the rendering of items happens at the same time).

expect(visibility).to.equal('visible');
const display = await controller.getElementCssValue(seeMoreButton,
'display');
expect(display).to.equal('block');

Choose a reason for hiding this comment

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

@cvializ Would it be useful to have a simple isDisplayed method here? For example, the approach outlined here: https://w3c.github.io/webdriver/#dfn-bot-dom-isshown

Basically check if something has a rect (therefore has some sort of display, and all the parents do), check the opacity to see if it is actually visible (I think you need to check the ancestors too), check the computed visibility property and optionally check if it is hidden overflow from a parent element.

We could also start with something simple and add to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1! That would be nice indeed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like that could be more than is needed, since our tests should be checking the state of the components they're testing. This feels like a heuristic more than a clear assertion and could introduce flakiness when people use it believing it to be more solid.

For example, is something visible if it meeds all the above criteria but is also position: absolute; left: -9999? What is the author of the code's intention? What if its opacity is .0001 for a technical reason like needing to be picked up by a screen reader?

I think for initial testing / proving it can be implemented as a helper method in test code, then be promoted to a FunctionalTestController API method after it is stable and well-defined. What do you think?

Choose a reason for hiding this comment

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

Sounds good, we can start with just a helper function in this file that does what is needed. For the position: absolute; left: -9999 case, screen readers will not be able to interact with that item, so I think that is also something we will want to check for. This is covered by the "hidden by overflow from a parent element", where the element is positioned in the overflow area of the body (otherwise the body would scroll horizontally).

Perhaps a better function would be isInteractable (which is less vague than isDisplayed), which would not check opacity, since that does not affect whether the element can receive interaction.

await controller.scroll(article, {top: 10});

const sixthItem = await controller.findElement(
'div.item:nth-child(4)');

Choose a reason for hiding this comment

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

CSS says 4, variable name says 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. ToT


it('should load more items on scroll', async() => {
let listItems = await controller.findElements('.item');
expect(listItems.length).to.equal(2);

Choose a reason for hiding this comment

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

can you try expect(listItems).to.have.length(2)?

extensions/amp-list/0.1/test-e2e/test-load-more-manual.js Outdated Show resolved Hide resolved
expect(listItems.length).to.equal(2);

const loader = await controller.findElement('[load-more-loading]');
expect(loader).to.not.be.null;

Choose a reason for hiding this comment

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

I think you can also do expect(loader).to.be.ok, I seem to get a bit tripped up reading to.not.be.null personally.

const seeMoreButton = await controller.findElement('[load-more-button]');
expect(seeMoreButton).to.not.be.null;
const visibility = await controller.getElementCssValue(seeMoreButton,
'visibility', 'visible');

Choose a reason for hiding this comment

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

@cvializ Hmm, getElementCssValue says it has a third arg in the abstract method, but the actual implementation does not. Should we remove the third arg from the abstract method since expect will already wait for it to go the desired value?

Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

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

LGTM

const article = await controller.findElement('article');
await controller.scroll(article, {top: 10});

const sixthItem = await controller.findElement(
Copy link
Contributor

Choose a reason for hiding this comment

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

For now waiting for an element to appear that is not initially present is the best way, IMO

@cathyxz cathyxz merged commit 8e1a1c5 into ampproject:master Feb 26, 2019
@cathyxz cathyxz deleted the feature/list-tests branch February 26, 2019 21:36
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* First e2e test for amp-list-load-more

* Added a load-more items test

* Add test for load-more-end

* Add basic tests for load-more=auto

* Fix spelling, variable names, spaces

* to be ok
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
* First e2e test for amp-list-load-more

* Added a load-more items test

* Add test for load-more-end

* Add basic tests for load-more=auto

* Fix spelling, variable names, spaces

* to be ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants