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

Fix #3894 - update sizeConfig logic around multiformat bids #3938

Merged
merged 1 commit into from
Jul 9, 2019
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 src/sizeMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export function resolveStatus({labels = [], labelAll = false, activeLabels = []}

let results = {
active: (
allMediaTypes.length > 1 || (allMediaTypes.length === 1 && allMediaTypes[0] !== 'banner')
allMediaTypes.every(type => type !== 'banner')
) || (
allMediaTypes[0] === 'banner' && deepAccess(mediaTypes, 'banner.sizes.length') > 0 && (
allMediaTypes.some(type => type === 'banner') && deepAccess(mediaTypes, 'banner.sizes.length') > 0 && (
labels.length === 0 || (
(!labelAll && (
labels.some(label => maps.labels[label]) ||
Expand Down
105 changes: 93 additions & 12 deletions test/spec/sizeMapping_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ describe('sizeMapping', function () {
}
return matchMediaOverride;
});

sandbox.stub(window, 'matchMedia').callsFake((...args) => {
if (typeof matchMediaOverride === 'function') {
return matchMediaOverride.apply(window, args);
}
return matchMediaOverride;
});
});

afterEach(function () {
Expand Down Expand Up @@ -161,15 +154,14 @@ describe('sizeMapping', function () {
});
});

it('should filter all banner sizes but not disable adUnit if multiple mediaTypes are present', function () {
it('should filter all banner sizes and should disable the adUnit even if other mediaTypes are present', function () {
matchMediaOverride = (str) => str === '(min-width: 0px) and (max-width: 767px)' ? {matches: true} : {matches: false};

let status = resolveStatus(undefined, Object.assign({}, testSizes, {
native: {
type: 'image'
}
}), undefined, sizeConfig);
expect(status.active).to.equal(true);
expect(status.active).to.equal(false);
expect(status.mediaTypes).to.deep.equal({
banner: {
sizes: []
Expand Down Expand Up @@ -210,12 +202,101 @@ describe('sizeMapping', function () {
expect(status.mediaTypes).to.deep.equal(testSizes);
});

it('should activate/decactivate adUnits/bidders based on labels with multiformat ads', function () {
matchMediaOverride = (str) => str === '(min-width: 768px) and (max-width: 1199px)' ? {matches: true} : {matches: false};

let multiFormatSizes = {
banner: {
sizes: [[728, 90], [300, 300]]
},
native: {
type: 'image'
},
video: {
context: 'outstream',
playerSize: [300, 300]
}
};

let status = resolveStatus({
labels: ['tablet', 'test'],
labelAll: true
}, multiFormatSizes, undefined, sizeConfigWithLabels);

expect(status.active).to.equal(false);
expect(status.mediaTypes).to.deep.equal({
banner: {
sizes: [[728, 90]]
},
native: {
type: 'image'
},
video: {
context: 'outstream',
playerSize: [300, 300]
}
});

status = resolveStatus({
labels: ['tablet']
}, multiFormatSizes, undefined, sizeConfigWithLabels);

expect(status.active).to.equal(true);
expect(status.mediaTypes).to.deep.equal({
banner: {
sizes: [[728, 90]]
},
native: {
type: 'image'
},
video: {
context: 'outstream',
playerSize: [300, 300]
}
});

multiFormatSizes.banner.sizes.splice(0, 1, [728, 80]);
status = resolveStatus({
labels: ['tablet']
}, multiFormatSizes, undefined, sizeConfigWithLabels);

expect(status.active).to.equal(false);
expect(status.mediaTypes).to.deep.equal({
banner: {
sizes: []
},
native: {
type: 'image'
},
video: {
context: 'outstream',
playerSize: [300, 300]
}
});

delete multiFormatSizes.banner;
status = resolveStatus({
labels: ['tablet']
}, multiFormatSizes, undefined, sizeConfigWithLabels);

expect(status.active).to.equal(true);
expect(status.mediaTypes).to.deep.equal({
native: {
type: 'image'
},
video: {
context: 'outstream',
playerSize: [300, 300]
}
});
});

it('should active/deactivate adUnits/bidders based on requestBids labels', function () {
let activeLabels = ['us-visitor', 'desktop', 'smart'];

let status = resolveStatus({
labels: ['uk-visitor'],
activeLabels
labels: ['uk-visitor'], // from adunit
activeLabels // from requestBids.labels
}, testSizes, undefined, sizeConfigWithLabels);

expect(status.active).to.equal(false);
Expand Down