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

refactor 3p ad test #5193

Merged
merged 5 commits into from Sep 24, 2016
Merged

refactor 3p ad test #5193

merged 5 commits into from Sep 24, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Sep 23, 2016

follow up with ad test refactoring. PTAL

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

Looks good in general

const fragment = url.substr(url.indexOf('#') + 1);
const data = JSON.parse(fragment);

expect(data.type).to.equal('_ping_');
Copy link
Contributor

Choose a reason for hiding this comment

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

This will give better error message when it fails:

expect(data).have.property('type', '_ping_');

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

'http://ads.localhost:9876/dist.3p/current/integration.js');
const preconnects = doc.querySelectorAll(
'link[rel=preconnect]');
expect(preconnects[preconnects.length - 1].href).to.equal(
Copy link
Contributor

Choose a reason for hiding this comment

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

here too

it('should only layout once', () => {
return getAd().then(ad => {
ad.implementation_.unlayoutCallback();
it('should only layout once', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move this test case up for better grouping.

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

});
ad.appendChild(fallback);
ad.appendChild(placeholder);
expect(placeholder.classList.contains('amp-hidden')).to.be.false;
Copy link
Contributor

@lannka lannka Sep 23, 2016

Choose a reason for hiding this comment

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

expect(placeholder.classList).to.not.contain(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do this here. because there will be error:
AssertionError: object tested must be an array, an object, or a string, but domtokenlist given

const placeholderEl = ad.querySelector('[placeholder]');

ad.implementation_.noContentHandler_();
expect(ad).to.have.class('amp-notsupported');
Copy link
Contributor

Choose a reason for hiding this comment

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

ha, does this work? if it is, we can apply it to line 192

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only works after toggleFallback() is called. https://github.com/ampproject/amphtml/blob/master/src/custom-element.js#L1262
Can't apply to line 192 because we haven't #toggleFallback then.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I was just wondering if the chai assert .to.have.class works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! I see!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tested. worked. changed to use .to.have.class


ad.implementation_.noContentHandler_();
expect(ad).to.have.class('amp-notsupported');
expect(placeholderEl.classList.contains('amp-hidden')).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

clock.tick(900);
expect(impl.renderOutsideViewport()).to.be.false;
clock.tick(100);
expect(impl.renderOutsideViewport()).not.to.be.false;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this same as to.be.true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not in this special case. #renderOutsideViewport() return {boolean|number}

const placeholderEl = ad.querySelector('[placeholder]');

ad.implementation_.noContentHandler_();
expect(ad).to.have.class('amp-notsupported');
Copy link
Contributor

Choose a reason for hiding this comment

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

No, I was just wondering if the chai assert .to.have.class works.

@zhouyx zhouyx merged commit 1eb6379 into ampproject:master Sep 24, 2016
@zhouyx zhouyx deleted the refactor-ad-test branch September 24, 2016 00:28
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants