pleroma/app/soapbox/reducers/__tests__/list-adder.test.ts

117 lines
2.6 KiB
TypeScript
Raw Normal View History

import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
2020-07-08 17:22:49 -07:00
import * as actions from 'soapbox/actions/lists';
2022-11-15 12:39:43 -08:00
import reducer from '../list-adder';
2020-06-09 18:08:07 -07:00
describe('list_adder reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {} as any)).toMatchObject({
2020-06-09 18:08:07 -07:00
accountId: null,
lists: {
2020-06-09 18:08:07 -07:00
items: ImmutableList(),
loaded: false,
isLoading: false,
},
});
2020-06-09 18:08:07 -07:00
});
it('should handle LIST_ADDER_RESET', () => {
const state = ImmutableRecord({
accountId: null,
lists: ImmutableRecord({
items: ImmutableList<string>(),
loaded: false,
isLoading: false,
})(),
})();
const action = {
type: actions.LIST_ADDER_RESET,
};
expect(reducer(state, action)).toMatchObject({
accountId: null,
lists: {
items: ImmutableList(),
loaded: false,
isLoading: false,
},
});
});
2020-07-08 17:22:49 -07:00
it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => {
const state = ImmutableRecord({
2020-07-08 17:22:49 -07:00
accountId: null,
lists: ImmutableRecord({
items: ImmutableList<string>(),
2020-07-08 17:22:49 -07:00
loaded: false,
isLoading: false,
})(),
})();
2020-07-08 17:22:49 -07:00
const action = {
type: actions.LIST_ADDER_LISTS_FETCH_REQUEST,
};
expect(reducer(state, action)).toMatchObject({
2020-07-08 17:22:49 -07:00
accountId: null,
lists: {
2020-07-08 17:22:49 -07:00
items: ImmutableList(),
loaded: false,
isLoading: true,
},
});
2020-07-08 17:22:49 -07:00
});
it('should handle LIST_ADDER_LISTS_FETCH_FAIL', () => {
const state = ImmutableRecord({
accountId: null,
lists: ImmutableRecord({
items: ImmutableList<string>(),
loaded: false,
isLoading: false,
})(),
})();
const action = {
type: actions.LIST_ADDER_LISTS_FETCH_FAIL,
};
expect(reducer(state, action)).toMatchObject({
accountId: null,
lists: {
items: ImmutableList(),
loaded: false,
isLoading: false,
},
});
});
// it('should handle LIST_ADDER_LISTS_FETCH_SUCCESS', () => {
// const state = ImmutableMap({
// accountId: null,
//
// lists: ImmutableMap({
// items: ImmutableList(),
// loaded: false,
// isLoading: false,
// }),
// });
// const action = {
// type: actions.LIST_ADDER_LISTS_FETCH_SUCCESS,
// };
// expect(reducer(state, action)).toEqual(ImmutableMap({
// accountId: null,
//
// lists: ImmutableMap({
// items: ImmutableList(),
// loaded: true,
// isLoading: false,
// }),
// }));
// });
2020-06-09 18:08:07 -07:00
});