import { AppState } from './types' import SUT, { initialState as sliceInitialState } from './App.slice' import { appSlice } from '.' describe('App Slice', () => { describe('Redux Actions', () => { describe('initApp', () => { it('should return an action of type AppActions.InitApp', () => { // when ... we call the initApp action creator const action = SUT.actions.initApp() const expectedAction = { type: 'app/initApp', } // then we should expect it to create an action with the correct type and payload expect(action).toEqual(expectedAction) }) }) describe('initAppSuccess', () => { it('should return an action of type AppActions.InitAppSuccess', () => { // when ... we call the initAppSuccess action creator const action = SUT.actions.initAppSuccess() const expectedAction = { type: 'app/initAppSuccess', } // then we should expect it to create an action with the correct type expect(action).toEqual(expectedAction) }) }) describe('initAppFailure', () => { it('should return an action of type AppActions.InitAppSuccess', () => { // when ... we call the initAppFailure action creator const action = SUT.actions.initAppFailure() const expectedAction = { type: 'app/initAppFailure', } // then we should expect it to create an action with the correct type expect(action).toEqual(expectedAction) }) }) }) describe('App Reducer', () => { let initialTestState: AppState beforeEach(() => { initialTestState = sliceInitialState }) describe('initApp Action', () => { it('should return a new copy of state, set state.loading to true and state.loaded to false', () => { // given ... we create an initApp action const action = appSlice.actions.initApp() // when ... we run the reducer and pass it our initialState and this action const state = SUT.reducer(initialTestState, action) // then ... it should set the loading value of state to true expect(state.loading).toBe(true) // ... it should set the loaded value of state to false expect(state.loaded).toBe(false) }) }) describe('initAppSuccess Action', () => { it('should return a new copy of state, set state.loading to false and state.loaded to true', () => { // given ... we create an initAppSuccess action const action = appSlice.actions.initAppSuccess() // when ... we run the reducer and pass it our initialState and this action const state = SUT.reducer(initialTestState, action) // then // ... should set the loading value of state to false expect(state.loading).toBe(false) // ... should set the loaded value of state to true expect(state.loaded).toBe(true) }) }) describe('initAppFailure Action', () => { it('should return a new copy of state, set state.loading to false and state.loaded to false', () => { // given ... we create an initAppFailure action const action = appSlice.actions.initAppFailure() // when ... we run the reducer and pass it our initialState and this action const state = SUT.reducer(initialTestState, action) // then // ... should set the loading value of state to false expect(state.loading).toBe(false) // ... should set the loaded value of state to true expect(state.loaded).toBe(false) }) }) }) })