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

Amp-Img Bind Integration Tests #7721

Merged
merged 55 commits into from
Mar 6, 2017

Conversation

kmh287
Copy link
Contributor

@kmh287 kmh287 commented Feb 22, 2017

Added integration tests for amp-img that test the src, alt, width, and height attributes. I did not add a test for srcset but I can if needed, though these tests will become quite large if we test every supported attribute on every supported amp element exhaustively.

@kmh287
Copy link
Contributor Author

kmh287 commented Mar 3, 2017

@choumx PTAL

@@ -53,10 +52,14 @@ describe.configure().retryOnSaucelabs().run('integration amp-bind', function() {
});
}

function setButtonBinding(button, binding) {
button.setAttribute('on', `tap:AMP.setState(${binding})`);

Choose a reason for hiding this comment

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

Bit of a misnomer. A "binding" is a (property, expression) tuple on an expression -- the element's property is "bound" to the expression. Updating a state var via AMP.setState is not a binding.

I'd rename this method function setStateOnTap(button, key, value).

Copy link
Contributor Author

@kmh287 kmh287 Mar 3, 2017

Choose a reason for hiding this comment

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

function deleted based on other comments

@@ -66,9 +69,10 @@ describe.configure().retryOnSaucelabs().run('integration amp-bind', function() {

it('should update CSS class when class binding changes', () => {
const textElement = fixture.doc.getElementById('textElement');
const button = fixture.doc.getElementById('mutateTextButton');
const changeClassButton =

Choose a reason for hiding this comment

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

Nit: When naming, be only as specific as necessary to disambiguate. I.e. in the absence of other buttons in this scope, just button would suffice. Otherwise readers have to take some time to understand what the "changeClass" prefix signifies.

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.

fixture.doc.getElementById('changeImgSrcButton');
const img = fixture.doc.getElementById('image');
expect(img.getAttribute('src')).to.equal('https://lh3.googleusercontent' +
'.com/5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w300-h200-no');

Choose a reason for hiding this comment

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

Is there a more pithy image URL you could use here? Does it matter than if it's valid?

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.

const originalSrc = 'https://lh3.googleusercontent.com/' +
'5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w300-h200-no';
expect(img.getAttribute('src')).to.equal(originalSrc);
const newSrc = '__amp_source_origin';

Choose a reason for hiding this comment

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

Prefer inlined literals over local vars in unit tests. IMO duplicating simple literals is more readable.

https://engdoc.corp.google.com/eng/doc/devguide/coding/testing/unit-testing-best-practices.shtml?cl=head#constants

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.

expect(img.getAttribute('src')).to.equal(originalSrc);
const newSrc = '__amp_source_origin';
const blockedURLBinding = `imageSrc="${newSrc}"`;
setButtonBinding(changeImgSrcButton, blockedURLBinding);

Choose a reason for hiding this comment

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

Actually probably more readable if you just used a different button for this.

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 Mar 6, 2017

@choumx let me know if you have any other comments

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Nice work.

@kmh287 kmh287 merged commit c5471d3 into ampproject:master Mar 6, 2017
kmh287 added a commit to kmh287/amphtml that referenced this pull request Mar 13, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
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.

2 participants