2021-02-04 19:15:23 +01:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import React from 'react';
|
2021-03-16 22:00:08 +01:00
|
|
|
import withModalProps from './with-modal-props';
|
2018-09-19 23:30:52 +02:00
|
|
|
|
|
|
|
const mockState = {
|
|
|
|
appState: {
|
|
|
|
modal: {
|
|
|
|
modalState: {
|
|
|
|
props: {
|
|
|
|
prop1: 'prop1',
|
|
|
|
prop2: 2,
|
|
|
|
prop3: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('withModalProps', () => {
|
|
|
|
it('should return a component wrapped with modal state props', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const TestComponent = () => <div className="test">Testing</div>;
|
|
|
|
const WrappedComponent = withModalProps(TestComponent);
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
const wrapper = mount(<WrappedComponent store={store} />);
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
const testComponent = wrapper.find(TestComponent).at(0);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(testComponent).toHaveLength(1);
|
|
|
|
expect(testComponent.find('.test').text()).toStrictEqual('Testing');
|
2021-02-04 19:15:23 +01:00
|
|
|
const testComponentProps = testComponent.props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(testComponentProps.prop1).toStrictEqual('prop1');
|
|
|
|
expect(testComponentProps.prop2).toStrictEqual(2);
|
|
|
|
expect(testComponentProps.prop3).toStrictEqual(true);
|
|
|
|
expect(typeof testComponentProps.hideModal).toStrictEqual('function');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|