2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
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
|
|
|
|
2018-05-10 13:37:33 +02:00
|
|
|
describe('SendHeader Component', function () {
|
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
|
|
|
|
|
|
|
before(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.spy(SendHeader.prototype, 'onClose');
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
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
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
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
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('onClose', function () {
|
|
|
|
it('should call clearSend', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(propsMethodSpies.clearSend.callCount, 0);
|
|
|
|
wrapper.instance().onClose();
|
|
|
|
assert.strictEqual(propsMethodSpies.clearSend.callCount, 1);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call history.push', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(historySpies.push.callCount, 0);
|
|
|
|
wrapper.instance().onClose();
|
|
|
|
assert.strictEqual(historySpies.push.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
historySpies.push.getCall(0).args[0],
|
|
|
|
'mostRecentOverviewPage',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
2020-07-20 19:02:49 +02:00
|
|
|
it('should render a PageContainerHeader component', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(wrapper.find(PageContainerHeader).length, 1);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass the correct props to PageContainerHeader', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { onClose, title } = wrapper.find(PageContainerHeader).props();
|
|
|
|
assert.strictEqual(title, 'mockTitleKey');
|
|
|
|
assert.strictEqual(SendHeader.prototype.onClose.callCount, 0);
|
|
|
|
onClose();
|
|
|
|
assert.strictEqual(SendHeader.prototype.onClose.callCount, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|