|
| 1 | +import ActionUtility from '../../utilities/ActionUtility'; |
| 2 | +import ShowsReducer from './ShowsReducer'; |
| 3 | +import ShowsAction from './ShowsAction'; |
| 4 | +import ShowModel from './models/shows/ShowModel'; |
| 5 | +import EpisodeModel from './models/episodes/EpisodeModel'; |
| 6 | +import CastModel from './models/cast/CastModel'; |
| 7 | + |
| 8 | +describe('ShowsReducer', () => { |
| 9 | + const showsReducer = new ShowsReducer(); |
| 10 | + |
| 11 | + it('returns default state with invalid action type', () => { |
| 12 | + const action = ActionUtility.createAction(''); |
| 13 | + |
| 14 | + expect(showsReducer.reducer(undefined, action)).toEqual(showsReducer.initialState); |
| 15 | + }); |
| 16 | + |
| 17 | + describe(ShowsAction.REQUEST_SHOW_FINISHED, () => { |
| 18 | + it('should update show state', () => { |
| 19 | + const payload = new ShowModel({}); |
| 20 | + const action = ActionUtility.createAction(ShowsAction.REQUEST_SHOW_FINISHED, payload); |
| 21 | + |
| 22 | + const actualResult = showsReducer.reducer(showsReducer.initialState, action); |
| 23 | + const expectedResult = { |
| 24 | + ...showsReducer.initialState, |
| 25 | + show: payload, |
| 26 | + }; |
| 27 | + |
| 28 | + expect(actualResult).toEqual(expectedResult); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe(ShowsAction.REQUEST_EPISODES_FINISHED, () => { |
| 33 | + it('should update episodes state', () => { |
| 34 | + const payload = [new EpisodeModel({})]; |
| 35 | + const action = ActionUtility.createAction(ShowsAction.REQUEST_EPISODES_FINISHED, payload); |
| 36 | + |
| 37 | + const actualResult = showsReducer.reducer(showsReducer.initialState, action); |
| 38 | + const expectedResult = { |
| 39 | + ...showsReducer.initialState, |
| 40 | + episodes: payload, |
| 41 | + }; |
| 42 | + |
| 43 | + expect(actualResult).toEqual(expectedResult); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe(ShowsAction.REQUEST_CAST_FINISHED, () => { |
| 48 | + it('should update cast state', () => { |
| 49 | + const payload = [new CastModel({})]; |
| 50 | + const action = ActionUtility.createAction(ShowsAction.REQUEST_CAST_FINISHED, payload); |
| 51 | + |
| 52 | + const actualResult = showsReducer.reducer(showsReducer.initialState, action); |
| 53 | + const expectedResult = { |
| 54 | + ...showsReducer.initialState, |
| 55 | + actors: payload, |
| 56 | + }; |
| 57 | + |
| 58 | + expect(actualResult).toEqual(expectedResult); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments