Skip to content

Commit 22ee9e7

Browse files
robertrmartinezChris Pabst
authored and
Chris Pabst
committed
Eplanning & Adapter Manager: fix testing of innerwidth to fix current build (prebid#7679)
* console log innerWidth * hmmm * more debug * weird * if I change to larger mediaQuery it works I think * stub window.top becasue we are mocking just window * stub similar to sizeConfig test * addressing window things * i camel cased * stub stuff right * remove debug logs
1 parent 8a5c801 commit 22ee9e7

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

test/spec/modules/eplanningBidAdapter_spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,26 +328,25 @@ describe('E-Planning Adapter', function () {
328328
describe('buildRequests', function () {
329329
let bidRequests = [validBid];
330330
let sandbox;
331+
let getWindowSelfStub;
332+
let innerWidth;
331333
beforeEach(() => {
332334
sandbox = sinon.sandbox.create();
335+
getWindowSelfStub = sandbox.stub(utils, 'getWindowSelf');
336+
getWindowSelfStub.returns(createWindow(800));
333337
});
334338

335339
afterEach(() => {
336340
sandbox.restore();
337341
});
338342

339-
const createWindow = () => {
343+
const createWindow = (innerWidth) => {
340344
const win = {};
341345
win.self = win;
342-
win.innerWidth = 1025;
346+
win.innerWidth = innerWidth;
343347
return win;
344348
};
345349

346-
function setupSingleWindow(sandBox) {
347-
const win = createWindow();
348-
sandBox.stub(utils, 'getWindowSelf').returns(win);
349-
}
350-
351350
it('should create the url correctly', function () {
352351
const url = spec.buildRequests(bidRequests, bidderRequest).url;
353352
expect(url).to.equal('https://pbjs.e-planning.net/pbjs/1/' + CI + '/1/localhost/ROS');
@@ -516,7 +515,8 @@ describe('E-Planning Adapter', function () {
516515

517516
it('should return the e parameter with a value according to the sizes in order corresponding to the desktop priority list of the ad units', function () {
518517
let bidRequestsPrioritySizes = [validBidExistingSizesInPriorityListForDesktop];
519-
setupSingleWindow(sandbox);
518+
// overwrite default innerWdith for tests with a larger one we consider "Desktop" or NOT Mobile
519+
getWindowSelfStub.returns(createWindow(1025));
520520
const e = spec.buildRequests(bidRequestsPrioritySizes, bidderRequest).data.e;
521521
expect(e).to.equal('300x250_0:300x250,300x600,970x250');
522522
});

test/spec/unit/core/adapterManager_spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,17 @@ describe('adapterManager tests', function () {
17121712
});
17131713

17141714
describe('sizeMapping', function () {
1715+
let sandbox;
17151716
beforeEach(function () {
1717+
sandbox = sinon.sandbox.create();
17161718
allS2SBidders.length = 0;
17171719
clientTestAdapters.length = 0;
1718-
sinon.stub(window, 'matchMedia').callsFake(() => ({matches: true}));
1720+
// always have matchMedia return true for us
1721+
sandbox.stub(utils.getWindowTop(), 'matchMedia').callsFake(() => ({matches: true}));
17191722
});
17201723

17211724
afterEach(function () {
1722-
matchMedia.restore();
1725+
sandbox.restore();
17231726
config.resetConfig();
17241727
setSizeConfig([]);
17251728
});

0 commit comments

Comments
 (0)