@aller/blink
Version:
A library for tracking user behaviour.
91 lines (80 loc) • 2.12 kB
text/typescript
import screenReducer from '../screen';
import { SCREEN_SHOW, SCREEN_HIDE } from '../../actions';
describe('screen reducer', () => {
describe('SCREEN_SHOW', () => {
it('should have correct default state', () => {
const action = {
type: 'INVALID_ACTION',
};
expect(screenReducer(undefined, action)).toEqual({
events: [],
});
});
it('should add a screen show event to empty state', () => {
const action = { type: SCREEN_SHOW, payload: { time: new Date(5) } };
expect(screenReducer({ events: [] }, action)).toEqual({
events: [
{
time: new Date(5),
type: 'show',
},
],
});
});
it('should add a screen show event to existing state', () => {
const action = { type: SCREEN_SHOW, payload: { time: new Date(5) } };
expect(
screenReducer(
{
events: [{ time: new Date(3), type: 'hide' }],
},
action,
),
).toEqual({
events: [
{
time: new Date(3),
type: 'hide',
},
{
time: new Date(5),
type: 'show',
},
],
});
});
});
describe('SCREEN_HIDE', () => {
it('should add a screen show event to empty state', () => {
const action = { type: SCREEN_HIDE, payload: { time: new Date(5) } };
expect(screenReducer({ events: [] }, action)).toEqual({
events: [
{
time: new Date(5),
type: 'hide',
},
],
});
});
it('should add a screen show event to existing state', () => {
const action = { type: SCREEN_HIDE, payload: { time: new Date(5) } };
expect(
screenReducer(
{ events: [{ time: new Date(3), type: 'hide' }] },
action,
),
).toEqual({
events: [
{
time: new Date(3),
type: 'hide',
},
{
time: new Date(5),
type: 'hide',
},
],
});
});
});
});