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

Text and Amp-Carousel Bind Integration Tests #7637

Merged
merged 36 commits into from Mar 3, 2017

Conversation

kmh287
Copy link
Contributor

@kmh287 kmh287 commented Feb 17, 2017

An integration tesat for amp-bind and amp-carousel.

/to @choumx @jridgewell

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

I dislike all these private properties we're exposing for testing. Seems like we should be returning the promises.

this.boundElements_.forEach(boundElement => {
const {element, boundProperties} = boundElement;
const tagName = element.tagName;

this.resources_.mutateElement(element, () => {
const applyPromise = this.resources_.mutateElement(element, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use boundElements#map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 17, 2017

Returning the promise won't quite work because the callers aren't always reachable from the test.

How would you feel about making these properties private and instead exposing methods that return the promises?

@jridgewell
Copy link
Contributor

Returning the promise won't quite work because the callers aren't always reachable from the test.

It'd require reworking several. #apply, #digest, #setState.

How would you feel about making these properties private and instead exposing methods that return the promises?

That's better than using the property directly.

@dreamofabear
Copy link

#7573 changes those methods to return promises FYI.

@kmh287 kmh287 mentioned this pull request Feb 21, 2017
import {createIframePromise} from '../../../../testing/iframe';
import {bindForDoc} from '../../../../src/bind';

describe('test-scrollable-carousel', () => {

Choose a reason for hiding this comment

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

I think amp-bind should have a single integration test test-bind-integration.js with a nested describe() for each component.

A <p> element with a [text] and [class] binding is the simplest starting point. Then amp-img, etc.

let bind;

beforeEach(() => {
return createIframePromise().then(i => {

Choose a reason for hiding this comment

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

Check out how createFixtureIframe is used in other integration tests.

They live in /test/integration/ or in individual extension folders (searching for "test integration" in Sublime's open resource should suffice).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you saying you want me to use a test fixture instead of what I have here?

it('should change slides when the slide variable binding changes', () => {
const impl = carousel.implementation_;
expect(impl.slideIndex_).to.equal(0);
bind.setState({selectedSlide: 1});

Choose a reason for hiding this comment

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

Integration tests should verify functionality at a higher level (e.g. an on="tap:AMP.setState(...) action rather than method invocation).

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 21, 2017

I've made the promises private and exposed methods to wait on them.

@kmh287 kmh287 changed the title Bind-Carousel Integration Test Text and Bind-Carousel Integration Test Feb 21, 2017
@kmh287 kmh287 changed the title Text and Bind-Carousel Integration Test Text and Amp-Carousel Bind Integration Tests Feb 22, 2017
@kmh287
Copy link
Contributor Author

kmh287 commented Feb 23, 2017

#7369

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 27, 2017

@choumx Let me know if you have any more comments.

* @return {?Promise}
* @visibleForTesting
*/
waitForInitializationForTesting() {

Choose a reason for hiding this comment

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

Nit: initializePromiseForTesting

"waitForInitialization" is a verb and sounds like the method is actively doing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/**
* @private {?Promise}
*/
this.applyPromise_ = null;

Choose a reason for hiding this comment

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

This is not set anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

* @return {?Promise}
* @visibleForTesting
*/
waitForApplicationForTesting() {

Choose a reason for hiding this comment

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

setStatePromiseForTesting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

chunkInstanceForTesting(iframe.ampdoc);
toggleExperiment(iframe.win, 'amp-bind', true, true);
bind = installBindForTesting(iframe.ampdoc);
return iframe.ampdoc.whenReady();

Choose a reason for hiding this comment

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

There might be some quirk to using it. Ideally we shouldn't need to manually set up AMP services in the fixture.

I'll patch and give this a try tomorrow.

}).then(() => {
const ampdocService = ampdocServiceFor(iframe.win);
ampdoc = ampdocService.getAmpDoc(iframe.doc);
chunkInstanceForTesting(ampdoc);

Choose a reason for hiding this comment

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

Lines 40-42 shouldn't be necessary.

const ampdocService = ampdocServiceFor(iframe.win);
ampdoc = ampdocService.getAmpDoc(iframe.doc);
chunkInstanceForTesting(ampdoc);
bind = installBindForTesting(ampdoc);

Choose a reason for hiding this comment

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

I think you can use bind.js#bindForDoc and avoid the need for the new method entirely.

Copy link
Contributor Author

@kmh287 kmh287 Feb 28, 2017

Choose a reason for hiding this comment

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

Unfortunately if I add the script tag and try to use bindForDoc it just stalls indefinitely. I can clean this up a bit though.

Choose a reason for hiding this comment

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

Ah, it's because you're missing the amp-bind binary in the fixture.

<script async custom-element="amp-bind" src="dist/v0/amp-bind-0.1.js"></script>

return iframe.awaitEvent('amp:load:start', 1);
}).then(() => {
const ampdocService = ampdocServiceFor(iframe.win);
ampdoc = ampdocService.getAmpDoc(iframe.doc);

Choose a reason for hiding this comment

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

ampdoc.js#getAmpDoc is a more concise way to do this, although not sure you need it after fixing the other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still need the ampdoc to call bindForDoc

@kmh287
Copy link
Contributor Author

kmh287 commented Mar 3, 2017

@jridgewell let me know if you have any more comments


if (opt_verifyOnly) {
this.verify_(results);
return Promise.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: No need to return here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* @return {?Promise}
* @visibleForTesting
*/
initializePromiseForTesting() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nonblocking: @erwinmombay, can you confirm we strip *ForTesting methods?

@kmh287 kmh287 merged commit 711cc13 into ampproject:master Mar 3, 2017
kmh287 added a commit to kmh287/amphtml that referenced this pull request Mar 13, 2017
* carousel test, still in progress

* caorusel integration test working

* cleanup

* cleanup2

* lint errors

* made promises on bindimpl private

* lint error

* pr comment

* wrong path for closure annotation

* changing some type annotations

* pr comments

* lint errors

* retry

* cleanup

* cleanup

* don't access private property

* missing semicolon

* class binding test

* pr comments

* timeout for sauce labs

* title

* merge

* pr comment

* cleanup

* pr comments

* cleanup

* clean

* clean

* renaming to match other integration tests, comment about setup of bind in beforeEach

* more commenting

* pr comment
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
* carousel test, still in progress

* caorusel integration test working

* cleanup

* cleanup2

* lint errors

* made promises on bindimpl private

* lint error

* pr comment

* wrong path for closure annotation

* changing some type annotations

* pr comments

* lint errors

* retry

* cleanup

* cleanup

* don't access private property

* missing semicolon

* class binding test

* pr comments

* timeout for sauce labs

* title

* merge

* pr comment

* cleanup

* pr comments

* cleanup

* clean

* clean

* renaming to match other integration tests, comment about setup of bind in beforeEach

* more commenting

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

Successfully merging this pull request may close these issues.

None yet

3 participants