@aller/blink
Version:
A library for tracking user behaviour.
436 lines (414 loc) • 11.2 kB
text/typescript
import { inscreenReducer, inscreenReducer0 } from '../inscreen';
import {
AD_SCREEN_ENTER,
AD_SCREEN_EXIT,
ARTICLE_PREVIEW_SCREEN_ENTER,
AD_SCREEN_ENTER_0,
AD_SCREEN_EXIT_0,
PAGE_INIT,
BOX_SCREEN_ENTER,
} from '../../actions';
describe('inscreen reducer', () => {
describe('adScreenEnter', () => {
it('should add one start event when no state before', () => {
const action = {
type: AD_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(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', () => {
const action = {
type: AD_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: AD_SCREEN_ENTER,
payload: {
id: 'sol.no/555',
time: new Date(2018, 0, 0, 0, 5),
},
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
it('should add one start event when no state before', () => {
const action = {
type: AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(5) },
};
expect(inscreenReducer({}, action)).toEqual({
'ad-exit': [
{
time: new Date(5),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', () => {
const action = {
type: AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(10) },
};
const previousState = {
'ad-exit': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: AD_SCREEN_EXIT,
payload: { id: 'ad-exit', time: new Date(12) },
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-exit': [
{
time: new Date(12),
type: 'stop',
},
],
});
});
});
describe('articlePreviewScreenEnter', () => {
it('should add one start event when no state before', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: {
id: 'dagbladet.no/123',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(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', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: { id: 'dagbladet.no/123', time: new Date(2018, 0, 0, 0, 1) },
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: ARTICLE_PREVIEW_SCREEN_ENTER,
payload: { id: 'sol.no/555', time: new Date(2018, 0, 0, 0, 5) },
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(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('adScreenEnter0', () => {
it('should add one start event when no state before', () => {
const action = {
type: AD_SCREEN_ENTER_0,
payload: {
id: 'ad-banner-0',
time: new Date(2018, 0, 0, 0, 1),
},
};
expect(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', () => {
const action = {
type: AD_SCREEN_ENTER_0,
payload: { id: 'ad-banner-top', time: new Date(9) },
};
const previousState = {
'ad-banner-top': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: AD_SCREEN_ENTER_0,
payload: {
id: 'ad-banner-side',
time: new Date(8),
},
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreenReducer0(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-banner-side': [
{
time: new Date(8),
type: 'start',
},
],
});
});
});
describe('adScreenExit0', () => {
it('should add one start event when no state before', () => {
const action = {
type: AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(2) },
};
expect(inscreenReducer0({}, action)).toEqual({
'ad-exit0': [
{
time: new Date(2),
type: 'stop',
},
],
});
});
it('should add one stop event to the end of prev state', () => {
const action = {
type: AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(7) },
};
const previousState = {
'ad-exit0': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: AD_SCREEN_EXIT_0,
payload: { id: 'ad-exit0', time: new Date(7) },
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreenReducer0(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'ad-exit0': [
{
time: new Date(7),
type: 'stop',
},
],
});
});
});
describe('boxScreenEnter', () => {
it('should add one start event when no state before', () => {
const action = {
type: BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(2018, 0, 0, 0, 1) },
};
expect(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', () => {
const action = {
type: BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(9) },
};
const previousState = {
'a-box-id': [{ time: new Date(5), type: 'start' }],
};
expect(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', () => {
const action = {
type: BOX_SCREEN_ENTER,
payload: { id: 'a-box-id', time: new Date(8) },
};
const previousState = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
};
expect(inscreenReducer(previousState, action)).toEqual({
'dagbladet.no/123': [
{
time: new Date(5),
type: 'start',
},
],
'a-box-id': [
{
time: new Date(8),
type: 'start',
},
],
});
});
});
describe('pageInit', () => {
it('should flush inscreen', () => {
const state = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
'ad-exit0': [{ time: new Date(7), type: 'stop' }],
};
const action = {
type: PAGE_INIT,
payload: { url: 'https://dagbladet.no/' },
};
expect(inscreenReducer(state, action)).toEqual({});
});
it('should flush inscreen0', () => {
const state = {
'dagbladet.no/123': [{ time: new Date(5), type: 'start' }],
'ad-exit0': [{ time: new Date(7), type: 'stop' }],
};
const action = {
type: PAGE_INIT,
payload: { url: 'https://dagbladet.no/' },
};
expect(inscreenReducer0(state, action)).toEqual({});
});
});
});