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

stub window.top in tests #13

Merged
merged 1 commit into from
Sep 13, 2018
Merged
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
61 changes: 36 additions & 25 deletions test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ describe('33acrossBidAdapter:', function () {
const SITE_ID = 'pub1234';
const PRODUCT_ID = 'product1';
const END_POINT = 'https://ssc.33across.com/api/v1/hb';
const SYNC_ENDPOINT = 'https://de.tynt.com/deb/v2?m=xch&rt=html';

let element;
let sandbox;
let bidRequests;
let sandbox;

function TtxRequestBuilder() {
const ttxRequest = {
Expand Down Expand Up @@ -126,6 +125,26 @@ describe('33acrossBidAdapter:', function () {
}

beforeEach(function() {
element = {
x: 0,
y: 0,

width: 0,
height: 0,

getBoundingClientRect: () => {
return {
width: element.width,
height: element.height,

left: element.x,
top: element.y,
right: element.x + element.width,
bottom: element.y + element.height
};
}
};

bidRequests = [
{
bidId: 'b1',
Expand All @@ -147,26 +166,6 @@ describe('33acrossBidAdapter:', function () {

sandbox = sinon.sandbox.create();
sandbox.stub(document, 'getElementById').withArgs('div-id').returns(element);

element = {
x: 0,
y: 0,

width: 0,
height: 0,

getBoundingClientRect: () => {
return {
width: element.width,
height: element.height,

left: element.x,
top: element.y,
right: element.x + element.width,
bottom: element.y + element.height
};
}
};
});

afterEach(function() {
Expand Down Expand Up @@ -254,6 +253,9 @@ describe('33acrossBidAdapter:', function () {

Object.assign(element, { width: 600, height: 400 });

sandbox.stub(window.top, 'innerWidth').value(800);
sandbox.stub(window.top, 'innerHeight').value(600);

expect(buildRequests(bidRequests)).to.deep.equal([serverRequest]);
});
});
Expand All @@ -269,20 +271,26 @@ describe('33acrossBidAdapter:', function () {

Object.assign(element, { x: -300, y: 0, width: 207, height: 320 });

sandbox.stub(window.top, 'innerWidth').value(324);
sandbox.stub(window.top, 'innerHeight').value(212);

expect(buildRequests(bidRequests)).to.deep.equal([serverRequest]);
});
});

context('when element is partially in view', function() {
it('returns percentage', function() {
const ttxRequest = new TtxRequestBuilder()
.withViewabiliuty({amount: 40})
.withViewabiliuty({amount: 50})
.build();
const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();

Object.assign(element, { width: 100, height: 1500 });
Object.assign(element, { width: 800, height: 800 });

sandbox.stub(window.top, 'innerWidth').value(800);
sandbox.stub(window.top, 'innerHeight').value(400);

expect(buildRequests(bidRequests)).to.deep.equal([serverRequest]);
});
Expand All @@ -292,7 +300,7 @@ describe('33acrossBidAdapter:', function () {
it('try to use alternative values', function() {
const ttxRequest = new TtxRequestBuilder()
.withSizes([{ w: 800, h: 1200, ext: {} }])
.withViewabiliuty({amount: 50})
.withViewabiliuty({amount: 25})
.build();
const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
Expand All @@ -301,6 +309,9 @@ describe('33acrossBidAdapter:', function () {
Object.assign(element, { width: 0, height: 0 });
bidRequests[0].sizes = [[800, 1200]];

sandbox.stub(window.top, 'innerWidth').value(800);
sandbox.stub(window.top, 'innerHeight').value(300);

expect(buildRequests(bidRequests)).to.deep.equal([serverRequest]);
});
});
Expand Down