|
| 1 | +import { channel1, channel0 } from '../data.mock'; |
| 2 | +import * as actionTypes from '../actionTypes'; |
| 3 | +import reducers from '../reducers'; |
| 4 | +import initialState from '../initialState'; |
| 5 | + |
| 6 | +const CUSTOM_FILTER = 'GROUP_CHAT'; |
| 7 | +const channelListQuery = { |
| 8 | + includeEmpty: true, |
| 9 | + customTypesFilter: [CUSTOM_FILTER], |
| 10 | +}; |
| 11 | + |
| 12 | +describe('Channels-Reducers/CHANNEL_REPLACED_TO_TOP', () => { |
| 13 | + it('should move existing channel to top of the list', () => { |
| 14 | + const state = { |
| 15 | + ...initialState, |
| 16 | + allChannels: [channel0, channel1], |
| 17 | + }; |
| 18 | + const action = { |
| 19 | + type: actionTypes.CHANNEL_REPLACED_TO_TOP, |
| 20 | + payload: channel1, |
| 21 | + }; |
| 22 | + const expectedState = { |
| 23 | + ...state, |
| 24 | + allChannels: [channel1, channel0], |
| 25 | + }; |
| 26 | + |
| 27 | + const nextState = reducers(state, action); |
| 28 | + |
| 29 | + expect(nextState).toEqual(expectedState); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should move channel to top of the list if doesnt exist', () => { |
| 33 | + const state = { |
| 34 | + ...initialState, |
| 35 | + allChannels: [channel0], |
| 36 | + }; |
| 37 | + const action = { |
| 38 | + type: actionTypes.CHANNEL_REPLACED_TO_TOP, |
| 39 | + payload: channel1, |
| 40 | + }; |
| 41 | + const expectedState = { |
| 42 | + ...state, |
| 43 | + allChannels: [channel1, channel0], |
| 44 | + }; |
| 45 | + |
| 46 | + const nextState = reducers(state, action); |
| 47 | + |
| 48 | + expect(nextState).toEqual(expectedState); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should not prepend channel if channelListQuery doesnt pass', () => { |
| 52 | + const state = { |
| 53 | + ...initialState, |
| 54 | + channelListQuery, |
| 55 | + allChannels: [channel0], |
| 56 | + }; |
| 57 | + const action = { |
| 58 | + type: actionTypes.CHANNEL_REPLACED_TO_TOP, |
| 59 | + payload: channel1, |
| 60 | + }; |
| 61 | + const expectedState = { |
| 62 | + ...state, |
| 63 | + allChannels: [channel0], |
| 64 | + }; |
| 65 | + |
| 66 | + const nextState = reducers(state, action); |
| 67 | + |
| 68 | + expect(nextState).toEqual(expectedState); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should prepend channel if channelListQuery pass', () => { |
| 72 | + const state = { |
| 73 | + ...initialState, |
| 74 | + channelListQuery, |
| 75 | + allChannels: [channel0], |
| 76 | + }; |
| 77 | + const customChannel = { |
| 78 | + ...channel1, |
| 79 | + customType: CUSTOM_FILTER, |
| 80 | + }; |
| 81 | + const action = { |
| 82 | + type: actionTypes.CHANNEL_REPLACED_TO_TOP, |
| 83 | + payload: customChannel, |
| 84 | + }; |
| 85 | + const expectedState = { |
| 86 | + ...state, |
| 87 | + allChannels: [customChannel, channel0], |
| 88 | + }; |
| 89 | + |
| 90 | + const nextState = reducers(state, action); |
| 91 | + |
| 92 | + expect(nextState).toEqual(expectedState); |
| 93 | + }); |
| 94 | +}); |
0 commit comments