1+ import configureStore from 'redux-mock-store' ;
2+ import thunk from 'redux-thunk' ;
3+ import * as actions from '../../src/redux/actions/CreateTravelRequestAction' ;
4+ import * as dummy from '../../dummyData'
5+ import moxios from 'moxios'
6+ import axios from 'axios' ;
7+ import MockAdapter from 'axios-mock-adapter'
8+ const URL = process . env . REACT_APP_BACKEND_LINK ;
9+
10+ const middlewares = [ thunk ]
11+ const mockStore = configureStore ( middlewares ) ;
12+ let mock = new MockAdapter ( axios )
13+ describe ( 'CREATE TRAVEL REQUEST ACTIONS' , ( ) => {
14+ let store ;
15+
16+ beforeEach ( ( ) => {
17+ moxios . install ( )
18+ store = mockStore ( { createTravelRequest : { } } )
19+ } )
20+ afterEach ( ( ) => moxios . uninstall ( ) )
21+
22+ it ( 'It should retireve available locations' , ( ) => {
23+ mock . onGet ( `${ URL } /locations/` ) . reply ( 200 , {
24+ response : {
25+ locations : dummy . locationsPayload
26+ }
27+ } )
28+ store . dispatch ( actions . getLocationsAction ( ) ) . then ( ( res ) => {
29+ const action = [ {
30+ type : 'SEARCH_LOCATIONS' ,
31+ payload : dummy . locationsPayload
32+ } ]
33+ expect ( store . getActions ( ) . type ) . toEqual ( action . type )
34+ } )
35+ } )
36+ it ( 'should dispatch the SEARCH_LOCATIONS_LOADING action' , ( ) => {
37+ store . clearActions ( ) ;
38+ store . dispatch ( actions . getLocationsAction ( ) )
39+ expect ( store . getActions ( ) ) . toEqual ( [ { "type" : "SEARCH_LOCATIONS_LOADING" } ] ) ;
40+ } )
41+
42+ it ( 'should dispatch the select current location action' , ( ) => {
43+ store . clearActions ( ) ;
44+ store . dispatch ( actions . searchCurrentLocationAction ( dummy . currentLocation ) )
45+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : dummy . currentLocation . selectedLocation , type : "CURRENT_LOCATION" } ] ) ;
46+ } )
47+
48+ it ( 'should dispatch the select destination action' , ( ) => {
49+ store . clearActions ( ) ;
50+ store . dispatch ( actions . searchCurrentLocationAction ( dummy . destinationLocation ) )
51+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : dummy . currentLocation . selectedLocation , type : "DESTINATION_LOCATION" } , { type : 'SEARCH_ACCOMMODATIONS_LOADING' } ] ) ;
52+ } )
53+
54+ it ( 'should dispatch handle error action' , ( ) => {
55+ store . clearActions ( ) ;
56+ store . dispatch ( actions . handleErrorsAction ( 'error message' ) )
57+ expect ( store . getActions ( ) ) . toEqual ( [ { "payload" : "error message" , "type" : "HANDLE_ERRORS" } ] ) ;
58+ } )
59+
60+ it ( 'should dispatch close snack bar action' , ( ) => {
61+ store . clearActions ( ) ;
62+ store . dispatch ( actions . closeSnackbar ( ) )
63+ expect ( store . getActions ( ) ) . toEqual ( [ { type : "CLOSE_SNACKBAR" } ] ) ;
64+ } )
65+ it ( 'should dispatch add travel reason action' , ( ) => {
66+ store . clearActions ( ) ;
67+ store . dispatch ( actions . addTravelReasonAction ( 'reason' ) )
68+ expect ( store . getActions ( ) ) . toEqual ( [ { "payload" : "reason" , "type" : "ADD_TRAVEL_REASON" } ] ) ;
69+ } )
70+
71+ it ( 'should dispatch add multcity action' , ( ) => {
72+ store . clearActions ( ) ;
73+ store . dispatch ( actions . addMultiCityAction ( dummy . selectedLocaton ) )
74+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : dummy . selectedLocaton , "type" : "ADD_MULTI_CITY_TRAVEL_REQUEST" } ] ) ;
75+ } )
76+
77+ it ( 'should dispatch remove multcity action' , ( ) => {
78+ store . clearActions ( ) ;
79+ store . dispatch ( actions . removeMultiCityAction ( dummy . selectedLocaton ) )
80+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : dummy . selectedLocaton , "type" : "REMOVE_MULTI_CITY_TRAVEL_REQUEST" } ] ) ;
81+ } )
82+
83+ it ( 'should dispatch open model action' , ( ) => {
84+ store . clearActions ( ) ;
85+ store . dispatch ( actions . openModalAction ( dummy . openModalPayload ) )
86+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : dummy . openModalPayload , "type" : "OPEN_MODAL" } ] ) ;
87+ } )
88+ it ( 'should dispatch travel date action' , ( ) => {
89+ store . clearActions ( ) ;
90+ store . dispatch ( actions . checkTravelDatesAction ( dummy . dates ) )
91+ expect ( store . getActions ( ) ) . toEqual ( [ { payload : { departureDate : dummy . dates . departureDate , returnDate : dummy . dates . returnDate } , "type" : "TRAVEL_DATES" } ] ) ;
92+ } )
93+ it ( 'It should select accomodation' , ( ) => {
94+ const action = [ {
95+ type : 'SELECT_ACCOMMODATION' ,
96+ payload : {
97+ accommodation : dummy . selectedAccommodationsPayload . selected ,
98+ displaySelection : dummy . selectedAccommodationsPayload . checked ,
99+ displaySelected : ! dummy . selectedAccommodationsPayload . checked
100+ }
101+ } ]
102+ store . dispatch ( actions . selectAccommodationAction ( dummy . selectedAccommodationsPayload ) )
103+ expect ( store . getActions ( ) . type ) . toEqual ( action . type )
104+ } )
105+
106+ it ( 'It should deselect accomodation' , ( ) => {
107+ const action = [ {
108+ type : 'DESELECT_ACCOMMODATION' ,
109+ payload : {
110+ accommodation : dummy . selectedAccommodationsPayload . selected ,
111+ displaySelection : true ,
112+ displaySelected : true
113+ }
114+ } ]
115+ store . dispatch ( actions . selectAccommodationAction ( dummy . deselectedAccommodationsPayload ) )
116+ expect ( store . getActions ( ) . type ) . toEqual ( action . type )
117+ } )
118+ it ( 'It should remove multcity destination' , ( ) => {
119+ const action = [ {
120+ type : 'REMOVE_MULTI_CITY_TRAVEL_REQUEST' ,
121+ payload : {
122+ accommodation : dummy . removeMultiCityPayload ,
123+ }
124+ } ]
125+ store . dispatch ( actions . removeMultiCityAction ( dummy . deselectedAccommodationsPayload ) )
126+ expect ( store . getActions ( ) . type ) . toEqual ( action . type )
127+ } )
128+
129+ it ( 'It should send travel request' , ( ) => {
130+ mock . onPost ( `${ URL } /requests/request` ) . reply ( 200 , {
131+ response : {
132+ locations : dummy . createTravelRequest
133+ }
134+ } )
135+ store . dispatch ( actions . getLocationsAction ( dummy . createTravelRequest ) ) . then ( ( res ) => {
136+ const action = [ {
137+ type : 'SEND_TRAVEL_REQUEST' ,
138+ payload : dummy . createTravelRequest
139+ } ]
140+ expect ( store . getActions ( ) . type ) . toEqual ( action . type )
141+ } )
142+ } )
143+ } )
0 commit comments