2016-07-30 16:14:43 +05:30
|
|
|
import expect from 'unexpected';
|
|
|
|
|
2016-05-01 23:20:55 +05:30
|
|
|
import reducer from 'components/ui/popup/reducer';
|
2016-05-11 10:56:44 +05:30
|
|
|
import {create, destroy} from 'components/ui/popup/actions';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
describe('popup/reducer', () => {
|
|
|
|
it('should have no popups by default', () => {
|
|
|
|
const actual = reducer(undefined, {});
|
|
|
|
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(actual.popups, 'to be an', 'array');
|
|
|
|
expect(actual.popups, 'to be empty');
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('#create', () => {
|
|
|
|
it('should create popup', () => {
|
2016-07-26 10:10:45 +05:30
|
|
|
const actual = reducer(undefined, create({
|
|
|
|
Popup: FakeComponent
|
|
|
|
}));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(actual.popups[0], 'to equal', {
|
2016-07-26 10:10:45 +05:30
|
|
|
Popup: FakeComponent
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-26 10:10:45 +05:30
|
|
|
it('should support shortcut popup creation', () => {
|
|
|
|
const actual = reducer(undefined, create(FakeComponent));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(actual.popups[0], 'to equal', {
|
2016-07-26 10:10:45 +05:30
|
|
|
Popup: FakeComponent
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-26 10:10:45 +05:30
|
|
|
it('should create multiple popups', () => {
|
|
|
|
let actual = reducer(undefined, create({
|
|
|
|
Popup: FakeComponent
|
|
|
|
}));
|
|
|
|
actual = reducer(actual, create({
|
|
|
|
Popup: FakeComponent
|
|
|
|
}));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(actual.popups[1], 'to equal', {
|
2016-07-26 10:10:45 +05:30
|
|
|
Popup: FakeComponent
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws when no type provided', () => {
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(() => reducer(undefined, create()), 'to throw', 'Popup is required');
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#destroy', () => {
|
|
|
|
let state;
|
|
|
|
let popup;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2016-05-11 10:56:44 +05:30
|
|
|
state = reducer(state, create(FakeComponent));
|
2016-05-01 23:20:55 +05:30
|
|
|
popup = state.popups[0];
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove popup', () => {
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(state.popups, 'to have length', 1);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
state = reducer(state, destroy(popup));
|
|
|
|
|
2016-07-30 16:14:43 +05:30
|
|
|
expect(state.popups, 'to have length', 0);
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not remove something, that it should not', () => {
|
2016-07-26 10:10:45 +05:30
|
|
|
state = reducer(state, create({
|
|
|
|
Popup: FakeComponent
|
|
|
|
}));
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
state = reducer(state, destroy(popup));
|
|
|
|
|
2016-07-30 16:14:43 +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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-05-11 10:56:44 +05:30
|
|
|
|
|
|
|
function FakeComponent() {}
|