|
| 1 | +import { |
| 2 | + GET_ORG_REPOS, |
| 3 | + GET_ORG_REPOS_LOADING, |
| 4 | + GET_ORG_REPOS_ERROR, |
| 5 | +} from 'organization/organization.constants'; |
| 6 | +import { |
| 7 | + initialState, |
| 8 | + organizationReducer, |
| 9 | +} from 'organization/organization.reducer'; |
| 10 | + |
| 11 | +describe('Organization Reducer', () => { |
| 12 | + it('should set initial state', () => { |
| 13 | + expect(organizationReducer(undefined, {})).toEqual(initialState); |
| 14 | + }); |
| 15 | + |
| 16 | + [true, false].forEach(payload => { |
| 17 | + it(`should set loading state to ${JSON.stringify( |
| 18 | + payload |
| 19 | + )} on action "GET_ORG_REPOS_LOADING"`, () => { |
| 20 | + const action = { type: GET_ORG_REPOS_LOADING, payload }; |
| 21 | + const expectedState = { ...initialState, isPendingRepos: action.payload }; |
| 22 | + |
| 23 | + expect(organizationReducer(initialState, action)).toEqual(expectedState); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + [{ id: 1 }, { id: 2 }].forEach(payload => { |
| 28 | + it('should set repos on success on action "GET_ORG_REPOS"', () => { |
| 29 | + const action = { type: GET_ORG_REPOS, payload }; |
| 30 | + const expectedState = { |
| 31 | + ...initialState, |
| 32 | + isPendingRepos: false, |
| 33 | + repositories: payload, |
| 34 | + }; |
| 35 | + |
| 36 | + expect(organizationReducer(initialState, action)).toEqual(expectedState); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should set error state on action "GET_ORG_REPOS_ERROR"', () => { |
| 41 | + const action = { type: GET_ORG_REPOS_ERROR, payload: 'error' }; |
| 42 | + const expectedState = { |
| 43 | + ...initialState, |
| 44 | + organizationRepositoriesError: action.payload, |
| 45 | + }; |
| 46 | + |
| 47 | + expect(organizationReducer(initialState, action)).toEqual(expectedState); |
| 48 | + }); |
| 49 | +}); |
0 commit comments