mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Simplified popup component api
This commit is contained in:
@@ -9,16 +9,13 @@ function DummyPopup() {}
|
||||
describe('<PopupStack />', () => {
|
||||
it('renders all popup components', () => {
|
||||
const props = {
|
||||
pool: {
|
||||
dummy: DummyPopup
|
||||
},
|
||||
destroy: () => {},
|
||||
popups: [
|
||||
{
|
||||
type: 'dummy'
|
||||
type: DummyPopup
|
||||
},
|
||||
{
|
||||
type: 'dummy'
|
||||
type: DummyPopup
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -33,13 +30,10 @@ describe('<PopupStack />', () => {
|
||||
};
|
||||
|
||||
const props = {
|
||||
pool: {
|
||||
dummy: DummyPopup
|
||||
},
|
||||
destroy: () => {},
|
||||
popups: [
|
||||
{
|
||||
type: 'dummy',
|
||||
type: DummyPopup,
|
||||
props: expectedProps
|
||||
}
|
||||
]
|
||||
@@ -55,13 +49,10 @@ describe('<PopupStack />', () => {
|
||||
};
|
||||
|
||||
const props = {
|
||||
pool: {
|
||||
dummy: DummyPopup
|
||||
},
|
||||
destroy: () => {},
|
||||
popups: [
|
||||
{
|
||||
type: 'dummy',
|
||||
type: DummyPopup,
|
||||
props: (props) => {
|
||||
expect(props).to.have.property('onClose');
|
||||
|
||||
@@ -77,15 +68,12 @@ describe('<PopupStack />', () => {
|
||||
|
||||
it('should hide popup, when onClose called', () => {
|
||||
const props = {
|
||||
pool: {
|
||||
dummy: DummyPopup
|
||||
},
|
||||
popups: [
|
||||
{
|
||||
type: 'dummy'
|
||||
type: DummyPopup
|
||||
},
|
||||
{
|
||||
type: 'dummy'
|
||||
type: DummyPopup
|
||||
}
|
||||
],
|
||||
destroy: sinon.stub()
|
||||
@@ -97,22 +85,4 @@ describe('<PopupStack />', () => {
|
||||
sinon.assert.calledOnce(props.destroy);
|
||||
sinon.assert.calledWith(props.destroy, sinon.match.same(props.popups[1]));
|
||||
});
|
||||
|
||||
it('throws when there is no popup component in pool', () => {
|
||||
const props = {
|
||||
pool: {
|
||||
dummy: DummyPopup
|
||||
},
|
||||
destroy: () => {},
|
||||
popups: [
|
||||
{
|
||||
type: 'notExists'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
shallow(<PopupStack {...props} />);
|
||||
}).to.throw('Unknown popup type: notExists');
|
||||
});
|
||||
});
|
||||
|
@@ -1,14 +1,7 @@
|
||||
import reducer from 'components/ui/popup/reducer';
|
||||
import {create, destroy, register} from 'components/ui/popup/actions';
|
||||
import {create, destroy} from 'components/ui/popup/actions';
|
||||
|
||||
describe('popup/reducer', () => {
|
||||
it('should have empty pool by default', () => {
|
||||
const actual = reducer(undefined, {});
|
||||
|
||||
expect(actual.pool).to.be.an('object');
|
||||
expect(actual.pool).to.be.empty;
|
||||
});
|
||||
|
||||
it('should have no popups by default', () => {
|
||||
const actual = reducer(undefined, {});
|
||||
|
||||
@@ -16,45 +9,32 @@ describe('popup/reducer', () => {
|
||||
expect(actual.popups).to.be.empty;
|
||||
});
|
||||
|
||||
describe('#register', () => {
|
||||
it('should add popup components into pool', () => {
|
||||
const actual = reducer(undefined, register('foo', function() {}));
|
||||
|
||||
expect(actual.pool.foo).to.be.a('function');
|
||||
});
|
||||
|
||||
it('throws when no type or component provided', () => {
|
||||
expect(() => reducer(undefined, register()), 'type').to.throw('Type and component are required');
|
||||
expect(() => reducer(undefined, register('foo')), 'component').to.throw('Type and component are required');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#create', () => {
|
||||
it('should create popup', () => {
|
||||
const actual = reducer(undefined, create('foo'));
|
||||
const actual = reducer(undefined, create(FakeComponent));
|
||||
|
||||
expect(actual.popups[0]).to.be.deep.equal({
|
||||
type: 'foo',
|
||||
type: FakeComponent,
|
||||
props: {}
|
||||
});
|
||||
});
|
||||
|
||||
it('should store props', () => {
|
||||
const expectedProps = {foo: 'bar'};
|
||||
const actual = reducer(undefined, create('foo', expectedProps));
|
||||
const actual = reducer(undefined, create(FakeComponent, expectedProps));
|
||||
|
||||
expect(actual.popups[0]).to.be.deep.equal({
|
||||
type: 'foo',
|
||||
type: FakeComponent,
|
||||
props: expectedProps
|
||||
});
|
||||
});
|
||||
|
||||
it('should not remove existed popups', () => {
|
||||
let actual = reducer(undefined, create('foo'));
|
||||
actual = reducer(actual, create('foo2'));
|
||||
let actual = reducer(undefined, create(FakeComponent));
|
||||
actual = reducer(actual, create(FakeComponent));
|
||||
|
||||
expect(actual.popups[1]).to.be.deep.equal({
|
||||
type: 'foo2',
|
||||
type: FakeComponent,
|
||||
props: {}
|
||||
});
|
||||
});
|
||||
@@ -69,8 +49,7 @@ describe('popup/reducer', () => {
|
||||
let popup;
|
||||
|
||||
beforeEach(() => {
|
||||
state = reducer(undefined, register('foo', () => {}));
|
||||
state = reducer(state, create('foo'));
|
||||
state = reducer(state, create(FakeComponent));
|
||||
popup = state.popups[0];
|
||||
});
|
||||
|
||||
@@ -96,3 +75,5 @@ describe('popup/reducer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function FakeComponent() {}
|
||||
|
Reference in New Issue
Block a user