accounts-frontend/packages/app/components/ui/popup/reducer.test.tsx

99 lines
2.5 KiB
TypeScript
Raw Normal View History

import React, { ComponentType } from 'react';
import expect from 'app/test/unexpected';
import reducer, { PopupConfig, State } from './reducer';
import { create, destroy } from './actions';
const FakeComponent: ComponentType = () => <span />;
describe('popup/reducer', () => {
2020-05-24 04:38:24 +05:30
it('should have no popups by default', () => {
const actual = reducer(undefined, {
type: 'init',
});
2020-05-24 04:38:24 +05:30
expect(actual.popups, 'to be an', 'array');
expect(actual.popups, 'to be empty');
});
2020-05-24 04:38:24 +05:30
describe('#create', () => {
it('should create popup', () => {
const actual = reducer(
undefined,
create({
Popup: FakeComponent,
}),
);
expect(actual.popups[0], 'to equal', {
Popup: FakeComponent,
});
});
it('should create multiple popups', () => {
let actual = reducer(
undefined,
create({
Popup: FakeComponent,
}),
);
actual = reducer(
actual,
create({
Popup: FakeComponent,
}),
);
expect(actual.popups[1], 'to equal', {
Popup: FakeComponent,
});
});
it('throws when no type provided', () => {
expect(
() =>
reducer(
undefined,
// @ts-ignore
create({}),
),
'to throw',
'Popup is required',
);
});
});
2020-05-24 04:38:24 +05:30
describe('#destroy', () => {
let state: State;
let popup: PopupConfig;
2020-05-24 04:38:24 +05:30
beforeEach(() => {
state = reducer(state, create({ Popup: FakeComponent }));
[popup] = state.popups;
});
2020-05-24 04:38:24 +05:30
it('should remove popup', () => {
expect(state.popups, 'to have length', 1);
2020-05-24 04:38:24 +05:30
state = reducer(state, destroy(popup));
2020-05-24 04:38:24 +05:30
expect(state.popups, 'to have length', 0);
});
2020-05-24 04:38:24 +05:30
it('should not remove something, that it should not', () => {
state = reducer(
state,
create({
Popup: FakeComponent,
}),
);
2020-05-24 04:38:24 +05:30
state = reducer(state, destroy(popup));
2020-05-24 04:38:24 +05:30
expect(state.popups, 'to have length', 1);
expect(state.popups[0], 'not to be', popup);
});
});
});