2018-05-07 14:03:20 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
2019-04-17 21:15:13 +02:00
|
|
|
import { DEFAULT_ROUTE } from '../../../../helpers/constants/routes'
|
2018-05-07 14:03:20 +02:00
|
|
|
import SendHeader from '../send-header.component.js'
|
2019-04-17 21:15:13 +02:00
|
|
|
import PageContainerHeader from '../../../../components/ui/page-container/page-container-header'
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2018-05-10 13:37:33 +02:00
|
|
|
describe('SendHeader Component', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
let wrapper
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
clearSend: sinon.spy(),
|
|
|
|
}
|
|
|
|
const historySpies = {
|
|
|
|
push: sinon.spy(),
|
|
|
|
}
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
sinon.spy(SendHeader.prototype, 'onClose')
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2019-12-03 17:35:44 +01:00
|
|
|
wrapper = shallow((
|
|
|
|
<SendHeader
|
|
|
|
clearSend={propsMethodSpies.clearSend}
|
|
|
|
history={historySpies}
|
|
|
|
titleKey="mockTitleKey"
|
|
|
|
/>
|
2019-12-03 17:53:13 +01:00
|
|
|
), { context: { t: (str1, str2) => (str2 ? str1 + str2 : str1) } })
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
propsMethodSpies.clearSend.resetHistory()
|
|
|
|
historySpies.push.resetHistory()
|
|
|
|
SendHeader.prototype.onClose.resetHistory()
|
|
|
|
})
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('onClose', function () {
|
|
|
|
it('should call clearSend', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(propsMethodSpies.clearSend.callCount, 0)
|
|
|
|
wrapper.instance().onClose()
|
|
|
|
assert.equal(propsMethodSpies.clearSend.callCount, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call history.push', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(historySpies.push.callCount, 0)
|
|
|
|
wrapper.instance().onClose()
|
|
|
|
assert.equal(historySpies.push.callCount, 1)
|
|
|
|
assert.equal(historySpies.push.getCall(0).args[0], DEFAULT_ROUTE)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render a PageContainerHeader compenent', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(wrapper.find(PageContainerHeader).length, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass the correct props to PageContainerHeader', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
const {
|
|
|
|
onClose,
|
|
|
|
title,
|
|
|
|
} = wrapper.find(PageContainerHeader).props()
|
2018-05-24 21:57:33 +02:00
|
|
|
assert.equal(title, 'mockTitleKey')
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(SendHeader.prototype.onClose.callCount, 0)
|
|
|
|
onClose()
|
|
|
|
assert.equal(SendHeader.prototype.onClose.callCount, 1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|