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 unit test to remove dependency on amp-ad.js. #5417

Merged
merged 4 commits into from Oct 5, 2016

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Oct 4, 2016

No description provided.

return getAd().then(ad => {
const src = ad.firstChild.getAttribute('src');

return ad3p.layoutCallback().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

already tested before. Remove either one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed from previous test

impl.onLayoutMeasure();
return impl.layoutCallback().then(() => {
const src = ampAd.firstChild.getAttribute('src');
it('should allow position:fixed with whitelisted ad container', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

also mention in description. pass container name to iframe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed test name

clock.tick(100);
expect(impl.renderOutsideViewport()).to.equal(1.25);
});
it('should allow position:fixed with whitelisted ad container', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate, please remove

Copy link
Contributor Author

@lannka lannka Oct 5, 2016

Choose a reason for hiding this comment

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

forgot to change the test name of the other test


beforeEach(() => {
sandbox = sinon.sandbox.create();
return createIframePromise().then(iframe => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see comment //Make sure we run tests without CID available by default from our tests before. I don't feel this is necessary, but just to confirm we don't need to check this anymore.

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 don't think this is valid anymore. We should just have separate test cases for w/ and w/o CID

href: 'blah',
describe('renderOutsideViewport', () => {
it('should allow rendering within 3 viewports by default', () => {
expect(ad3p.renderOutsideViewport()).to.equal(3);
Copy link
Contributor

Choose a reason for hiding this comment

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

wait, this work? I find the test statement totally different from what we have before. We don't have to wait for a sec now?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, i think i get it, because we never layout ad in this case. But then should we test that renderOutsideViewport will be false for 1 sec after we layout an ad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the 1 sec logic is in cocurrent-load.js, it should be better tested there

Copy link
Contributor

Choose a reason for hiding this comment

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

but we don't have test there 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test added

it('should prefer-viewability-over-views', () => {
ad3p.element.setAttribute(
'data-loading-strategy', 'prefer-viewability-over-views');
expect(ad3p.renderOutsideViewport()).to.equal(1.25);
Copy link
Contributor

Choose a reason for hiding this comment

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

same for this one

return iframe.addElement(a);
});
}
// TODO: add test for noContentHandler_()
Copy link
Contributor

Choose a reason for hiding this comment

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

The code for noContentHandler_ may be moved outside 3p-ad-impl later. But before that let's keep still keep the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test will be very different from the current one. I would rather rewrite the test once the code here got extracted to somewhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

But then we wouldn't have test coverage for noContentHandler. I am not sure about this because we are going to change that function, and we definitely want to have test for the upcoming change.

@zhouyx
Copy link
Contributor

zhouyx commented Oct 5, 2016

lgtm

@lannka lannka merged commit ce59850 into ampproject:master Oct 5, 2016
@lannka lannka deleted the refactor_3p_ad_test branch October 5, 2016 23:14
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 6, 2016
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 12, 2016
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants