@aller/blink
Version:
A library for tracking user behaviour.
532 lines • 19.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var inscreen_1 = require("../inscreen");
var actions_1 = require("../../actions");
describe('inscreen reducer', function () {
describe('adScreenEnter', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event to the end of prev state', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER,
payload: {
id: 'sol.no/555',
time: new Date(2018, 0, 0, 0, 5),
},
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'sol.no/555': [
{
time: new Date(2018, 0, 0, 0, 5),
type: 'start',
},
],
});
});
});
describe('adScreenExit', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(5) },
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'ad-exit': [
{
time: new Date(5),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(10) },
};
var previousState = {
'ad-exit': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'ad-exit': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(10),
type: 'stop',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(12) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-exit': [
{
time: new Date(12),
type: 'stop',
},
],
});
});
});
describe('articlePreviewScreenEnter', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event to the end of prev state', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_ENTER,
payload: { id: 'dagbladet.no/123', time: new Date(2018, 0, 0, 0, 1) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_ENTER,
payload: { id: 'sol.no/555', time: new Date(2018, 0, 0, 0, 5) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'sol.no/555': [
{
time: new Date(2018, 0, 0, 0, 5),
type: 'start',
},
],
});
});
});
describe('articlePreviewScreenExit', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_EXIT,
payload: {
id: 'ad-exit',
time: new Date(5),
},
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'ad-exit': [
{
time: new Date(5),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(10) },
};
var previousState = {
'ad-exit': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'ad-exit': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(10),
type: 'stop',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.ARTICLE_PREVIEW_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(12) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-exit': [
{
time: new Date(12),
type: 'stop',
},
],
});
});
});
describe('adScreenEnter0', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER_0,
payload: {
id: 'ad-banner-0',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(inscreen_1.inscreenReducer0({}, action)).toEqual({
'ad-banner-0': [
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event to the end of prev state', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER_0,
payload: { id: 'ad-banner-top', time: new Date(9) },
};
var previousState = {
'ad-banner-top': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer0(previousState, action)).toEqual({
'ad-banner-top': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(9),
type: 'start',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.AD_SCREEN_ENTER_0,
payload: {
id: 'ad-banner-side',
time: new Date(8),
},
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer0(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-banner-side': [
{
time: new Date(8),
type: 'start',
},
],
});
});
});
describe('adScreenExit0', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(2) },
};
expect(inscreen_1.inscreenReducer0({}, action)).toEqual({
'ad-exit0': [
{
time: new Date(2),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(7) },
};
var previousState = {
'ad-exit0': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer0(previousState, action)).toEqual({
'ad-exit0': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(7),
type: 'stop',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(7) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer0(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-exit0': [
{
time: new Date(7),
type: 'stop',
},
],
});
});
});
describe('boxScreenEnter', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(2018, 0, 0, 0, 1) },
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'a-box-id': [
{
time: new Date(2018, 0, 0, 0, 1),
type: 'start',
},
],
});
});
it('should add one start event to the end of prev state', function () {
var action = {
type: actions_1.BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(9) },
};
var previousState = {
'a-box-id': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'a-box-id': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(9),
type: 'start',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(8) },
};
var previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'a-box-id': [
{
time: new Date(8),
type: 'start',
},
],
});
});
});
describe('boxScreenExit', function () {
it('should add one start event when no state before', function () {
var action = {
type: actions_1.BOX_SCREEN_EXIT,
payload: { id: 'a-box-id', time: new Date(2) },
};
expect(inscreen_1.inscreenReducer({}, action)).toEqual({
'a-box-id': [
{
time: new Date(2),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', function () {
var action = {
type: actions_1.BOX_SCREEN_EXIT,
payload: { id: 'a-box-id', time: new Date(7) },
};
var previousState = {
'a-box-id': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'a-box-id': [
{
time: new Date(5),
type: 'start',
},
{
time: new Date(7),
type: 'stop',
},
],
});
});
it('should add one start event for other ids', function () {
var action = {
type: actions_1.BOX_SCREEN_EXIT,
payload: { id: 'another-box-id', time: new Date(7) },
};
var previousState = {
'a-box-id': [{ time: new Date(5), type: 'start' }],
};
expect(inscreen_1.inscreenReducer(previousState, action)).toEqual({
'a-box-id': [
{
time: new Date(5),
type: 'start',
},
],
'another-box-id': [
{
time: new Date(7),
type: 'stop',
},
],
});
});
});
describe('pageInit', function () {
it('should flush inscreen', function () {
var state = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
'ad-exit0': [{ time: new Date(7), type: 'stop' }],
};
var action = {
type: actions_1.PAGE_INIT,
payload: { url: 'https://dagbladet.no/' },
};
expect(inscreen_1.inscreenReducer(state, action)).toEqual({});
});
it('should flush inscreen0', function () {
var state = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
'ad-exit0': [{ time: new Date(7), type: 'stop' }],
};
var action = {
type: actions_1.PAGE_INIT,
payload: { url: 'https://dagbladet.no/' },
};
expect(inscreen_1.inscreenReducer0(state, action)).toEqual({});
});
});
});
//# sourceMappingURL=inscreen.test.js.map