File size: 2,725 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import { ROUTE_SET, COMMENTS_LIKE } from 'calypso/state/action-types';
import reducer from '../reducer';
describe( 'reducer', () => {
beforeEach( () => {
jest.useFakeTimers();
jest.setSystemTime( 1337 );
} );
test( 'should default to an empty list', () => {
const state = reducer( undefined, {} );
expect( state ).toEqual( [] );
} );
test( 'should add actions to the log', () => {
const actions = [
{
type: ROUTE_SET,
path: '/themes/77203074',
},
{
type: ROUTE_SET,
path: '/themes/foobar',
},
];
const state = actions.reduce( reducer, undefined );
expect( state ).toEqual( [
{ ...actions[ 0 ], timestamp: 1337 },
{ ...actions[ 1 ], timestamp: 1337 },
] );
} );
test( 'should discard them if payload is irrelevant', () => {
const actions = [
{
type: COMMENTS_LIKE,
path: '/menus/77203074',
},
{
type: COMMENTS_LIKE,
path: '/menus/foobar',
},
];
const state = actions.reduce( reducer, undefined );
expect( state ).toEqual( [] );
} );
test( 'should log actions with relevant analytics meta', () => {
const actions = [
{
type: ROUTE_SET,
path: '/themes/77203074',
meta: {
analytics: [
{
type: 'ANALYTICS_EVENT_RECORD',
payload: {
service: 'tracks',
name: 'calypso_themeshowcase_theme_click',
properties: {},
},
},
],
},
},
{
type: COMMENTS_LIKE,
path: '/menus/foobar',
meta: {
analytics: [
{
type: 'ANALYTICS_EVENT_RECORD',
payload: {
service: 'tracks',
name: 'calypso_themeshowcase_theme_click',
properties: {},
},
},
],
},
},
];
const state = actions.reduce( reducer, undefined );
expect( state ).toEqual( [
{ ...actions[ 0 ], timestamp: 1337 },
{ ...actions[ 1 ], timestamp: 1337 },
] );
} );
test( 'should discard actions with irrelevant analytics meta', () => {
const actions = [
{
type: ROUTE_SET,
path: '/themes/77203074',
meta: {
analytics: [
{
type: 'ANALYTICS_EVENT_RECORD',
payload: {
service: 'tracks',
name: 'calypso_all_your_base_are_belong_to_us',
properties: {},
},
},
],
},
},
{
type: COMMENTS_LIKE,
path: '/menus/foobar',
meta: {
analytics: [
{
type: 'ANALYTICS_EVENT_RECORD',
payload: {
service: 'tracks',
name: 'calypso_all_your_base_are_belong_to_us',
properties: {},
},
},
],
},
},
];
const state = actions.reduce( reducer, undefined );
expect( state ).toEqual( [ { ...actions[ 0 ], timestamp: 1337 } ] );
} );
} );
|