Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alpadotsh committed Sep 25, 2019
1 parent fd27d40 commit 946710f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 5 additions & 4 deletions modules/viBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export function mergeArrays(hashFn, ...args) {
return merged;
}

export function documentFocus(doc) {
return typeof doc.hasFocus === 'function' ? +doc.hasFocus() : undefined;
}

const spec = {
code: 'vi',
supportedMediaTypes: [mediaTypes.VIDEO, mediaTypes.BANNER],
Expand Down Expand Up @@ -373,10 +377,7 @@ const spec = {
};
}
),
focus:
typeof document.hasFocus === 'function'
? +document.hasFocus()
: undefined
focus: documentFocus(document)
},
options: {
contentType: 'application/json',
Expand Down
19 changes: 18 additions & 1 deletion test/spec/modules/viBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
area,
get,
getViewabilityDescription,
mergeArrays
mergeArrays,
documentFocus
} from 'modules/viBidAdapter';

describe('ratioToPercentageCeil', () => {
Expand Down Expand Up @@ -892,3 +893,19 @@ describe('mergeSizes', () => {
).to.deep.equal([[1, 2], [2, 4], [400, 500], [500, 600]]);
});
});

describe('documentFocus', () => {
it('calls hasFocus function if it present, converting boolean to an int 0/1 value, returns undefined otherwise', () => {
expect(
documentFocus({
hasFocus: () => true
})
).to.equal(1);
expect(
documentFocus({
hasFocus: () => false
})
).to.equal(0);
expect(documentFocus({})).to.be.undefined;
});
});

0 comments on commit 946710f

Please sign in to comment.