@aller/blink
Version:
A library for tracking user behaviour.
157 lines (151 loc) • 4.63 kB
text/typescript
import articlePreviewReducer from '../article-preview';
import { ARTICLE_PREVIEW_SCREEN_ENTER, CLICK, PAGE_INIT } from '../../actions';
describe('articlePreviewReducer', () => {
describe('articlePreviewScreenEnter', () => {
it('should add into empty state', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
};
expect(articlePreviewReducer({}, action)).toEqual({
'dagbladet.no/123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
});
});
it('should add next to existing state', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/456',
url: 'https://www.dagbladet.no/a/456',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
};
const previousState = {
'dagbladet.no/123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
},
};
expect(articlePreviewReducer(previousState, action)).toEqual({
'dagbladet.no/123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
},
'dagbladet.no/456': {
id: 'dagbladet.no/456',
url: 'https://www.dagbladet.no/a/456',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
});
});
it('should overwrite for existing state for same id', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
};
const previousState = {
'dagbladet.no/123': {
id: 'dagbladet.no/123',
},
};
expect(articlePreviewReducer(previousState, action)).toEqual({
'dagbladet.no/123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
});
});
});
describe('click', () => {
it('should add into empty state', () => {
const action = {
type: CLICK,
payload: {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
},
};
expect(articlePreviewReducer({}, action)).toEqual({
'dagbladet.no/123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
clicked: true,
},
});
});
it('should not alter state given empty id', () => {
const action = {
type: CLICK,
payload: {
id: undefined,
url: 'https://www.dagbladet.no/a/345',
},
};
expect(articlePreviewReducer({}, action)).toEqual({});
});
});
describe('pageInit', () => {
it('should flush state', () => {
const state = {
'dagbladet.no / 123': {
id: 'dagbladet.no/123',
url: 'https://www.dagbladet.no/a/123',
title: 'best title',
height: 340,
width: 231,
personalizationParametersRequested: 'xavier-pluss',
personalizationSystemUsed: 'cerebro',
position: 10,
},
};
const action = {
type: PAGE_INIT,
payload: { url: 'https://dagbladet.no/' },
};
expect(articlePreviewReducer(state, action)).toEqual({});
});
});
});