reducer.spec.ts
1 import { CustomNodeConfig } from 'types/node'; 2 import { addCustomNode, removeCustomNode } from './actions'; 3 import { customNodesReducer } from './reducer'; 4 5 export const firstCustomNode: CustomNodeConfig = { 6 isCustom: true, 7 id: 'customNode1', 8 name: 'My cool custom node', 9 network: 'CustomNetworkId', 10 service: 'your custom node', 11 url: '127.0.0.1' 12 }; 13 14 const secondCustomNode: CustomNodeConfig = { 15 ...firstCustomNode, 16 id: 'customNode2' 17 }; 18 19 const expectedState = { 20 initialState: {}, 21 addFirstCustomNode: { [firstCustomNode.id]: firstCustomNode }, 22 addSecondCustomNode: { 23 [firstCustomNode.id]: firstCustomNode, 24 [secondCustomNode.id]: secondCustomNode 25 }, 26 removeFirstCustomNode: { [secondCustomNode.id]: secondCustomNode } 27 }; 28 29 const actions = { 30 addFirstCustomNode: addCustomNode(firstCustomNode), 31 addSecondCustomNode: addCustomNode(secondCustomNode), 32 removeFirstCustomNode: removeCustomNode(firstCustomNode.id) 33 }; 34 35 describe('custom nodes reducer', () => { 36 it('should return the initial state', () => 37 expect(customNodesReducer(undefined, {} as any)).toEqual({})); 38 39 it('should handle adding the first custom node', () => 40 expect(customNodesReducer(expectedState.initialState, actions.addFirstCustomNode)).toEqual( 41 expectedState.addFirstCustomNode 42 )); 43 it('should handle adding a second custom node', () => 44 expect( 45 customNodesReducer(expectedState.addFirstCustomNode, actions.addSecondCustomNode) 46 ).toEqual(expectedState.addSecondCustomNode)); 47 it('should handle removing the first custom node', () => 48 expect( 49 customNodesReducer(expectedState.addSecondCustomNode, actions.removeFirstCustomNode) 50 ).toEqual(expectedState.removeFirstCustomNode)); 51 }); 52 53 export { actions as customNodesActions, expectedState as customNodesExpectedState };