Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Charbeat config values for Feature Index page #7941

Merged
merged 9 commits into from Oct 5, 2020
4 changes: 4 additions & 0 deletions src/app/containers/ChartbeatAnalytics/utils/index.js
Expand Up @@ -43,6 +43,8 @@ export const getType = (pageType, shorthand = false) => {
return 'STY';
case 'PGL':
return 'PGL';
case 'FIX':
return 'FIX';
default:
return null;
}
Expand Down Expand Up @@ -121,6 +123,8 @@ export const getTitle = ({ pageType, pageData, brandName, title }) => {
return path(['promo', 'headlines', 'headline'], pageData);
case 'PGL':
return path(['promo', 'headlines', 'headline'], pageData);
case 'FIX':
return getPageTitle(pageData, brandName);
default:
return null;
}
Expand Down
86 changes: 86 additions & 0 deletions src/app/containers/ChartbeatAnalytics/utils/index.test.js
Expand Up @@ -56,6 +56,11 @@ describe('Chartbeat utilities', () => {
expectedDefaultType: 'Index',
expectedShortType: 'IDX',
},
{
type: 'FIX',
expectedDefaultType: 'FIX',
expectedShortType: 'FIX',
},
{
type: 'MAP',
expectedDefaultType: 'article-media-asset',
Expand Down Expand Up @@ -263,6 +268,7 @@ describe('Chartbeat utilities', () => {
pageType | brandName | pageTitle | expectedNumberOfCalls
${'index'} | ${'BBC News'} | ${'This is an index page title'} | ${1}
${'IDX'} | ${'BBC Persian'} | ${'This is an IDX page title'} | ${1}
${'FIX'} | ${'BBC Afrique'} | ${'This is an FIX page title'} | ${1}
${'frontPage'} | ${'BBC News'} | ${'This is a frontpage title'} | ${1}
${'article'} | ${null} | ${'This is an article title'} | ${1}
${'foo'} | ${'BBC News'} | ${null} | ${0}
Expand Down Expand Up @@ -784,6 +790,86 @@ describe('Chartbeat utilities', () => {
expect(getConfig(fixtureData)).toStrictEqual(expectedConfig);
});

it('should return config for canonical pages when page type is FIX and env is not live', () => {
const fixtureData = {
isAmp: false,
platform: 'canonical',
pageType: 'FIX',
data: {},
brandName: 'BBC-Afique',
chartbeatDomain: 'bbc.co.uk',
env: 'test',
service: 'afrique',
origin: 'test.bbc.com',
previousPath: '/previous-path',
};

const expectedConfig = {
domain: 'test.bbc.co.uk',
idSync: {
bbc_hid: 'foobar',
},
path: '/',
sections: 'Afrique, Afrique - FIX',
title: 'This is a Feautre Index page title',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo? This is a Feature Index page title

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOH

type: 'FIX',
uid: 50924,
useCanonical: true,
virtualReferrer: 'test.bbc.com/previous-path',
};

const mockTitle = jest
.fn()
.mockImplementation(() => 'This is a Feautre Index page title');

frontPageUtils.getPageTitle = mockTitle;

const expectedCookieValue = 'foobar';
jest.spyOn(Cookie, 'get').mockImplementation(() => expectedCookieValue);

expect(getConfig(fixtureData)).toStrictEqual(expectedConfig);
});

it('should return config for canonical pages when page type is IDX and env is not live', () => {
const fixtureData = {
isAmp: false,
platform: 'canonical',
pageType: 'IDX',
data: {},
brandName: 'BBC-Persian',
chartbeatDomain: 'bbc.co.uk',
env: 'test',
service: 'persian',
origin: 'test.bbc.com',
previousPath: '/previous-path',
};

const expectedConfig = {
domain: 'test.bbc.co.uk',
idSync: {
bbc_hid: 'foobar',
},
path: '/',
sections: 'Persian, Persian - IDX',
title: 'This is an index page title',
type: 'Index',
uid: 50924,
useCanonical: true,
virtualReferrer: 'test.bbc.com/previous-path',
};

const mockTitle = jest
.fn()
.mockImplementation(() => 'This is an index page title');

frontPageUtils.getPageTitle = mockTitle;

const expectedCookieValue = 'foobar';
jest.spyOn(Cookie, 'get').mockImplementation(() => expectedCookieValue);

expect(getConfig(fixtureData)).toStrictEqual(expectedConfig);
});

it('should return null for virtualReferrer when there is no previousPath', () => {
const fixtureData = {
isAmp: false,
Expand Down