Skip to content

Commit

Permalink
PLY-534: added prebid.bids.labelAny and prebid.bids.labelAll to adver…
Browse files Browse the repository at this point in the history
…tising slot config prop type

Change-Id: I0c6fb48747fdd210f2f278fc37d56a62ee5e2b56
  • Loading branch information
Patrick Hund committed Jun 26, 2018
1 parent b94a53a commit 940e624
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 1.0.7 / 26 Jun 2018

* removed obsolete prebid size mapping code that doesn't work with Prebid 1
* added `prebid.sizeConfig` to advertising config prop type
* added `prebid.bids.labelAny` and `prebid.bids.labelAll` to advertising slot config prop type

## 1.0.6 / 25 Jun 2018

Expand Down
2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-prebid",
"version": "1.0.7-beta.0",
"version": "1.0.7-beta.1",
"description": "Library for ad placements with Prebid header bidding in React applications",
"main": "index.js",
"esnext": "index-esnext.js",
Expand Down
11 changes: 10 additions & 1 deletion src/components/utils/AdvertisingConfigPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ export default PropTypes.shape({
).isRequired
})
])
})
}),
sizeConfig: PropTypes.arrayOf(
PropTypes.shape({
mediaQuery: PropTypes.string.isRequired,
sizesSupported: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.number)])
),
labels: PropTypes.arrayOf(PropTypes.string)
})
)
}),
sizeMappings: PropTypes.objectOf(
PropTypes.arrayOf(
Expand Down
136 changes: 136 additions & 0 deletions src/components/utils/AdvertisingConfigPropType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,139 @@ describe('When I check the prop types with a size mapping', () => {
});
}
});

describe('When I check the prop types with a prebid size config', () => {
const testCases = [
{
sizeConfig: {},
expectToPass: false
},
{
sizeConfig: 'corge',
expectToPass: false
},
{
sizeConfig: [],
expectToPass: true
},
{
sizeConfig: [{}],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: false
}
],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: 666
}
],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: { garply: 'baz' }
}
],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)'
}
],
expectToPass: true
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
sizesSupported: 'quux'
}
],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
sizesSupported: []
}
],
expectToPass: true
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
sizesSupported: ['fluid']
}
],
expectToPass: true
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
sizesSupported: [[320, 250]]
}
],
expectToPass: true
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
sizesSupported: ['fluid', [320, 250]]
}
],
expectToPass: true
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
labels: 'phone'
}
],
expectToPass: false
},
{
sizeConfig: [
{
mediaQuery: '(min-width: 490px)',
labels: ['phone']
}
],
expectToPass: true
}
];
for (const { sizeConfig, expectToPass } of testCases) {
describe(`${typeof sizeConfig === 'object' ? JSON.stringify(sizeConfig) : sizeConfig}`, () => {
let result;
beforeEach(
() =>
(result = checkPropTypes(MyComponent.propTypes, {
config: {
prebid: {
sizeConfig
}
}
}))
);
if (expectToPass) {
describe('the prop type validation', () => it('passes', () => void expect(result).toBeUndefined()));
} else {
describe('the prop type validation', () => it('fails', () => void expect(result).toBeTruthy()));
}
});
}
});
4 changes: 3 additions & 1 deletion src/components/utils/AdvertisingSlotConfigPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default PropTypes.shape({
bids: PropTypes.arrayOf(
PropTypes.shape({
bidder: PropTypes.string.isRequired,
params: PropTypes.object
params: PropTypes.object,
labelAny: PropTypes.arrayOf(PropTypes.string),
labelAll: PropTypes.arrayOf(PropTypes.string)
})
).isRequired
})
Expand Down
108 changes: 108 additions & 0 deletions src/components/utils/AdvertisingSlotConfigPropType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,111 @@ describe('When I check the prop types for a valid slot config', () => {
});
}
});

describe('When I check the prop types a slot config', () => {
const testCases = [
{
labelAny: 'blub',
expectToPass: false
},
{
labelAny: [],
expectToPass: true
},
{
labelAny: ['blub'],
expectToPass: true
},
{
labelAny: [666],
expectToPass: false
}
];
for (const { labelAny, expectToPass } of testCases) {
describe(`with a prebid bids labelAny config ${labelAny}`, () => {
let result;
beforeEach(
() =>
(result = checkPropTypes(MyComponent.propTypes, {
config: {
id: 'thud',
prebid: [
{
mediaTypes: {
banner: {
sizes: [[320, 240]]
}
},
bids: [
{
bidder: 'my-precious-bidder',
labelAny
}
]
}
]
}
}))
);
if (expectToPass) {
describe('the prop type validation', () => it('passes', () => void expect(result).toBeUndefined()));
} else {
describe('the prop type validation', () => it('fails', () => void expect(result).toBeTruthy()));
}
});
}
});

describe('When I check the prop types a slot config', () => {
const testCases = [
{
labelAll: 'blub',
expectToPass: false
},
{
labelAll: [],
expectToPass: true
},
{
labelAll: ['blub'],
expectToPass: true
},
{
labelAll: [666],
expectToPass: false
}
];
for (const { labelAll, expectToPass } of testCases) {
describe(`with a prebid bids labelAll config ${labelAll}`, () => {
let result;
beforeEach(
() =>
(result = checkPropTypes(MyComponent.propTypes, {
config: {
id: 'thud',
prebid: [
{
mediaTypes: {
banner: {
sizes: [[320, 240]]
}
},
bids: [
{
bidder: 'my-precious-bidder',
labelAll
}
]
}
]
}
}))
);
if (expectToPass) {
describe('the prop type validation', () => it('passes', () => void expect(result).toBeUndefined()));
} else {
describe('the prop type validation', () => it('fails', () => void expect(result).toBeTruthy()));
}
});
}
});

0 comments on commit 940e624

Please sign in to comment.