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

99 lines
2.1 KiB
JavaScript
Raw Normal View History

import expect from 'app/test/unexpected';
2019-12-07 16:58:52 +05:30
import React from 'react';
import reducer from 'app/components/ui/popup/reducer';
import { create, destroy } from 'app/components/ui/popup/actions';
describe('popup/reducer', () => {
it('should have no popups by default', () => {
2019-12-07 16:58:52 +05:30
const actual = reducer(undefined, {
type: 'init',
});
expect(actual.popups, 'to be an', 'array');
expect(actual.popups, 'to be empty');
});
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(
2019-12-07 16:58:52 +05:30
() =>
reducer(
undefined,
// @ts-ignore
create({}),
),
'to throw',
'Popup is required',
);
});
});
describe('#destroy', () => {
let state;
let popup;
beforeEach(() => {
state = reducer(state, create({ Popup: FakeComponent }));
popup = state.popups[0];
});
it('should remove popup', () => {
expect(state.popups, 'to have length', 1);
state = reducer(state, destroy(popup));
expect(state.popups, 'to have length', 0);
});
it('should not remove something, that it should not', () => {
state = reducer(
state,
create({
Popup: FakeComponent,
}),
);
state = reducer(state, destroy(popup));
expect(state.popups, 'to have length', 1);
expect(state.popups[0], 'not to be', popup);
});
});
});
2016-05-11 10:56:44 +05:30
2019-12-07 16:58:52 +05:30
function FakeComponent() {
return <span />;
}