This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Ads - specifying ad loading viewport margins for different screensizes/page types #1094
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c9945a
wip
andrewgeorgiou1981 747e5f6
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 64d249b
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 844a4a3
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 5de8dad
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 2d9e186
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 9cea797
Ads - Setting viewport margin for specific pagetype/screensizes
andrewgeorgiou1981 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,20 +55,21 @@ module.exports = function (flags, appName, adOptions) { | |
return zone.join('/'); | ||
} | ||
|
||
function setViewportMarginBy (variant) { | ||
switch (variant) { | ||
case '5': | ||
return'5%'; | ||
break; | ||
case '10': | ||
return '10%'; | ||
break; | ||
case '15': | ||
return '15%'; | ||
break; | ||
default: | ||
return '0%'; | ||
function setViewportMarginBy () { | ||
let pt = appName; | ||
pt = pt.toLowerCase().substr(0, 3); | ||
let scrnSize = utils.getScreenSize(); | ||
if (pt === 'fro') { | ||
if (scrnSize < 760) {return '15%';} | ||
else { | ||
if (pt === 'fro' && scrnSize < 980) {return '5%';} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking 'fro' again here shouldn't be necessary |
||
} | ||
} | ||
if (pt === 'str'){ | ||
if (scrnSize < 760) {return '5%';} | ||
else if (scrnSize < 980) {return '15%';} | ||
} | ||
return '0%'; | ||
} | ||
|
||
function isTargetSize () { | ||
|
@@ -78,8 +79,7 @@ module.exports = function (flags, appName, adOptions) { | |
function getViewportMargin () { | ||
let viewportMargin = '0%'; | ||
if (flags.get('adOptimizeLazyLoad') && isTargetSize() ) { | ||
const variant = flags.get('adOptimizeLazyLoad'); | ||
viewportMargin = setViewportMarginBy(variant); | ||
viewportMargin = setViewportMarginBy(); | ||
} | ||
return viewportMargin; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,36 +141,80 @@ describe('Config', () => { | |
expect(config.lazyLoad.viewportMargin).to.equal('0%'); | ||
}); | ||
|
||
context('when screen size is less than 980px and adOptimizeLazyLoad flag is defined', () => { | ||
|
||
beforeEach(() => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 979; }); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
it('Should pass 15% when screen size is narrower than 760px and adOptimizeLazyLoad flag is defined and appName is fro', () => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 750; }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably remove the flag from the tests...it's a little confusing otherwise There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was planning to keep the flag but update it so that its no longer an MVT - this would allow us to toggle the viewport margin. However, i guess it doesnt give us much benefit so, as you say it might be less confusing to remove it. |
||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return '50'; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'front'); | ||
expect(config.lazyLoad.viewportMargin).to.equal('15%'); | ||
}); | ||
|
||
['5', '10', '15'].forEach( margin => { | ||
|
||
it(`Should pass ${margin}% when the flag\'s value is ${margin}`, () => { | ||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return margin; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'article'); | ||
expect(config.lazyLoad.viewportMargin).to.equal(`${margin}%`); | ||
}); | ||
it('Should pass 5% when screen size is narrower than 980px and wider than 759px and adOptimizeLazyLoad flag is defined and appName is fro', () => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 970; }); | ||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return '50'; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'front'); | ||
expect(config.lazyLoad.viewportMargin).to.equal('5%'); | ||
}); | ||
|
||
}); | ||
it('Should pass 5% when screen size is narrower than 760px and adOptimizeLazyLoad flag is defined and appName is stream', () => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 750; }); | ||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return '50'; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'stream'); | ||
expect(config.lazyLoad.viewportMargin).to.equal('5%'); | ||
}); | ||
|
||
it('Should pass 15% when screen size is narrower than 980px and wider than 759px and adOptimizeLazyLoad flag is defined and appName is stream', () => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 970; }); | ||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return '50'; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'stream'); | ||
expect(config.lazyLoad.viewportMargin).to.equal('15%'); | ||
}); | ||
|
||
it('Should pass 0% when adOptimizeLazyLoad flag is defined and appName is article', () => { | ||
sandbox.stub(utils, 'getScreenSize', () => { return 970; }); | ||
const flags = { get: (flagName) => { | ||
switch (flagName) { | ||
case 'adOptimizeLazyLoad': | ||
return '50'; | ||
break; | ||
default: | ||
return true; | ||
} | ||
}}; | ||
const config = oAdsConfig(flags, 'article'); | ||
expect(config.lazyLoad.viewportMargin).to.equal('0%'); | ||
}); | ||
}); | ||
|
||
describe('o-ads', () => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to substring it here? Might be more readable later on to refer to 'front-page' (or whatever the full name is)