2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
2021-03-16 22:00:08 +01:00
|
|
|
import PageContainerHeader from '../../../components/ui/page-container/page-container-header';
|
|
|
|
import SendHeader from './send-header.component';
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('SendHeader Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
clearSend: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 21:33:32 +01:00
|
|
|
const historySpies = {
|
|
|
|
push: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeAll(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.spy(SendHeader.prototype, 'onClose');
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<SendHeader
|
|
|
|
clearSend={propsMethodSpies.clearSend}
|
|
|
|
history={historySpies}
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
2019-12-03 17:35:44 +01:00
|
|
|
titleKey="mockTitleKey"
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{ context: { t: (str1, str2) => (str2 ? str1 + str2 : str1) } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.clearSend.resetHistory();
|
|
|
|
historySpies.push.resetHistory();
|
|
|
|
SendHeader.prototype.onClose.resetHistory();
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterAll(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('onClose', () => {
|
|
|
|
it('should call clearSend', () => {
|
|
|
|
expect(propsMethodSpies.clearSend.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().onClose();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.clearSend.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should call history.push', () => {
|
|
|
|
expect(historySpies.push.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().onClose();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
|
|
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'mostRecentOverviewPage',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a PageContainerHeader component', () => {
|
|
|
|
expect(wrapper.find(PageContainerHeader)).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct props to PageContainerHeader', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { onClose, title } = wrapper.find(PageContainerHeader).props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(title).toStrictEqual('mockTitleKey');
|
|
|
|
expect(SendHeader.prototype.onClose.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
onClose();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(SendHeader.prototype.onClose.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|