UNPKG

@aller/blink

Version:

A library for tracking user behaviour.

264 lines 10.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var ads_1 = __importDefault(require("../ads")); var consts_1 = require("../../events/consts"); var actions_1 = require("../../actions"); describe('ads reducer', function () { describe('adLoad', function () { it('should add into empty state', function () { var _a; var action = { type: actions_1.AD_LOAD_START, payload: { id: 'ad-top', offsetHeight: 300, offsetTop: 200, scrollTop: 100, }, }; expect(ads_1.default({}, action)).toEqual({ 'ad-top': (_a = {}, _a[consts_1.SCROLL_POS_AD_LOAD] = 100, _a[consts_1.SCROLL_OFFSET_TOP] = 200, _a[consts_1.SCROLL_OFFSET_HEIGHT] = 300, _a), }); }); it('should add next to existing state', function () { var _a, _b, _c; var action = { type: actions_1.AD_LOAD_START, payload: { id: 'ad-bottom', offsetHeight: 15, offsetTop: 20, scrollTop: 5, }, }; var previousState = { 'ad-top': (_a = {}, _a[consts_1.SCROLL_POS_AD_LOAD] = 100, _a[consts_1.SCROLL_OFFSET_TOP] = 200, _a[consts_1.SCROLL_OFFSET_HEIGHT] = 300, _a), }; expect(ads_1.default(previousState, action)).toEqual({ 'ad-top': (_b = {}, _b[consts_1.SCROLL_POS_AD_LOAD] = 100, _b[consts_1.SCROLL_OFFSET_TOP] = 200, _b[consts_1.SCROLL_OFFSET_HEIGHT] = 300, _b), 'ad-bottom': (_c = {}, _c[consts_1.SCROLL_POS_AD_LOAD] = 5, _c[consts_1.SCROLL_OFFSET_TOP] = 20, _c[consts_1.SCROLL_OFFSET_HEIGHT] = 15, _c), }); }); it('should overwrite for existing state for same id', function () { var _a, _b; var action = { type: actions_1.AD_LOAD_START, payload: { id: 'ad-bottom', offsetHeight: 15, offsetTop: 10, scrollTop: 5, }, }; var previousState = { 'ad-bottom': (_a = { id: 'ad-bottom' }, _a[consts_1.SCROLL_POS_AD_LOAD] = 100, _a[consts_1.SCROLL_OFFSET_TOP] = 200, _a[consts_1.SCROLL_OFFSET_HEIGHT] = 300, _a), }; expect(ads_1.default(previousState, action)).toEqual({ 'ad-bottom': (_b = { id: 'ad-bottom' }, _b[consts_1.SCROLL_POS_AD_LOAD] = 5, _b[consts_1.SCROLL_OFFSET_TOP] = 10, _b[consts_1.SCROLL_OFFSET_HEIGHT] = 15, _b), }); }); }); describe('dfpImpressionViewable', function () { it('should add into empty state', function () { var _a; var action = { type: actions_1.DFP_IMPRESSION_VIEWABLE, payload: { id: 'ad-banner2', scrollTop: 100, }, }; expect(ads_1.default({}, action)).toEqual({ 'ad-banner2': (_a = {}, _a[consts_1.SCROLL_POS_INSCREEN_DFP] = 100, _a[consts_1.DFP_INSCREEN] = 1, _a), }); }); it('should add next to existing state', function () { var _a, _b, _c, _d; var action = { type: actions_1.DFP_IMPRESSION_VIEWABLE, payload: { id: 'ad-banner2', scrollTop: 25, }, }; var previousState = { 'ad-banner2': (_a = {}, _a[consts_1.SCROLL_POS_INSCREEN_DFP] = 50, _a), 'ad-top': (_b = {}, _b[consts_1.SCROLL_POS_INSCREEN_DFP] = 100, _b[consts_1.DFP_INSCREEN] = 1, _b), }; expect(ads_1.default(previousState, action)).toEqual({ 'ad-banner2': (_c = {}, _c[consts_1.SCROLL_POS_INSCREEN_DFP] = 25, _c[consts_1.DFP_INSCREEN] = 1, _c), 'ad-top': (_d = {}, _d[consts_1.SCROLL_POS_INSCREEN_DFP] = 100, _d[consts_1.DFP_INSCREEN] = 1, _d), }); }); }); describe('dfpSlotOnLoad', function () { it('should add into empty state', function () { var _a; var action = { type: actions_1.DFP_SLOT_ON_LOAD, payload: { id: 'ad-banner2', name: 'dfp-banner', scrollTop: 100, }, }; expect(ads_1.default({}, action)).toEqual({ 'ad-banner2': (_a = {}, _a[consts_1.SCROLL_POS_SLOT_ONLOAD] = 100, _a[consts_1.DFP_LOADED] = 1, _a[consts_1.DFP_NAME] = 'dfp-banner', _a), }); }); it('should add next to existing state', function () { var _a, _b, _c, _d; var action = { type: actions_1.DFP_SLOT_ON_LOAD, payload: { id: 'ad-banner2', name: 'dfp-banner', scrollTop: 25, }, }; var previousState = { 'ad-banner2': (_a = {}, _a[consts_1.SCROLL_POS_SLOT_ONLOAD] = 120, _a), 'ad-top': (_b = {}, _b[consts_1.SCROLL_POS_SLOT_ONLOAD] = 250, _b[consts_1.DFP_LOADED] = 1, _b[consts_1.DFP_NAME] = 'dfp-top', _b), }; expect(ads_1.default(previousState, action)).toEqual({ 'ad-banner2': (_c = {}, _c[consts_1.SCROLL_POS_SLOT_ONLOAD] = 25, _c[consts_1.DFP_LOADED] = 1, _c[consts_1.DFP_NAME] = 'dfp-banner', _c), 'ad-top': (_d = {}, _d[consts_1.SCROLL_POS_SLOT_ONLOAD] = 250, _d[consts_1.DFP_LOADED] = 1, _d[consts_1.DFP_NAME] = 'dfp-top', _d), }); }); }); describe('dfpSlotRenderEnded', function () { it('should add into empty state', function () { var _a; var action = { type: actions_1.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(ads_1.default({}, action)).toEqual({ 'ad-banner2': (_a = {}, _a[consts_1.DFP_ADVERTISER_ID] = 1204, _a[consts_1.DFP_CAMPAIGN_ID] = 123, _a[consts_1.DFP_CREATIVE_ID] = 234, _a[consts_1.DFP_LINE_ITEM_ID] = 543, _a[consts_1.DFP_SOURCE_AGNOSTIC_CREATIVE_ID] = 1202, _a[consts_1.DFP_SOURCE_AGNOSTIC_LINE_ITEM_ID] = 1303, _a[consts_1.DFP_ADUNIT_PATH] = '/some-path', _a[consts_1.DFP_RENDERED] = 1, _a[consts_1.SCROLL_POS_SLOT_RENDER_ENDED] = 100, _a[consts_1.DFP_BIDDER] = 'adform', _a), }); }); it('should add next to existing state', function () { var _a, _b, _c; var action = { type: actions_1.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', }, }; var previousState = { 'ad-top': (_a = {}, _a[consts_1.DFP_ADUNIT_PATH] = '/top-path', _a[consts_1.DFP_RENDERED] = 1, _a[consts_1.SCROLL_POS_SLOT_RENDER_ENDED] = 300, _a), }; expect(ads_1.default(previousState, action)).toEqual({ 'ad-banner2': (_b = {}, _b[consts_1.DFP_ADUNIT_PATH] = '/some-path', _b[consts_1.DFP_RENDERED] = 1, _b[consts_1.SCROLL_POS_SLOT_RENDER_ENDED] = 100, _b[consts_1.DFP_ADVERTISER_ID] = 1204, _b[consts_1.DFP_CAMPAIGN_ID] = 123, _b[consts_1.DFP_CREATIVE_ID] = 234, _b[consts_1.DFP_LINE_ITEM_ID] = 543, _b[consts_1.DFP_SOURCE_AGNOSTIC_CREATIVE_ID] = 1202, _b[consts_1.DFP_SOURCE_AGNOSTIC_LINE_ITEM_ID] = 1303, _b[consts_1.DFP_BIDDER] = 'adform', _b), 'ad-top': (_c = {}, _c[consts_1.DFP_ADUNIT_PATH] = '/top-path', _c[consts_1.DFP_RENDERED] = 1, _c[consts_1.SCROLL_POS_SLOT_RENDER_ENDED] = 300, _c), }); }); }); }); //# sourceMappingURL=ads.test.js.map