@aller/blink
Version:
A library for tracking user behaviour.
280 lines (271 loc) • 7.29 kB
text/typescript
import adsReducer from '../ads';
import {
SCROLL_OFFSET_HEIGHT,
SCROLL_OFFSET_TOP,
SCROLL_POS_AD_LOAD,
SCROLL_POS_INSCREEN_DFP,
DFP_INSCREEN,
SCROLL_POS_SLOT_ONLOAD,
DFP_LOADED,
DFP_NAME,
DFP_ADUNIT_PATH,
DFP_RENDERED,
SCROLL_POS_SLOT_RENDER_ENDED,
DFP_ADVERTISER_ID,
DFP_CAMPAIGN_ID,
DFP_CREATIVE_ID,
DFP_LINE_ITEM_ID,
DFP_SOURCE_AGNOSTIC_CREATIVE_ID,
DFP_SOURCE_AGNOSTIC_LINE_ITEM_ID,
DFP_BIDDER,
} from '../../events/consts';
import {
AD_LOAD_START,
DFP_IMPRESSION_VIEWABLE,
DFP_SLOT_ON_LOAD,
DFP_SLOT_RENDER_ENDED,
} from '../../actions';
describe('ads reducer', () => {
describe('adLoad', () => {
it('should add into empty state', () => {
const action = {
type: AD_LOAD_START,
payload: {
id: 'ad-top',
offsetHeight: 300,
offsetTop: 200,
scrollTop: 100,
},
};
expect(adsReducer({}, action)).toEqual({
'ad-top': {
[ ]: 100,
[ ]: 200,
[ ]: 300,
},
});
});
it('should add next to existing state', () => {
const action = {
type: AD_LOAD_START,
payload: {
id: 'ad-bottom',
offsetHeight: 15,
offsetTop: 20,
scrollTop: 5,
},
};
const previousState = {
'ad-top': {
[ ]: 100,
[ ]: 200,
[ ]: 300,
},
};
expect(adsReducer(previousState, action)).toEqual({
'ad-top': {
[ ]: 100,
[ ]: 200,
[ ]: 300,
},
'ad-bottom': {
[ ]: 5,
[ ]: 20,
[ ]: 15,
},
});
});
it('should overwrite for existing state for same id', () => {
const action = {
type: AD_LOAD_START,
payload: {
id: 'ad-bottom',
offsetHeight: 15,
offsetTop: 10,
scrollTop: 5,
},
};
const previousState = {
'ad-bottom': {
id: 'ad-bottom',
[ ]: 100,
[ ]: 200,
[ ]: 300,
},
};
expect(adsReducer(previousState, action)).toEqual({
'ad-bottom': {
id: 'ad-bottom',
[ ]: 5,
[ ]: 10,
[ ]: 15,
},
});
});
});
describe('dfpImpressionViewable', () => {
it('should add into empty state', () => {
const action = {
type: DFP_IMPRESSION_VIEWABLE,
payload: {
id: 'ad-banner2',
scrollTop: 100,
},
};
expect(adsReducer({}, action)).toEqual({
'ad-banner2': {
[ ]: 100,
[ ]: 1,
},
});
});
it('should add next to existing state', () => {
const action = {
type: DFP_IMPRESSION_VIEWABLE,
payload: {
id: 'ad-banner2',
scrollTop: 25,
},
};
const previousState = {
'ad-banner2': { [SCROLL_POS_INSCREEN_DFP]: 50 },
'ad-top': { [SCROLL_POS_INSCREEN_DFP]: 100, [DFP_INSCREEN]: 1 },
};
expect(adsReducer(previousState, action)).toEqual({
'ad-banner2': {
[ ]: 25,
[ ]: 1,
},
'ad-top': {
[ ]: 100,
[ ]: 1,
},
});
});
});
describe('dfpSlotOnLoad', () => {
it('should add into empty state', () => {
const action = {
type: DFP_SLOT_ON_LOAD,
payload: {
id: 'ad-banner2',
name: 'dfp-banner',
scrollTop: 100,
},
};
expect(adsReducer({}, action)).toEqual({
'ad-banner2': {
[ ]: 100,
[ ]: 1,
[ ]: 'dfp-banner',
},
});
});
it('should add next to existing state', () => {
const action = {
type: DFP_SLOT_ON_LOAD,
payload: {
id: 'ad-banner2',
name: 'dfp-banner',
scrollTop: 25,
},
};
const previousState = {
'ad-banner2': { [SCROLL_POS_SLOT_ONLOAD]: 120 },
'ad-top': {
[ ]: 250,
[ ]: 1,
[ ]: 'dfp-top',
},
};
expect(adsReducer(previousState, action)).toEqual({
'ad-banner2': {
[ ]: 25,
[ ]: 1,
[ ]: 'dfp-banner',
},
'ad-top': {
[ ]: 250,
[ ]: 1,
[ ]: 'dfp-top',
},
});
});
});
describe('dfpSlotRenderEnded', () => {
it('should add into empty state', () => {
const action = {
type: DFP_SLOT_RENDER_ENDED,
payload: {
id: 'ad-banner2',
adUnitPath: '/some-path',
advertiserId: 1204,
campaignId: 123,
creativeId: 234,
lineItemId: 543,
sourceAgnosticCreativeId: 1202,
sourceAgnosticLineItemId: 1303,
scrollTop: 100,
bidder: 'adform',
},
};
expect(adsReducer({}, action)).toEqual({
'ad-banner2': {
[ ]: 1204,
[ ]: 123,
[ ]: 234,
[ ]: 543,
[ ]: 1202,
[ ]: 1303,
[ ]: '/some-path',
[ ]: 1,
[ ]: 100,
[ ]: 'adform',
},
});
});
it('should add next to existing state', () => {
const action = {
type: DFP_SLOT_RENDER_ENDED,
payload: {
id: 'ad-banner2',
adUnitPath: '/some-path',
advertiserId: 1204,
campaignId: 123,
creativeId: 234,
lineItemId: 543,
sourceAgnosticCreativeId: 1202,
sourceAgnosticLineItemId: 1303,
scrollTop: 100,
bidder: 'adform',
},
};
const previousState = {
'ad-top': {
[ ]: '/top-path',
[ ]: 1,
[ ]: 300,
},
};
expect(adsReducer(previousState, action)).toEqual({
'ad-banner2': {
[ ]: '/some-path',
[ ]: 1,
[ ]: 100,
[ ]: 1204,
[ ]: 123,
[ ]: 234,
[ ]: 543,
[ ]: 1202,
[ ]: 1303,
[ ]: 'adform',
},
'ad-top': {
[ ]: '/top-path',
[ ]: 1,
[ ]: 300,
},
});
});
});
});