|
1 |
| -import React from 'react'; |
2 | 1 | import { expect } from 'chai';
|
3 |
| -import { shallow } from 'enzyme'; |
| 2 | +import { mount, shallow } from 'enzyme'; |
| 3 | +import React from 'react'; |
| 4 | +import sinon from 'sinon'; |
4 | 5 | import { ModalStatusMessage } from '../';
|
5 | 6 |
|
6 | 7 | describe('<ModalStatusMessage />', () => {
|
7 |
| - const component = shallow( |
8 |
| - <ModalStatusMessage icon="error" message="bad things" type="error" /> |
9 |
| - ); |
10 |
| - const iconColumn = component.find('.col-md-1'); |
11 |
| - const messageColumn = component.find('.col-md-11'); |
12 |
| - |
13 |
| - it('sets the base class', () => { |
14 |
| - expect(component.hasClass('modal-status-error')).to.equal(true); |
15 |
| - }); |
16 |
| - |
17 |
| - it('sets the child div', () => { |
18 |
| - expect(component.find('.row')).to.have.length(1); |
19 |
| - }); |
20 |
| - |
21 |
| - it('sets the icon column', () => { |
22 |
| - expect(iconColumn).to.have.length(1); |
| 8 | + context('when just showing some content', () => { |
| 9 | + const component = shallow( |
| 10 | + <ModalStatusMessage icon="error" message="bad things" type="error" /> |
| 11 | + ); |
| 12 | + const iconColumn = component.find('.col-md-1'); |
| 13 | + const messageColumn = component.find('.col-md-11'); |
| 14 | + |
| 15 | + it('sets the base class', () => { |
| 16 | + expect(component.hasClass('modal-status-error')).to.equal(true); |
| 17 | + }); |
| 18 | + |
| 19 | + it('sets the child div', () => { |
| 20 | + expect(component.find('.row')).to.have.length(1); |
| 21 | + }); |
| 22 | + |
| 23 | + it('sets the icon column', () => { |
| 24 | + expect(iconColumn).to.have.length(1); |
| 25 | + }); |
| 26 | + |
| 27 | + it('sets the message column', () => { |
| 28 | + expect(messageColumn).to.have.length(1); |
| 29 | + }); |
| 30 | + |
| 31 | + it('sets the icon', () => { |
| 32 | + expect(iconColumn.find('.fa-error')).to.have.length(1); |
| 33 | + }); |
| 34 | + |
| 35 | + it('sets the message paragraph', () => { |
| 36 | + expect(messageColumn.find('.modal-status-error-message')).to.have.length(1); |
| 37 | + }); |
| 38 | + |
| 39 | + it('sets the message text', () => { |
| 40 | + expect(messageColumn.find('.modal-status-error-message').text()).to.equal('bad things'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('does not show an interactible icon without click handler', () => { |
| 44 | + expect(component.find('.modal-status-error-icon-interactible')).not.to.be.present; |
| 45 | + }); |
23 | 46 | });
|
24 | 47 |
|
25 |
| - it('sets the message column', () => { |
26 |
| - expect(messageColumn).to.have.length(1); |
27 |
| - }); |
| 48 | + context('when providing an icon clicked handler', () => { |
| 49 | + const clickSpy = sinon.spy(); |
| 50 | + const component = mount( |
| 51 | + <ModalStatusMessage icon="times" message="An Error Occurred..." type="error" onIconClickHandler={clickSpy} /> |
| 52 | + ); |
28 | 53 |
|
29 |
| - it('sets the icon', () => { |
30 |
| - expect(iconColumn.find('.fa-error')).to.have.length(1); |
31 |
| - }); |
32 |
| - |
33 |
| - it('sets the message paragraph', () => { |
34 |
| - expect(messageColumn.find('.modal-status-error-message')).to.have.length(1); |
35 |
| - }); |
| 54 | + it('is called when clicked', () => { |
| 55 | + component.find('.modal-status-error-icon-interactible').first().simulate('click'); |
36 | 56 |
|
37 |
| - it('sets the message text', () => { |
38 |
| - expect(messageColumn.find('.modal-status-error-message').text()).to.equal('bad things'); |
| 57 | + expect(clickSpy.called).to.be.true; |
| 58 | + }); |
39 | 59 | });
|
40 | 60 | });
|
0 commit comments