import { screenSizeStoreReducer, } from './screen-size-store.reducer'; import { INIT_SCREEN_SIZE_REDUCER, InitScreenSizeReducerAction, SET_DESKTOP_CUTOFF_WIDTH, SET_SCREEN_SIZE, SET_TABLET_CUTOFF_WIDTH, SetCutoffWidthAction, SetScreenSizeAction, } from './screen-size-store.actions'; import { ScreenSizeStateInterface, } from './screen-size-state.interface'; const returnsCopyOfStateTest = (actionName: string) => { test('Returns copy of the state', () => { const state = {} as ScreenSizeStateInterface; const newState = screenSizeStoreReducer(state, { type: actionName, }); expect(newState).not.toBe(state); }); }; describe('default', () => { test('Returns a default desktopCutoffWidth', () => { const newState = screenSizeStoreReducer(undefined, { type: '', }); expect(newState.desktopCutoffWidth).toBe(0); }); test('Returns a default screenSize', () => { const newState = screenSizeStoreReducer(undefined, { type: '', }); expect(newState.screenSize).toEqual({ height: 0, width: 0, }); }); test('Returns a default tabletCutoffWidth', () => { const newState = screenSizeStoreReducer(undefined, { type: '', }); expect(newState.tabletCutoffWidth).toBe(0); }); }); describe('INIT_SCREEN_SIZE_REDUCER', () => { returnsCopyOfStateTest(INIT_SCREEN_SIZE_REDUCER); test('Sets the state to the value in the action', () => { const state = {} as ScreenSizeStateInterface; const action = { state: { desktopCutoffWidth: 50, }, type: INIT_SCREEN_SIZE_REDUCER, } as InitScreenSizeReducerAction; const newState = screenSizeStoreReducer( state, action, ); expect(newState).toBe(action.state); }); }); describe('SET_SCREEN_SIZE', () => { returnsCopyOfStateTest(SET_SCREEN_SIZE); test('Sets the screen size to the value in the action', () => { const state = {} as ScreenSizeStateInterface; const action = { screenSize: {}, type: SET_SCREEN_SIZE, } as SetScreenSizeAction; const newState = screenSizeStoreReducer( state, action, ); expect(newState.screenSize).toBe(action.screenSize); }); }); describe('SET_DESKTOP_CUTOFF_WIDTH', () => { returnsCopyOfStateTest(SET_DESKTOP_CUTOFF_WIDTH); // tslint:disable-next-line test('Sets the desktop cut off width to the value in the action', () => { const state = {} as ScreenSizeStateInterface; const action = { cutoffWidth: 100, type: SET_DESKTOP_CUTOFF_WIDTH, } as SetCutoffWidthAction; const newState = screenSizeStoreReducer( state, action, ); expect(newState.desktopCutoffWidth).toBe(100); }); }); describe('SET_TABLET_CUTOFF_WIDTH', () => { returnsCopyOfStateTest(SET_TABLET_CUTOFF_WIDTH); // tslint:disable-next-line test('Sets the tablet cut off width to the value in the action', () => { const state = {} as ScreenSizeStateInterface; const action = { cutoffWidth: 100, type: SET_TABLET_CUTOFF_WIDTH, } as SetCutoffWidthAction; const newState = screenSizeStoreReducer( state, action, ); expect(newState.tabletCutoffWidth).toBe(100); }); });