@financial-times/o-ads
Version:
This package contains the core functionality used by the FT in providing ads across all of its sites. This includes ft.com, howtospendit.com, ftadviser.com and other specialist titles.
92 lines (73 loc) • 3.95 kB
JavaScript
;
var _gpt = _interopRequireWildcard(require("../../dist-esm/js/ad-servers/gpt.js"));
var _log = _interopRequireDefault(require("../../dist-esm/js/utils/log.js"));
var _GoogleTagMock = _interopRequireDefault(require("./testUtils/GoogleTagMock.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/* eslint-env jest */
/* global jsdom */
jest.mock('./testUtils/GoogleTagMock');
describe('setup', () => {
beforeEach(() => {
window.googletag = new _GoogleTagMock.default();
});
describe('setTargeting()', () => {
test('should strip search terms', () => {
// @ts-ignore jsdom
jsdom.reconfigure({
url: 'https://www.ft.com/search?q=goog'
});
_gpt.default.setup({});
expect(global.googletag.pubads().setTargeting).toBeCalledWith('url', 'https://www.ft.com/search');
});
});
describe('enableLazyLoad()', () => {
test('should disable lazy loading, if the "enableLazyLoad" option is not provided', () => {
_gpt.default.setup({});
expect(global.googletag.pubads().enableLazyLoad).not.toBeCalled();
});
test('should explicitly disable lazy load, if false', () => {
_gpt.default.setup({
enableLazyLoad: false
});
expect(global.googletag.pubads().enableLazyLoad).not.toBeCalled();
});
test('should enable lazy load with default parameters, if lazy loadLoadConf is true', () => {
_gpt.default.setup({
enableLazyLoad: true
});
expect(global.googletag.pubads().enableLazyLoad).toBeCalledWith(_gpt.DEFAULT_LAZY_LOAD);
});
test('should enable lazy load with custom parameters, if lazyLoadConf is a config object', () => {
const gptConfig = {
enableLazyLoad: {
fetchMarginPercent: 300,
renderMarginPercent: 200
}
};
_gpt.default.setup(gptConfig);
expect(global.googletag.pubads().enableLazyLoad).toBeCalledWith(Object.assign({}, _gpt.DEFAULT_LAZY_LOAD, gptConfig.enableLazyLoad));
});
test('should not enable lazy load, if "enableLazyLoad" is not a boolean or an object', () => {
const enableLazyLoad = 'what';
const spyConsoleWarn = jest.spyOn(_log.default, 'warn');
_gpt.default.setup({
enableLazyLoad
});
expect(spyConsoleWarn).toBeCalledWith('lazyLoadConf must be either an object or a boolean', enableLazyLoad);
expect(global.googletag.pubads().enableLazyLoad).not.toBeCalled();
spyConsoleWarn.mockReset();
});
test('should not enable lazy load, if lazyLoadConf is null', () => {
const enableLazyLoad = null;
const spyConsoleWarn = jest.spyOn(_log.default, 'warn');
_gpt.default.setup({
enableLazyLoad
});
expect(spyConsoleWarn).toBeCalledWith('lazyLoadConf must be either an object or a boolean', enableLazyLoad);
expect(global.googletag.pubads().enableLazyLoad).not.toBeCalled();
spyConsoleWarn.mockReset();
});
});
});