1 import configureMockStore from 'redux-mock-store';
2 import thunk from 'redux-thunk';
3 import fetchMock from 'fetch-mock';
4 import expect from 'expect';
6 import {onLoadTotalCountByDate, onCountByTypeLoad, onTopographicMapMounted} from 'app/inventory/InventoryActions';
7 import {InventoryActionTypes} from 'app/inventory/InventoryConstants';
10 const middlewares = [thunk];
11 const mockStore = configureMockStore(middlewares);
14 function mockRequestToEntityCountHistoryEndpoint(postfix, response) {
16 `http://localhost:/rest/visualization${postfix}`,
21 describe('InventoryActions', () => {
27 describe('verify onLoadTotalCountByDate', () => {
28 it('creates COUNT_BY_DATE_SUCCESS response when there is no error', async () => {
31 mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=graph",{
41 const expectedActions = [
43 type: InventoryActionTypes.COUNT_BY_DATE_SUCCESS,
52 const store = mockStore();
55 await store.dispatch(onLoadTotalCountByDate());
58 expect(store.getActions()).toEqual(expectedActions);
62 it('creates COUNT_BY_DATE_FAILED response when there is a problem with remote service', async () => {
65 mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=graph",{
69 const expectedActions = [
71 type: InventoryActionTypes.COUNT_BY_DATE_FAILED,
73 message: 'Error fetching data from server',
78 const store = mockStore();
81 await store.dispatch(onLoadTotalCountByDate());
84 expect(store.getActions()).toEqual(expectedActions);
90 describe('verify onCountByTypeLoad', () => {
91 it('creates COUNT_BY_ENTITY_SUCCESS response when there is no error', async () => {
94 mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=table",{
104 const expectedActions = [
106 type: InventoryActionTypes.COUNT_BY_ENTITY_SUCCESS,
115 const store = mockStore();
118 await store.dispatch(onCountByTypeLoad());
121 expect(store.getActions()).toEqual(expectedActions);
125 it('creates COUNT_BY_ENTITY_FAILED response when there is a problem with remote service', async () => {
128 mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=table",{
132 const expectedActions = [
134 type: InventoryActionTypes.COUNT_BY_ENTITY_FAILED,
136 message: 'Error fetching data from server',
141 const store = mockStore();
144 await store.dispatch(onCountByTypeLoad());
147 expect(store.getActions()).toEqual(expectedActions);
153 describe('verify onTopographicMapMounted', () => {
154 it('creates TOPOGRAPHIC_QUERY_SUCCESS response when there is no error', async () => {
157 const requestObject = {
158 entityType: "entityType"
160 mockRequestToEntityCountHistoryEndpoint("/geovisualization/?entity=entityType",{
170 const expectedActions = [
172 type: InventoryActionTypes.TOPOGRAPHIC_QUERY_SUCCESS,
181 const store = mockStore();
184 await store.dispatch(onTopographicMapMounted(requestObject));
187 expect(store.getActions()).toEqual(expectedActions);
191 it('creates TOPOGRAPHIC_QUERY_FAILED response when there is a problem with remote service', async () => {
194 const requestObject = {
195 entityType: "entityType"
197 mockRequestToEntityCountHistoryEndpoint("/geovisualization/?entity=entityType",{
201 const expectedActions = [
203 type: InventoryActionTypes.TOPOGRAPHIC_QUERY_FAILED,
205 message: 'Error fetching data from server',
210 const store = mockStore();
213 await store.dispatch(onTopographicMapMounted(requestObject));
216 expect(store.getActions()).toEqual(expectedActions);