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
Conversation
return getAd().then(ad => { | ||
const src = ad.firstChild.getAttribute('src'); | ||
|
||
return ad3p.layoutCallback().then(() => { |
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.
already tested before. Remove either one.
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.
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', () => { |
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.
also mention in description. pass container name to iframe
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.
changed test name
clock.tick(100); | ||
expect(impl.renderOutsideViewport()).to.equal(1.25); | ||
}); | ||
it('should allow position:fixed with whitelisted ad container', () => { |
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.
duplicate, please remove
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.
forgot to change the test name of the other test
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
return createIframePromise().then(iframe => { |
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 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.
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 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); |
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.
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?
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.
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?
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.
the 1 sec logic is in cocurrent-load.js, it should be better tested there
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.
but we don't have test there 😢
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.
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); |
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.
same for this one
return iframe.addElement(a); | ||
}); | ||
} | ||
// TODO: add test for noContentHandler_() |
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.
The code for noContentHandler_
may be moved outside 3p-ad-impl later. But before that let's keep still keep the test.
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.
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.
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.
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.
lgtm |
No description provided.