2020-01-18 02:07:52 +05:30
|
|
|
import React, { ComponentType } from 'react';
|
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2020-01-18 02:07:52 +05:30
|
|
|
|
|
|
|
import reducer, { PopupConfig, State } from './reducer';
|
|
|
|
import { create, destroy } from './actions';
|
|
|
|
|
|
|
|
const FakeComponent: ComponentType = () => <span />;
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
describe('popup/reducer', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should have no popups by default', () => {
|
2019-12-07 16:58:52 +05:30
|
|
|
const actual = reducer(undefined, {
|
|
|
|
type: 'init',
|
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
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,
|
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('throws when no type provided', () => {
|
|
|
|
expect(
|
2019-12-07 16:58:52 +05:30
|
|
|
() =>
|
|
|
|
reducer(
|
|
|
|
undefined,
|
|
|
|
// @ts-ignore
|
|
|
|
create({}),
|
|
|
|
),
|
2019-11-27 14:33:32 +05:30
|
|
|
'to throw',
|
|
|
|
'Popup is required',
|
|
|
|
);
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#destroy', () => {
|
2020-01-18 02:07:52 +05:30
|
|
|
let state: State;
|
|
|
|
let popup: PopupConfig;
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = reducer(state, create({ Popup: FakeComponent }));
|
2020-01-18 02:07:52 +05:30
|
|
|
[popup] = state.popups;
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should remove popup', () => {
|
|
|
|
expect(state.popups, 'to have length', 1);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state = reducer(state, destroy(popup));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expect(state.popups, 'to have length', 0);
|
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should not remove something, that it should not', () => {
|
|
|
|
state = reducer(
|
|
|
|
state,
|
|
|
|
create({
|
|
|
|
Popup: FakeComponent,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state = reducer(state, destroy(popup));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expect(state.popups, 'to have length', 1);
|
|
|
|
expect(state.popups[0], 'not to be', popup);
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|