|
| 1 | +import reducer, { releaseState, getActions } from '@/reducers/releaseReducer'; |
| 2 | + |
| 3 | +describe('releaseReducer', () => { |
| 4 | + it('should return the initial state', () => { |
| 5 | + const initialState = releaseState; |
| 6 | + const action = { type: 'UNKNOWN_ACTION' }; |
| 7 | + expect(reducer(initialState, action)).toEqual(initialState); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should handle SET_VERSION action', () => { |
| 11 | + const initialState = releaseState; |
| 12 | + const action = { type: 'SET_VERSION', payload: 'v14.17.0' }; |
| 13 | + const expectedState = { ...initialState, version: 'v14.17.0' }; |
| 14 | + expect(reducer(initialState, action)).toEqual(expectedState); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should handle SET_OS action', () => { |
| 18 | + const initialState = releaseState; |
| 19 | + const action = { type: 'SET_OS', payload: 'Linux' }; |
| 20 | + const expectedState = { ...initialState, os: 'Linux' }; |
| 21 | + expect(reducer(initialState, action)).toEqual(expectedState); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should handle SET_PLATFORM action', () => { |
| 25 | + const initialState = releaseState; |
| 26 | + const action = { type: 'SET_PLATFORM', payload: 'arm64' }; |
| 27 | + const expectedState = { ...initialState, platform: 'arm64' }; |
| 28 | + expect(reducer(initialState, action)).toEqual(expectedState); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should handle SET_INSTALL_METHOD action', () => { |
| 32 | + const initialState = releaseState; |
| 33 | + const action = { type: 'SET_INSTALL_METHOD', payload: 'binary' }; |
| 34 | + const expectedState = { ...initialState, installMethod: 'binary' }; |
| 35 | + expect(reducer(initialState, action)).toEqual(expectedState); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should handle SET_MANAGER action', () => { |
| 39 | + const initialState = releaseState; |
| 40 | + const action = { type: 'SET_MANAGER', payload: 'Yarn' }; |
| 41 | + const expectedState = { ...initialState, packageManager: 'Yarn' }; |
| 42 | + expect(reducer(initialState, action)).toEqual(expectedState); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +describe('getActions', () => { |
| 47 | + it('should create actions correctly', () => { |
| 48 | + const dispatch = jest.fn(); |
| 49 | + const actions = getActions(dispatch); |
| 50 | + |
| 51 | + actions.setVersion('v14.17.0'); |
| 52 | + expect(dispatch).toHaveBeenCalledWith({ |
| 53 | + type: 'SET_VERSION', |
| 54 | + payload: 'v14.17.0', |
| 55 | + }); |
| 56 | + |
| 57 | + actions.setOS('Linux'); |
| 58 | + expect(dispatch).toHaveBeenCalledWith({ type: 'SET_OS', payload: 'Linux' }); |
| 59 | + |
| 60 | + actions.setPlatform('arm64'); |
| 61 | + expect(dispatch).toHaveBeenCalledWith({ |
| 62 | + type: 'SET_PLATFORM', |
| 63 | + payload: 'arm64', |
| 64 | + }); |
| 65 | + |
| 66 | + actions.setInstallMethod('binary'); |
| 67 | + expect(dispatch).toHaveBeenCalledWith({ |
| 68 | + type: 'SET_INSTALL_METHOD', |
| 69 | + payload: 'binary', |
| 70 | + }); |
| 71 | + |
| 72 | + actions.setPackageManager('Yarn'); |
| 73 | + expect(dispatch).toHaveBeenCalledWith({ |
| 74 | + type: 'SET_MANAGER', |
| 75 | + payload: 'Yarn', |
| 76 | + }); |
| 77 | + }); |
| 78 | +}); |
0 commit comments