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

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-06-22 05:55:42 -07:00
import { AnyAction } from 'redux';
import {
CAROUSEL_AVATAR_REQUEST,
CAROUSEL_AVATAR_SUCCESS,
CAROUSEL_AVATAR_FAIL,
} from 'soapbox/actions/carousels';
import reducer from '../carousels';
describe('carousels reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {} as AnyAction)).toEqual({
avatars: [],
isLoading: false,
});
});
describe('CAROUSEL_AVATAR_REQUEST', () => {
it('sets "isLoading" to "true"', () => {
const initialState = { isLoading: false, avatars: [] };
const action = { type: CAROUSEL_AVATAR_REQUEST };
expect(reducer(initialState, action).isLoading).toEqual(true);
});
});
describe('CAROUSEL_AVATAR_SUCCESS', () => {
it('sets the next state', () => {
const initialState = { isLoading: true, avatars: [] };
const action = { type: CAROUSEL_AVATAR_SUCCESS, payload: [45] };
const result = reducer(initialState, action);
expect(result.isLoading).toEqual(false);
expect(result.avatars).toEqual([45]);
});
});
describe('CAROUSEL_AVATAR_FAIL', () => {
it('sets "isLoading" to "true"', () => {
const initialState = { isLoading: true, avatars: [] };
const action = { type: CAROUSEL_AVATAR_FAIL };
expect(reducer(initialState, action).isLoading).toEqual(false);
});
});
});