bigbuffet-rw/app/soapbox/reducers/__tests__/modals.test.ts

66 lines
1.5 KiB
TypeScript
Raw Normal View History

import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
import { MODAL_OPEN, MODAL_CLOSE } from 'soapbox/actions/modals';
import reducer from '../modals';
2020-06-09 18:08:07 -07:00
describe('modal reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {} as any)).toEqual(ImmutableList());
2020-06-09 18:08:07 -07:00
});
2020-07-09 16:44:23 -07:00
it('should handle MODAL_OPEN', () => {
const state = ImmutableList<any>();
2020-07-09 16:44:23 -07:00
const action = {
type: MODAL_OPEN,
modalType: 'type1',
modalProps: { props1: '1' },
2020-07-09 17:37:04 -07:00
};
expect(reducer(state, action).toJS()).toMatchObject([{
2020-07-09 16:44:23 -07:00
modalType: 'type1',
modalProps: { props1: '1' },
}]);
2020-07-09 16:44:23 -07:00
});
it('should handle MODAL_CLOSE', () => {
const state = ImmutableList([
ImmutableRecord({
modalType: 'type1',
modalProps: { props1: '1' },
})(),
]);
const action = {
type: MODAL_CLOSE,
2020-07-09 17:37:04 -07:00
};
expect(reducer(state, action).toJS()).toMatchObject([]);
});
it('should handle MODAL_CLOSE with specified modalType', () => {
const state = ImmutableList([
ImmutableRecord({
modalType: 'type1',
modalProps: null,
})(),
ImmutableRecord({
modalType: 'type2',
modalProps: null,
})(),
ImmutableRecord({
modalType: 'type1',
modalProps: null,
})(),
]);
2020-07-09 16:44:23 -07:00
const action = {
type: MODAL_CLOSE,
modalType: 'type2',
2020-07-09 17:37:04 -07:00
};
expect(reducer(state, action).toJS()).toEqual([
{
modalType: 'type1',
modalProps: null,
},
]);
2020-07-09 16:44:23 -07:00
});
2020-06-09 18:08:07 -07:00
});