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

Commit

Permalink
Remove default welcome banner
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Apr 7, 2017
1 parent 0ea4389 commit 8fac946
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 49 deletions.
2 changes: 1 addition & 1 deletion browser/layout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ This module is bundled by default.
### Templates

- `vanilla.html` loads all the standard next app styles and scripts, including cutting the mustard and tracking.
- `wrapper.html` all of the above but also including the next header, footer and welcome panel.
- `wrapper.html` all of the above but also including the next header and footer.
4 changes: 3 additions & 1 deletion browser/layout/wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@

<div class="n-layout__row n-layout__row--footer">
{{#outputBlock 'footer'}}{{/outputBlock}}
{{>n-ui/compact-view-promo/template}}
{{#if welcomeBanner}}
{{>n-ui/compact-view-promo/template}}
{{/if}}
{{>n-ui/footer/template}}
{{#if @root.flags.fancyDrawer}}
{{#unlessEquals nUi.header.variant 'logo-only'}}
Expand Down
6 changes: 3 additions & 3 deletions components/n-ui/compact-view-promo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const superstore = require('superstore-sync');

const HAS_MINIMIZED_COMPACT = 'n-welcome-message-compact-ad-collapsed';
const HAS_MINIMIZED = 'n-welcome-message-compact-ad-collapsed';
const TEST_KEY = 'n-welcome-message-test';
const TEST_VAL = 'can-store';

Expand All @@ -17,7 +17,7 @@ function hasLocalStorage () {
function hideSticky () {
fixedEl.hidden = true;
staticEl.hidden = false;
superstore.local.set(HAS_MINIMIZED_COMPACT, 1);
superstore.local.set(HAS_MINIMIZED, 1);
}

function showSticky (){
Expand All @@ -35,7 +35,7 @@ function init () {
// only show the sticky banner thrice
const viewCount = superstore.local.get('n-welcome-message-ad-view-count') || 0;

if (viewCount >= 3 || superstore.local.get(HAS_MINIMIZED_COMPACT)) {
if (viewCount >= 3 || superstore.local.get(HAS_MINIMIZED)) {
hideSticky();
} else {
superstore.local.set('n-welcome-message-ad-view-count', viewCount + 1);
Expand Down
34 changes: 8 additions & 26 deletions server/models/welcome-banner.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
const defaultWelcomeBannerModel = {
name: 'default',
title: 'Welcome to the new FT.com.',
strapline: 'The same global insight. Faster than ever before on all your devices.',
ctas : {
primary : {
text: 'View tips',
href: '/tour',
trackable: 'tour-page',
'component-attr': 'cta-take-tour'
}
}
};

const compactAdvertWelcomeBannerModel = {
name: 'compact-ad',
title: 'Try the new compact homepage.',
Expand All @@ -25,7 +11,7 @@ const compactAdvertWelcomeBannerModel = {
}
};

const compactViewWelcomeBannerModel = {
const compactViewEnabledWelcomeBannerModel = {
name: 'compact-view',
title: 'You\'ve enabled the compact homepage.',
strapline: 'A list view of today\'s homepage, with fewer images',
Expand All @@ -39,20 +25,16 @@ const compactViewWelcomeBannerModel = {
};

function welcomeBannerModelFactory (req, res, next) {
let model;
if (!res.locals.flags || !res.locals.anon) {
model = defaultWelcomeBannerModel;
} else if (res.locals.flags.compactView && !res.locals.anon.userIsAnonymous && (req.path === '/') && (req.get('FT-Cookie-ft-homepage-view') !== 'compact')) {
model = compactAdvertWelcomeBannerModel;
} else if (res.locals.flags.compactView && req.path === '/' && req.get('FT-Cookie-ft-homepage-view') === 'compact') {
model = compactViewWelcomeBannerModel;
} else {
model = defaultWelcomeBannerModel;
if (res.locals.flags.compactView && req.path === '/' && !res.locals.anon.userIsAnonymous) {
if (req.get('FT-Cookie-ft-homepage-view') === 'compact') {
res.locals.welcomeBanner = compactViewEnabledWelcomeBannerModel;
} else {
res.locals.welcomeBanner = compactAdvertWelcomeBannerModel;
}
}

res.locals.welcomeBanner = model;
next();
}

module.exports = welcomeBannerModelFactory;
module.exports._banners = {defaultWelcomeBannerModel, compactAdvertWelcomeBannerModel, compactViewWelcomeBannerModel};
module.exports._banners = { compactAdvertWelcomeBannerModel, compactViewEnabledWelcomeBannerModel };
33 changes: 15 additions & 18 deletions server/test/welcome-banner-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,58 @@ const sinon = require('sinon');

describe('Welcome Banner Model', () => {

let welcomeBannerModelFactory;
let subject;

before(() => {
welcomeBannerModelFactory = require('../models/welcome-banner');
subject = require('../models/welcome-banner');
});

const wait = t => new Promise(r => setTimeout(r, t));

it('Should provide the welcome banner model by default', () => {
it('Should provide the no welcome banner by default', () => {
const res = {locals:{flags:{}}};
const req = {path:'/', get: () => ''};
const next = sinon.spy();
welcomeBannerModelFactory(req, res, next);
subject(req, res, next);
return wait(0).then(() => {
sinon.assert.called(next);
expect(res.locals).to.have.property('welcomeBanner');
expect(res.locals.welcomeBanner).to.deep.equal(welcomeBannerModelFactory._banners.defaultWelcomeBannerModel);
expect(res.locals).to.not.have.property('welcomeBanner');
});
});

it('Should not provide the compact advert view model if the user is anonymous', () => {
it('Should not provide the welcome banner if the user is anonymous', () => {
const res = {locals:{anon:{userIsAnonymous: true},flags:{compactView:true}}};
const req = {path:'/', get: () => 'standard'};
const next = sinon.spy();
welcomeBannerModelFactory(req, res, next);
subject(req, res, next);
return wait(0).then(() => {
sinon.assert.called(next);
expect(res.locals).to.have.property('welcomeBanner');
expect(res.locals.welcomeBanner).to.deep.equal(welcomeBannerModelFactory._banners.defaultWelcomeBannerModel);
expect(res.locals).to.not.have.property('welcomeBanner');
});
});

it('Should provide the compact advert view model if the compactView flag is on AND we are on the homepage AND the FT-Cookie-ft-homepage-view IS NOT set to "compact" AND the user is not anonymous', () => {
it('Should provide the compact advert view model if the compactView flag is on AND we are on the homepage AND the user is not anonymous', () => {
const res = {locals:{anon:{userIsAnonymous: false},flags:{compactView:true}}};
const req = {path:'/', get: () => 'standard'};
const next = sinon.spy();
welcomeBannerModelFactory(req, res, next);
subject(req, res, next);
return wait(0).then(() => {
sinon.assert.called(next);
expect(res.locals).to.have.property('welcomeBanner');
expect(res.locals.welcomeBanner).to.deep.equal(welcomeBannerModelFactory._banners.compactAdvertWelcomeBannerModel);
expect(res.locals.welcomeBanner).to.deep.equal(subject._banners.compactAdvertWelcomeBannerModel);
});
});

it('Should provide the compact view model if the compactView flag is on AND we are on the homepage AND the FT-Cookie-ft-homepage-view IS set to "compact"', () => {
it('Should provide the compact enabled view model if the compactView flag is on AND we are on the homepage AND the user is not anonymous AND the FT-Cookie-ft-homepage-view IS set to "compact"', () => {
const res = {locals:{anon:{userIsAnonymous: false},flags:{compactView:true}}};
const req = {path:'/', get: () => 'compact'};
const next = sinon.spy();
welcomeBannerModelFactory(req, res, next);
subject(req, res, next);
return wait(0).then(() => {
sinon.assert.called(next);
expect(res.locals).to.have.property('welcomeBanner');
expect(res.locals.welcomeBanner).to.deep.equal(welcomeBannerModelFactory._banners.compactViewWelcomeBannerModel);
expect(res.locals.welcomeBanner).to.deep.equal(subject._banners.compactViewEnabledWelcomeBannerModel);
});
});


})
});

0 comments on commit 8fac946

Please sign in to comment.