Skip to content

Commit

Permalink
Add unit tests for the Auto Ads reponsive upgrade changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaming-X committed May 11, 2020
1 parent 721f5f0 commit c12d66f
Showing 1 changed file with 63 additions and 6 deletions.
69 changes: 63 additions & 6 deletions extensions/amp-auto-ads/0.1/test/test-placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,18 @@ describes.realWin(
});
});

it('should set the correct attributes for responsive enabled ads using amp-ad responsive', () => {
it('should set the responsive attributes for responsive enabled mobile users.', () => {
const anchor = doc.createElement('div');
anchor.id = 'anId';
container.appendChild(anchor);

const mutator = Services.mutatorForDoc(anchor);
env.sandbox.stub(mutator, 'requestChangeSize').callsFake(() => {
return Promise.resolve();
});
env.sandbox.stub(mutator.viewport_, 'getWidth').callsFake(() => 2000);
const viewportMock = env.sandbox.mock(
Services.viewportForDoc(env.win.document)
);
viewportMock
.expects('getSize')
.returns({width: 411, height: 823})
.atLeast(1);

const placements = getPlacementsFromConfigObj(ampdoc, {
placements: [
Expand Down Expand Up @@ -661,6 +663,61 @@ describes.realWin(
});
});

it('should not set the responsive attributes for responsive enabled desktop users.', () => {
const anchor = doc.createElement('div');
anchor.id = 'anId';
container.appendChild(anchor);

const placements = getPlacementsFromConfigObj(ampdoc, {
placements: [
{
anchor: {
selector: 'DIV#anId',
},
pos: 2,
type: 1,
},
],
});
expect(placements).to.have.lengthOf(1);

const attributes = {
'type': '_ping_',
};

const sizing = {};
const adTracker = new AdTracker([], {
initialMinSpacing: 0,
subsequentMinSpacing: [],
maxAdCount: 10,
});

const viewportMock = env.sandbox.mock(
Services.viewportForDoc(env.win.document)
);
viewportMock
.expects('getSize')
.returns({width: 1620, height: 1300})
.atLeast(1);

return placements[0]
.placeAd(attributes, sizing, adTracker, true)
.then((placementState) => {
const adElement = anchor.firstChild;
expect(adElement.tagName).to.equal('AMP-AD');
expect(adElement.getAttribute('type')).to.equal('_ping_');
expect(adElement.getAttribute('layout')).to.equal('fixed-height');
expect(adElement.getAttribute('height')).to.equal('0');
expect(adElement.hasAttribute('data-auto-format')).to.be.false;
expect(adElement.hasAttribute('data-full-width')).to.be.false;
expect(adElement.style.marginTop).to.equal('');
expect(adElement.style.marginBottom).to.equal('');
expect(adElement.style.marginLeft).to.equal('');
expect(adElement.style.marginRight).to.equal('');
expect(placementState).to.equal(PlacementState.PLACED);
});
});

it('should report placement placed when resize allowed', () => {
const anchor = doc.createElement('div');
anchor.id = 'anId';
Expand Down

0 comments on commit c12d66f

Please sign in to comment.