2022-04-13 15:04:41 -07:00
|
|
|
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-07-08 17:22:49 -07:00
|
|
|
import * as actions from 'soapbox/actions/lists';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
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', () => {
|
2022-06-12 11:29:28 -07:00
|
|
|
expect(reducer(undefined, {} as any)).toMatchObject({
|
2020-06-09 18:08:07 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: {
|
2020-06-09 18:08:07 -07:00
|
|
|
items: ImmutableList(),
|
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
},
|
|
|
|
});
|
2020-06-09 18:08:07 -07:00
|
|
|
});
|
2020-07-07 17:38:16 -07:00
|
|
|
|
|
|
|
it('should handle LIST_ADDER_RESET', () => {
|
2022-04-13 15:04:41 -07:00
|
|
|
const state = ImmutableRecord({
|
2020-07-07 17:38:16 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: ImmutableRecord({
|
2022-06-12 11:29:28 -07:00
|
|
|
items: ImmutableList<string>(),
|
2020-07-07 17:38:16 -07:00
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
})(),
|
|
|
|
})();
|
2020-07-07 17:38:16 -07:00
|
|
|
const action = {
|
|
|
|
type: actions.LIST_ADDER_RESET,
|
|
|
|
};
|
2022-04-13 15:04:41 -07:00
|
|
|
expect(reducer(state, action)).toMatchObject({
|
2020-07-07 17:38:16 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: {
|
2020-07-07 17:38:16 -07:00
|
|
|
items: ImmutableList(),
|
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
},
|
|
|
|
});
|
2020-07-07 17:38:16 -07:00
|
|
|
});
|
|
|
|
|
2020-07-08 17:22:49 -07:00
|
|
|
it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => {
|
2022-04-13 15:04:41 -07:00
|
|
|
const state = ImmutableRecord({
|
2020-07-08 17:22:49 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: ImmutableRecord({
|
2022-06-12 11:29:28 -07:00
|
|
|
items: ImmutableList<string>(),
|
2020-07-08 17:22:49 -07:00
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
})(),
|
|
|
|
})();
|
2020-07-08 17:22:49 -07:00
|
|
|
const action = {
|
|
|
|
type: actions.LIST_ADDER_LISTS_FETCH_REQUEST,
|
|
|
|
};
|
2022-04-13 15:04:41 -07:00
|
|
|
expect(reducer(state, action)).toMatchObject({
|
2020-07-08 17:22:49 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: {
|
2020-07-08 17:22:49 -07:00
|
|
|
items: ImmutableList(),
|
|
|
|
loaded: false,
|
|
|
|
isLoading: true,
|
2022-04-13 15:04:41 -07:00
|
|
|
},
|
|
|
|
});
|
2020-07-08 17:22:49 -07:00
|
|
|
});
|
2020-07-07 17:38:16 -07:00
|
|
|
|
|
|
|
it('should handle LIST_ADDER_LISTS_FETCH_FAIL', () => {
|
2022-04-13 15:04:41 -07:00
|
|
|
const state = ImmutableRecord({
|
2020-07-07 17:38:16 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: ImmutableRecord({
|
2022-06-12 11:29:28 -07:00
|
|
|
items: ImmutableList<string>(),
|
2020-07-07 17:38:16 -07:00
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
})(),
|
|
|
|
})();
|
2020-07-07 17:38:16 -07:00
|
|
|
const action = {
|
|
|
|
type: actions.LIST_ADDER_LISTS_FETCH_FAIL,
|
|
|
|
};
|
2022-04-13 15:04:41 -07:00
|
|
|
expect(reducer(state, action)).toMatchObject({
|
2020-07-07 17:38:16 -07:00
|
|
|
accountId: null,
|
|
|
|
|
2022-04-13 15:04:41 -07:00
|
|
|
lists: {
|
2020-07-07 17:38:16 -07:00
|
|
|
items: ImmutableList(),
|
|
|
|
loaded: false,
|
|
|
|
isLoading: false,
|
2022-04-13 15:04:41 -07:00
|
|
|
},
|
|
|
|
});
|
2020-07-07 17:38:16 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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
|
|
|
});
|