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
Conversation
There was a problem hiding this 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, () => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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? |
It'd require reworking several.
That's better than using the property directly. |
#7573 changes those methods to return promises FYI. |
import {createIframePromise} from '../../../../testing/iframe'; | ||
import {bindForDoc} from '../../../../src/bind'; | ||
|
||
describe('test-scrollable-carousel', () => { |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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).
I've made the promises private and exposed methods to wait on them. |
@choumx Let me know if you have any more comments. |
extensions/amp-bind/0.1/bind-impl.js
Outdated
* @return {?Promise} | ||
* @visibleForTesting | ||
*/ | ||
waitForInitializationForTesting() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
extensions/amp-bind/0.1/bind-impl.js
Outdated
/** | ||
* @private {?Promise} | ||
*/ | ||
this.applyPromise_ = null; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
extensions/amp-bind/0.1/bind-impl.js
Outdated
* @return {?Promise} | ||
* @visibleForTesting | ||
*/ | ||
waitForApplicationForTesting() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setStatePromiseForTesting
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
d1ec400
to
81a80de
Compare
}).then(() => { | ||
const ampdocService = ampdocServiceFor(iframe.win); | ||
ampdoc = ampdocService.getAmpDoc(iframe.doc); | ||
chunkInstanceForTesting(ampdoc); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
2e0c115
to
5462373
Compare
return iframe.awaitEvent('amp:load:start', 1); | ||
}).then(() => { | ||
const ampdocService = ampdocServiceFor(iframe.win); | ||
ampdoc = ampdocService.getAmpDoc(iframe.doc); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@jridgewell let me know if you have any more comments |
extensions/amp-bind/0.1/bind-impl.js
Outdated
|
||
if (opt_verifyOnly) { | ||
this.verify_(results); | ||
return Promise.resolve(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
* 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
* 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
An integration tesat for amp-bind and amp-carousel.
/to @choumx @jridgewell