Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
use window.innerWidth instead of o-viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
fenglish committed Jun 8, 2017
1 parent c253f55 commit e31e61a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"n-ui-foundations": "^1.0.0",
"o-expander": "^4.2.2",
"next-session-client": "^2.3.1",
"n-counter-ad-blocking": "^2.0.0",
"o-viewport": "^3.1.2"
"n-counter-ad-blocking": "^2.0.0"
}
}
5 changes: 2 additions & 3 deletions components/n-ui/ads/js/oAdsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const utils = require('./utils');
const sandbox = require('./sandbox');
const extend = require('o-ads').utils.extend;
const apiUrlRoot = 'https://ads-api.ft.com/v1/';
const oViewport = require('o-viewport');

module.exports = function (flags, appName, adOptions) {
adOptions = adOptions || {};
Expand Down Expand Up @@ -57,10 +56,10 @@ module.exports = function (flags, appName, adOptions) {
}

function getViewportMargin () {
const screen = oViewport.getSize(true);

let viewportMargin;

if (flags.get('adOptimizeLazyLoadSmall') && screen.width < 760 ) {
if (flags.get('adOptimizeLazyLoadSmall') && window.innerWidth < 760 ) {
const variant = flags.get('adOptimizeLazyLoadSmall');
switch (variant) {
case '50':
Expand Down
28 changes: 16 additions & 12 deletions components/n-ui/ads/test/oAdsConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const oAdsConfig = require('../js/oAdsConfig');
const adsSandbox = require('../js/sandbox');
const fakeArticleUuid = '123456';
const fakeConceptUuid = '12345678';
const oViewport = require('o-viewport');

let sandbox;
let targeting;
Expand Down Expand Up @@ -111,17 +110,23 @@ describe('Config', () => {

describe('lazyLoad viewportMargin', () => {

it('Should pass 0% when screen width is wider than 760px', () => {
const stubGetSize = () => { return { height: 'height', width: 760 } };
sandbox.stub(oViewport, 'getSize', stubGetSize);
const flags = { get: () => true };
it('Should pass 0% when window.innerWidth is wider than 760px and adOptimizeLazyLoadSmall flag is defined', () => {
global.innerWidth = 760;
const flags = { get: (flagName) => {
switch (flagName) {
case 'adOptimizeLazyLoadSmall':
return '50';
break;
default:
return true;
}
}};
const config = oAdsConfig(flags, 'article');
expect(config.lazyLoad.viewportMargin).to.equal('0%');
});

it('Should pass 0% when screen width is less than 760px and adOptimizeLazyLoadSmall flag is undefined', () => {
const stubGetSize = () => { return { height: 'height', width: 759 } };
sandbox.stub(oViewport, 'getSize', stubGetSize);
it('Should pass 0% when window.innerWidth is less than 760px and adOptimizeLazyLoadSmall flag is undefined', () => {
global.innerWidth = 759;
const flags = { get: (flagName) => {
switch (flagName) {
case 'adOptimizeLazyLoadSmall':
Expand All @@ -135,15 +140,14 @@ describe('Config', () => {
expect(config.lazyLoad.viewportMargin).to.equal('0%');
});

context('when screen width is less than 760px and adOptimizeLazyLoadSmall flag is defined', () => {
context('when window.innerWidth is less than 760px and adOptimizeLazyLoadSmall flag is defined', () => {

beforeEach(() => {
const stubGetSize = () => { return { height: 'height', width: 759 } };
sandbox.stub(oViewport, 'getSize', stubGetSize);
global.innerWidth = 759;
});

afterEach(() => {
sandbox.restore();
delete global.innerWidth;
});

it('Should pass 50% when the flag\'s value is 50', () => {
Expand Down
8 changes: 4 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
const path = require('path');
const BowerWebpackPlugin = require('bower-webpack-plugin');
const componentsToTest = [
// 'browser',
'components/n-ui/ads'
// 'components/n-ui/tracking',
// 'components/n-ui/subscription-offer-prompt'
'browser',
'components/n-ui/ads',
'components/n-ui/tracking',
'components/n-ui/subscription-offer-prompt'
];

module.exports = function (karma) {
Expand Down

0 comments on commit e31e61a

Please sign in to comment.