X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fsparky-fe.git;a=blobdiff_plain;f=test%2Fapp%2Finventory%2FInventoryReducer.test.js;fp=test%2Fapp%2Finventory%2FInventoryReducer.test.js;h=49f8e581678f34041ee1a05f866d8184d564fe0b;hp=0000000000000000000000000000000000000000;hb=b2c7546f9027099161aeaf5791f1d0f3a52b92d2;hpb=85fa41b6a03a3914788e825cb28db84b33772489 diff --git a/test/app/inventory/InventoryReducer.test.js b/test/app/inventory/InventoryReducer.test.js new file mode 100644 index 0000000..49f8e58 --- /dev/null +++ b/test/app/inventory/InventoryReducer.test.js @@ -0,0 +1,186 @@ +import fetchMock from 'fetch-mock'; +import expect from 'expect'; +import {InventoryActionTypes} from "app/inventory/InventoryConstants"; +import reducer from 'app/inventory/InventoryReducer'; + + + +function verifyStateProducedByReducer(action, currentState, expectedState) { + // when + const actual = reducer(currentState, action); + + // then + expect(actual).toEqual(expectedState); +} + +describe('InventoryReducer', () => { + + afterEach(() => { + fetchMock.restore() + }); + + it('verify store state after TOPOGRAPHIC_QUERY_SUCCESS action', async () => { + + // given + const action = { + type: InventoryActionTypes.TOPOGRAPHIC_QUERY_SUCCESS, + data: { + "plotPoints": { + "keyA": "valueA", + "keyB": "valueB" + } + } + }; + + const expectedState = { + state: "dummy", + mapPlotPoints: { + "keyA": "valueA", + "keyB": "valueB" + } + }; + + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + + }); + + it('verify store state after COUNT_BY_ENTITY_SUCCESS action', async () => { + + // given + const action = { + type: InventoryActionTypes.COUNT_BY_ENTITY_SUCCESS, + data: { + "countByType": { + "keyA": "valueA", + "keyB": "valueB" + } + } + }; + + const expectedState = { + state: "dummy", + countByType: { + "keyA": "valueA", + "keyB": "valueB" + } + }; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + + + it('verify store state after COUNT_BY_DATE_SUCCESS action', async () => { + + // given + const action = { + type: InventoryActionTypes.COUNT_BY_DATE_SUCCESS, + data: { + "countByDate": { + "keyA": "valueA", + "keyB": "valueB" + } + } + }; + + const expectedState = { + state: "dummy", + countByDate: { + "keyA": "valueA", + "keyB": "valueB" + } + }; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + + it('verify store state after TOPOGRAPHIC_QUERY_FAILED action', async () => { + + // given + const action = { + type: InventoryActionTypes.TOPOGRAPHIC_QUERY_FAILED, + data: { + severity: "ERROR", + message: "Some error occurred" + } + }; + + const expectedState = { + state: "dummy", + feedbackMsgSeverity: "ERROR", + feedbackMsgText: "Some error occurred" + + }; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + + it('verify store state after COUNT_BY_ENTITY_FAILED action', async () => { + + // given + const action = { + type: InventoryActionTypes.COUNT_BY_ENTITY_FAILED, + data: { + severity: "ERROR", + message: "Some error occurred" + } + }; + + const expectedState = { + state: "dummy", + feedbackMsgSeverity: "ERROR", + feedbackMsgText: "Some error occurred" + + }; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + + it('verify store state after COUNT_BY_DATE_FAILED action', async () => { + + // given + const action = { + type: InventoryActionTypes.COUNT_BY_DATE_FAILED, + data: { + severity: "ERROR", + message: "Some error occurred" + } + }; + + const expectedState = { + state: "dummy", + feedbackMsgSeverity: "ERROR", + feedbackMsgText: "Some error occurred" + + }; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + + it('verify store state after unknown action', async () => { + + // given + const action = { + type: 'unknown', + }; + + const expectedState = {state: "dummy"}; + + const currentState = {state: "dummy"}; + + verifyStateProducedByReducer(action, currentState, expectedState); + }); + +});