Skip to content

Commit

Permalink
Merge branch 'oil-173-vendors' into noticket-stabilize-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phogel committed Jul 10, 2018
2 parents 37ddcd3 + 35a03ff commit 0029eae
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 33 deletions.
6 changes: 6 additions & 0 deletions etc/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ module.exports = {
chunks: ['oilstub', 'oil'],
chunksSortMode: 'dependency',
inject: 'head'
}, {
filename: 'demos/advanced-settings-limited-vendors.html',
template: path.resolve(sourcePath, 'demos', 'advanced-settings-limited-vendors.html'),
chunks: ['oilstub', 'oil'],
chunksSortMode: 'dependency',
inject: 'head'
}, {
filename: 'demos/advanced-settings-purposes-default.html',
template: path.resolve(sourcePath, 'demos', 'advanced-settings-purposes-default.html'),
Expand Down
1 change: 1 addition & 0 deletions etc/karma.conf.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function (config) {
'coverage',
'coveralls'
],

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"e2esafari": "./node_modules/.bin/nightwatch -c etc/nightwatch.local.conf.js -e safari",
"test": "npm run test:unit && npm run test:node",
"test:unit": "cross-env NODE_ENV=test karma start etc/karma.conf.ci.js",
"test:unit:fast": "cross-env NODE_ENV=test karma start etc/karma.conf.js",
"test:node": "mocha 3000 test/node",
"test:selenium": "node etc/nightwatch.jenkins.conf.js && mkdir -p target/reports &&./node_modules/.bin/nightwatch -c etc/nightwatch.jenkins.conf.js -e chrome",
"test:watch": "cross-env SNAPSHOT=$SNAPSHOT cross-env NODE_ENV=test karma start etc/karma.conf.js",
Expand Down
39 changes: 39 additions & 0 deletions src/demos/advanced-settings-limited-vendors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Test Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- tag::oil-config[] -->
<script id="oil-configuration" type="application/configuration">
{
"advanced_settings": true,
"iabVendorWhitelist": [2,3],
"show_limited_vendors": true
}
</script>
<!-- end::oil-config[] -->
<style>
body {
font-family: 'Nunito', sans-serif;
font-size: 60px;
color: #f7f7f7;
min-height: 100vh;
height: 100%;
background: linear-gradient(20deg, #3a871a 0%, #a5ba10 50%, #cfcd26 100%);
padding: 0;
margin: 0;
}

.demoname {
padding: 24px;
}
</style>
</head>

<body>
<div class="demoname">Group A Site A</div>
<!--<div id="oil-preference-center"></div>-->
</body>
</html>
5 changes: 5 additions & 0 deletions src/scripts/core/core_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@ export function gdprApplies() {
export function setGdprApplies(value = true) {
setConfigValue(OIL_CONFIG.ATTR_GDPR_APPLIES, value);
}

export function getShowLimitedVendors() {
return getConfigValue(OIL_CONFIG.ATTR_SHOW_LIMITED_VENDORS, false);
}

1 change: 1 addition & 0 deletions src/scripts/core/core_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const OIL_CONFIG = {
ATTR_CUSTOM_PURPOSES: 'customPurposes',
ATTR_IAB_VENDOR_BLACKLIST: 'iabVendorBlacklist',
ATTR_IAB_VENDOR_WHITELIST: 'iabVendorWhitelist',
ATTR_SHOW_LIMITED_VENDORS: 'show_limited_vendors',
ATTR_ADVANCED_SETTINGS_PURPOSES_DEFAULT: 'advanced_settings_purposes_default',
ATTR_DEFAULT_TO_OPTIN: 'default_to_optin',
ATTR_GDPR_APPLIES_GLOBALLY: 'gdpr_applies_globally',
Expand Down
7 changes: 5 additions & 2 deletions src/scripts/core/core_oil.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ export function initOilLayer() {
}

function registerDomElementActivationManager() {
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', onDomContentLoaded);
}

function onDomContentLoaded() {
document.removeEventListener('DOMContentLoaded', onDomContentLoaded);
manageDomElementActivation();
});
}

function attachCommandCollectionFunctionToWindowObject() {
Expand Down
19 changes: 17 additions & 2 deletions src/scripts/core/core_vendor_information.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getIabVendorBlacklist, getIabVendorListUrl, getIabVendorWhitelist } from './core_config';
import { logError } from './core_log';
import { getIabVendorBlacklist, getIabVendorListUrl, getIabVendorWhitelist, getShowLimitedVendors } from './core_config';
import { logInfo, logError } from './core_log';
import { fetchJsonData } from './core_utils';

export const DEFAULT_VENDOR_LIST = {
Expand Down Expand Up @@ -69,6 +69,21 @@ export function clearVendorListCache() {
cachedVendorList = undefined;
}

export function getVendorsToDisplay() {
return getShowLimitedVendors() ? getLimitedVendors() : getVendors();
}

export function getLimitedVendors() {
let vendors = getVendors();
const limitedIds = getLimitedVendorIds();

logInfo('limiting vendors');

vendors = vendors.filter(vendor => limitedIds.indexOf(vendor.id) > -1);

return vendors;
}

export function getLimitedVendorIds() {
let limited;
if (!cachedVendorList) {
Expand Down
16 changes: 8 additions & 8 deletions src/scripts/poi-list/oil.list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {getLabel, getTheme} from '../userview/userview_config.js';
import {OIL_LABELS} from '../userview/userview_constants.js';
import {DATA_CONTEXT_BACK, DATA_CONTEXT_YES, OIL_GLOBAL_OBJECT_NAME} from '../core/core_constants.js';
import { getLabel, getTheme } from '../userview/userview_config.js';
import { OIL_LABELS } from '../userview/userview_constants.js';
import { DATA_CONTEXT_BACK, DATA_CONTEXT_YES, OIL_GLOBAL_OBJECT_NAME } from '../core/core_constants.js';
import './poi.group.scss';
import {getGlobalOilObject, setGlobalOilObject} from '../core/core_utils.js';
import {getGroupList} from './poi.group.list';
import {loadVendorList} from '../core/core_vendor_information';
import { getGlobalOilObject, setGlobalOilObject } from '../core/core_utils';
import { getGroupList } from './poi.group.list';
import { loadVendorList, getVendorsToDisplay } from '../core/core_vendor_information';

export function renderOilGroupListTemplate(renderMethod) {
getGroupList()
Expand All @@ -15,8 +15,8 @@ export function renderOilGroupListTemplate(renderMethod) {

export function renderOilThirdPartyListTemplate(renderMethod) {
loadVendorList()
.then((vendorList) => {
renderMethod(oilThirdPartyListTemplate(vendorList.vendors))
.then(() => {
renderMethod(oilThirdPartyListTemplate(getVendorsToDisplay()))
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/scripts/userview/view/oil.advanced.settings.standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getLabel, getLabelWithDefault, getTheme } from '../userview_config.js';
import { getCustomPurposes } from '../../core/core_config.js';
import { DATA_CONTEXT_BACK, DATA_CONTEXT_YES, OIL_GLOBAL_OBJECT_NAME } from '../../core/core_constants.js';
import { setGlobalOilObject } from '../../core/core_utils.js';
import { getPurposes, getVendorList, getVendors } from '../../core/core_vendor_information.js';
import { getPurposes, getVendorList, getVendorsToDisplay } from '../../core/core_vendor_information.js';


const CLASS_NAME_FOR_ACTIVE_MENU_SECTION = 'as-oil-cpc__category-link--active';
Expand Down Expand Up @@ -33,7 +33,7 @@ const buildVendorEntries = () => {
let vendorList = getVendorList();

if (vendorList && !vendorList.isDefault) {
let listWrapped = getVendors().map((element) => {
let listWrapped = getVendorsToDisplay().map((element) => {
if (element.name) {
return `<div class="as-oil-third-party-list-element">
<span onclick='${OIL_GLOBAL_OBJECT_NAME}._toggleViewElements(this)'>
Expand All @@ -53,7 +53,7 @@ const buildVendorEntries = () => {
});
return `<div class="as-oil-poi-group-list">${listWrapped.join('')}</div>`;
} else {
return 'Missing vendor list! Maybe vendor list retrieval has been failed! Please contact web administrator!';
return 'Missing vendor list! Maybe vendor list retrieval has failed! Please contact web administrator!';
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/scripts/userview/view/oil.advanced.settings.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getLabel, getLabelWithDefault, getTheme } from '../userview_config.js';
import { getCustomPurposes } from '../../core/core_config.js';
import { DATA_CONTEXT_BACK, DATA_CONTEXT_YES, OIL_GLOBAL_OBJECT_NAME } from '../../core/core_constants.js';
import { setGlobalOilObject } from '../../core/core_utils.js';
import { getPurposes, getVendorList, getVendors } from '../../core/core_vendor_information.js';
import { getPurposes, getVendorList, getVendorsToDisplay } from '../../core/core_vendor_information.js';

// TODO Currently, this template is a copy of the standard CPC template.
// TODO It has to be reimplemented to provide a tab layout
Expand Down Expand Up @@ -34,7 +34,7 @@ const buildVendorEntries = () => {
let vendorList = getVendorList();

if (vendorList && !vendorList.isDefault) {
let listWrapped = getVendors().map((element) => {
let listWrapped = getVendorsToDisplay().map((element) => {
if (element.name) {
return `<div class="as-oil-third-party-list-element">
<span onclick='${OIL_GLOBAL_OBJECT_NAME}._toggleViewElements(this)'>
Expand All @@ -54,7 +54,7 @@ const buildVendorEntries = () => {
});
return `<div class="as-oil-poi-group-list">${listWrapped.join('')}</div>`;
} else {
return 'Missing vendor list! Maybe vendor list retrieval has been failed! Please contact web administrator!';
return 'Missing vendor list! Maybe vendor list retrieval has failed! Please contact web administrator!';
}
};

Expand Down
35 changes: 35 additions & 0 deletions test/e2e/limited_vendors_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
OIL_LAYER,
OIL_ADVANCED_SETTINGS_WRAPPER,
OIL_ADVANCED_SETTINGS,
OIL_THIRD_PARTY_NAME
} from '../test_constants.js';

module.exports = {
'@disabled': false,

beforeEach: browser => {
browser
.url(browser.globals.launch_url_host1 + 'demos/advanced-settings-limited-vendors.html')
.deleteCookies();

browser
.url(browser.globals.launch_url_host1 + 'demos/advanced-settings-limited-vendors.html')
.useCss()
.waitForElementVisible('body', 1000, false)
.useXpath()
.waitForElementVisible(OIL_LAYER, 2000, false);
},

'third party list includes only two entries': function (browser) {
browser
.click(OIL_ADVANCED_SETTINGS)
.pause(200)
.waitForElementVisible(OIL_ADVANCED_SETTINGS_WRAPPER, 1000, false)
.pause(200)
.useCss()
.expect.element(OIL_THIRD_PARTY_NAME).text.to.equal('Captify Technologies Limited')
browser.end();
}

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script id="oil-configuration" type="application/configuration">
{
"advanced_settings": true,
"iabVendorWhitelist": [1,2],
"show_limited_vendors": true,
"locale": {
"localeId": "enEN_01",
"version": 1,
"texts": {
"label_intro_heading": "Insider, Inc."
}
}
}
</script>
2 changes: 1 addition & 1 deletion test/fixtures/gold-master/cpc.vendorlist.error.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
label_third_party
</div>
<div id="as-js-third-parties-list">
Missing vendor list! Maybe vendor list retrieval has been failed! Please contact web administrator!
Missing vendor list! Maybe vendor list retrieval has failed! Please contact web administrator!
</div>
</div>
<div class="as-oil-cpc__right">
Expand Down
17 changes: 16 additions & 1 deletion test/specs/core/core_config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
getPublicPath,
setLocale,
gdprApplies,
setGdprApplies
setGdprApplies,
getShowLimitedVendors
} from '../../../src/scripts/core/core_config';
import { loadFixture } from '../../test-utils/utils_fixtures';
import * as CoreLog from '../../../src/scripts/core/core_log';
Expand Down Expand Up @@ -215,4 +216,18 @@ describe('core_config', () => {

});

describe('getShowLimitedVendors', function() {

it('returns false by default', function() {
expect(getShowLimitedVendors()).toEqual(false);
});

it('returns true when show_limited_vendors in configuration', function() {
loadFixture('config/given.config.with.advanced.settings.show.limited.vendors.html');
expect(getShowLimitedVendors()).toBeTruthy();
});


});

});
43 changes: 43 additions & 0 deletions test/specs/core/core_vendor_information.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
getVendorList,
getVendorListVersion,
getVendors,
getLimitedVendors,
getVendorsToDisplay,
loadVendorList
} from '../../../src/scripts/core/core_vendor_information';
import VENDOR_LIST from '../../fixtures/vendorlist/simple_vendor_list.json';
import { resetOil } from '../../test-utils/utils_reset';

describe('core_vendor_information', () => {

const WHITELISTED_VENDORS = [1,2];
const BLACKLISTED_VENDORS = Array.apply(null, {length: (DEFAULT_VENDOR_LIST.maxVendorId-2)}).map(Number.call, Number);

beforeEach(() => resetOil());

describe('loading vendor list', () => {
Expand Down Expand Up @@ -267,6 +272,44 @@ describe('core_vendor_information', () => {
});
});

describe('getLimitedVendors', function() {

it('returns regular vendors when no whitelist or blacklist exists', function() {
spyOn(CoreConfig, 'getShowLimitedVendors').and.returnValue(true);
expect(getLimitedVendors().length).toEqual(DEFAULT_VENDOR_LIST.maxVendorId);
});

it('returns limited vendors when getShowLimitedVendors is true and whitelist exists', function() {
spyOn(CoreConfig, 'getShowLimitedVendors').and.returnValue(true);
spyOn(CoreConfig, 'getIabVendorWhitelist').and.returnValue(WHITELISTED_VENDORS);
expect(getLimitedVendors().length).toEqual(WHITELISTED_VENDORS.length);
});

it('returns limited vendors when getShowLimitedVendors is true and blacklist exists', function() {
spyOn(CoreConfig, 'getShowLimitedVendors').and.returnValue(true);
spyOn(CoreConfig, 'getIabVendorBlacklist').and.returnValue(BLACKLISTED_VENDORS);
expect(getLimitedVendors().length).toEqual(DEFAULT_VENDOR_LIST.maxVendorId - BLACKLISTED_VENDORS.length + 1);
});

});

describe('getVendorsToDisplay', function() {

it('should return full vendor list when configuration parameter show_limited_vendors is false', function() {
spyOn(CoreConfig, 'getShowLimitedVendors').and.returnValue(false);
let result = getVendorsToDisplay();
expect(result.length).toEqual(380);
});

it('should return limited vendor list when configuration parameter show_limited_vendors is true', function() {
spyOn(CoreConfig, 'getShowLimitedVendors').and.returnValue(true);
spyOn(CoreConfig, 'getIabVendorWhitelist').and.returnValue(WHITELISTED_VENDORS);
let result = getVendorsToDisplay();
expect(result.length).toEqual(WHITELISTED_VENDORS.length);
});

});

function buildDefaultVendorIdList(maxVendorId) {
return ((a, b) => {
while (a--) b[a] = a + 1;
Expand Down
Loading

0 comments on commit 0029eae

Please sign in to comment.