UNPKG

@aller/blink

Version:

A library for tracking user behaviour.

107 lines (102 loc) 2.48 kB
import boxReducer from '../box'; import { BOX_SCREEN_ENTER, PAGE_INIT } from '../../actions'; describe('boxReducer', () => { describe('boxScreenEnter', () => { it('should add into empty state', () => { const action = { type: BOX_SCREEN_ENTER, payload: { id: 'a-box-id', height: 340, title: 'box title', width: 231, }, }; expect(boxReducer({}, action)).toEqual({ 'a-box-id': { id: 'a-box-id', height: 340, title: 'box title', width: 231, }, }); }); it('should add next to existing state', () => { const action = { type: BOX_SCREEN_ENTER, payload: { id: 'another-box-id', height: 100, title: 'box title', width: 500, }, }; const previousState = { 'a-box-id': { id: 'a-box-id', height: 340, title: 'box title', width: 231, }, }; expect(boxReducer(previousState, action)).toEqual({ 'a-box-id': { id: 'a-box-id', height: 340, title: 'box title', width: 231, }, 'another-box-id': { id: 'another-box-id', height: 100, title: 'box title', width: 500, }, }); }); it('should overwrite for existing state for same id', () => { const action = { type: BOX_SCREEN_ENTER, payload: { id: 'a-box-id', height: 500, title: 'changed box title', width: 400, }, }; const previousState = { 'a-box-id': { id: 'a-box-id', height: 500, title: 'box title', width: 231, }, }; expect(boxReducer(previousState, action)).toEqual({ 'a-box-id': { id: 'a-box-id', height: 500, title: 'changed box title', width: 400, }, }); }); }); describe('pageInit', () => { it('should flush state', () => { const state = { 'ting-og-tang': { id: 'ting-og-tang', title: 'A Box Title', height: 250, width: 300, }, }; const action = { type: PAGE_INIT, payload: { url: 'https://dagbladet.no/' }, }; expect(boxReducer(state, action)).toEqual({}); }); }); });