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

🏗✅ Sandbox all unit and integration tests #34305

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ads/google/a4a/shared/test/test-content-recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getPubControlConfig,
} from '../content-recommendation.js';

describe('getAutoConfig', function () {
describes.sandboxed('getAutoConfig', {}, function () {
it('should use image_stacked on wide slots', function () {
const runTest = (availableWidth, expectedWidth, expectedHeight) => {
expect(
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('getAutoConfig', function () {
});
});

describe('getPubControlConfig', function () {
describes.sandboxed('getPubControlConfig', {}, function () {
it('should use setting when only one provided', function () {
const rawPubControlParams = {
numberOfColumns: '4',
Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/shared/test/test-url-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {buildUrl} from '../url-builder';

describe('buildUrl', () => {
describes.sandboxed('buildUrl', {}, () => {
it('should build a simple URL', () => {
expect(
buildUrl('https://example.test', {'key': 'value'}, Infinity)
Expand Down
6 changes: 3 additions & 3 deletions ads/google/a4a/test/test-line-delimited-response-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
metaJsonCreativeGrouper,
} from '../line-delimited-response-handler';

describe('#line-delimited-response-handler', () => {
describes.sandboxed('#line-delimited-response-handler', {}, (env) => {
let chunkHandlerStub;
let slotData;
let win;
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('#line-delimited-response-handler', () => {
}

beforeEach(() => {
chunkHandlerStub = window.sandbox.stub();
chunkHandlerStub = env.sandbox.stub();
});

describe('stream not supported', () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('#line-delimited-response-handler', () => {
}

beforeEach(() => {
readStub = window.sandbox.stub();
readStub = env.sandbox.stub();
response = {
text: () => Promise.resolve(),
body: {
Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/test/test-traffic-experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
validateExperimentIds,
} from '../traffic-experiments';

describe('all-traffic-experiments-tests', () => {
describes.sandboxed('all-traffic-experiments-tests', {}, () => {
describe('#validateExperimentIds', () => {
it('should return true for empty list', () => {
expect(validateExperimentIds([])).to.be.true;
Expand Down
38 changes: 19 additions & 19 deletions ads/google/a4a/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function noopMethods(
sandbox.stub(impl.element, 'offsetHeight').value(pageLayoutBox.height);
}

describe('Google A4A utils', () => {
describes.sandboxed('Google A4A utils', {}, (env) => {
//TODO: Add tests for other utils functions.

describe('#additionalDimensions', () => {
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('Google A4A utils', () => {
});

it('should add the correct CSI signals', () => {
window.sandbox
env.sandbox
.stub(Services, 'documentInfoForDoc')
.returns({pageViewId: 777});
const mockElement = {
Expand Down Expand Up @@ -388,7 +388,7 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
return fixture.addElement(elem).then(() =>
googleAdUrl(impl, '', 0, [], []).then((url1) => {
expect(url1).to.match(/ady=11/);
Expand All @@ -409,7 +409,7 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
const getRect = () => {
return {'width': 100, 'height': 200};
};
Expand All @@ -418,7 +418,7 @@ describe('Google A4A utils', () => {
};
const getScrollLeft = () => 12.1;
const getScrollTop = () => 34.2;
const viewportStub = window.sandbox.stub(Services, 'viewportForDoc');
const viewportStub = env.sandbox.stub(Services, 'viewportForDoc');
viewportStub.returns({getRect, getSize, getScrollTop, getScrollLeft});
return googleAdUrl(impl, '', 0, {}, []).then((url1) => {
expect(url1).to.match(/scr_x=12&scr_y=34/);
Expand All @@ -441,7 +441,7 @@ describe('Google A4A utils', () => {
[AMP_EXPERIMENT_ATTRIBUTE]: '111,222',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
return fixture.addElement(elem).then(() => {
return googleAdUrl(impl, '', 0, {}, ['789', '098']).then((url1) => {
expect(url1).to.match(/eid=123%2C456%2C789%2C098/);
Expand All @@ -462,7 +462,7 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
impl.win.AMP_CONFIG = {type: 'production'};
impl.win.location.hash = 'foo,deid=123456,654321,bar';
return fixture.addElement(elem).then(() => {
Expand All @@ -484,7 +484,7 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
impl.win.gaGlobal = {cid: 'foo', hid: 'bar'};
return fixture.addElement(elem).then(() => {
return googleAdUrl(impl, '', 0, [], []).then((url) => {
Expand All @@ -506,8 +506,8 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
const createElementStub = window.sandbox.stub(
noopMethods(impl, fixture.ampdoc, env.sandbox);
const createElementStub = env.sandbox.stub(
impl.win.document,
'createElement'
);
Expand Down Expand Up @@ -535,8 +535,8 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
const createElementStub = window.sandbox.stub(
noopMethods(impl, fixture.ampdoc, env.sandbox);
const createElementStub = env.sandbox.stub(
impl.win.document,
'createElement'
);
Expand All @@ -562,9 +562,9 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
impl.win.SVGElement = undefined;
const createElementStub = window.sandbox.stub(
const createElementStub = env.sandbox.stub(
impl.win.document,
'createElement'
);
Expand Down Expand Up @@ -592,11 +592,11 @@ describe('Google A4A utils', () => {
'height': '50',
});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
window.sandbox
noopMethods(impl, fixture.ampdoc, env.sandbox);
env.sandbox
.stub(Services.viewerForDoc(impl.getAmpDoc()), 'getReferrerUrl')
.returns(new Promise(() => {}));
const createElementStub = window.sandbox.stub(
const createElementStub = env.sandbox.stub(
impl.win.document,
'createElement'
);
Expand All @@ -621,7 +621,7 @@ describe('Google A4A utils', () => {
doc.win = fixture.win;
const elem = createElementWithAttributes(doc, 'amp-a4a', {});
const impl = new MockA4AImpl(elem);
noopMethods(impl, fixture.ampdoc, window.sandbox);
noopMethods(impl, fixture.ampdoc, env.sandbox);
return fixture.addElement(elem).then(() => {
return googleAdUrl(impl, '', Date.now(), [], []).then((url) => {
expect(url).to.match(/[&?]bdt=[1-9][0-9]*[&$]/);
Expand Down Expand Up @@ -989,7 +989,7 @@ describe('Google A4A utils', () => {
});

it('should include viewer lastVisibleTime', () => {
window.sandbox.stub(ampdoc, 'getLastVisibleTime').returns(300);
env.sandbox.stub(ampdoc, 'getLastVisibleTime').returns(300);

const vars = getCsiAmpAnalyticsVariables('trigger', a4a, null);
expect(vars['viewerLastVisibleTime']).to.be.a('number');
Expand Down
74 changes: 41 additions & 33 deletions ads/google/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getMultiSizeDimensions,
} from '../utils';

describe('#getMultiSizeDimensions', () => {
describes.sandboxed('#getMultiSizeDimensions', {}, () => {
const multiSizes = [
[300, 300],
[300, 250],
Expand Down Expand Up @@ -143,35 +143,43 @@ describe('#getMultiSizeDimensions', () => {
});
});

describe('#getMatchedContentResponsiveHeightAndUpdatePubParams', () => {
it('should use auto logic when no pub params present', () => {
const element = document.createElement('div');
expect(
getMatchedContentResponsiveHeightAndUpdatePubParams(400, element)
).to.equal(1472);
expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('12');
expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal('1');
expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal(
LayoutType.MOBILE_BANNER_IMAGE_SIDEBYSIDE
);
});

it('should use pub control logic when pub params present', () => {
const element = document.createElement('div');
element.setAttribute(ExternalCorePubVars.ROWS_NUM, '1,2');
element.setAttribute(ExternalCorePubVars.COLUMNS_NUM, '3,4');
element.setAttribute(
ExternalCorePubVars.UI_TYPE,
`${LayoutType.IMAGE_SIDEBYSIDE},${LayoutType.IMAGE_STACKED}`
);

expect(
getMatchedContentResponsiveHeightAndUpdatePubParams(800, element)
).to.equal(382);
expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('2');
expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal('4');
expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal(
LayoutType.PUB_CONTROL_IMAGE_STACKED
);
});
});
describes.sandboxed(
'#getMatchedContentResponsiveHeightAndUpdatePubParams',
{},
() => {
it('should use auto logic when no pub params present', () => {
const element = document.createElement('div');
expect(
getMatchedContentResponsiveHeightAndUpdatePubParams(400, element)
).to.equal(1472);
expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('12');
expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal(
'1'
);
expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal(
LayoutType.MOBILE_BANNER_IMAGE_SIDEBYSIDE
);
});

it('should use pub control logic when pub params present', () => {
const element = document.createElement('div');
element.setAttribute(ExternalCorePubVars.ROWS_NUM, '1,2');
element.setAttribute(ExternalCorePubVars.COLUMNS_NUM, '3,4');
element.setAttribute(
ExternalCorePubVars.UI_TYPE,
`${LayoutType.IMAGE_SIDEBYSIDE},${LayoutType.IMAGE_STACKED}`
);

expect(
getMatchedContentResponsiveHeightAndUpdatePubParams(800, element)
).to.equal(382);
expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('2');
expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal(
'4'
);
expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal(
LayoutType.PUB_CONTROL_IMAGE_STACKED
);
});
}
);
Loading