Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit 4600491

Browse files
authored
COMPASS-4409: Adds icon click handler to modal status message (#25)
1 parent f5bcf3b commit 4600491

File tree

2 files changed

+72
-35
lines changed

2 files changed

+72
-35
lines changed

packages/hadron-react-components/src/modal-status-message.jsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import React from 'react';
21
import PropTypes from 'prop-types';
2+
import React from 'react';
33
import { Panel } from 'react-bootstrap';
44

55
/**
66
* Component for the status message.
77
*/
88
class ModalStatusMessage extends React.Component {
9+
/**
10+
* Called when the icon of the message is clicked.
11+
* @param {Event} evt
12+
*/
13+
onIconClickHandler(evt) {
14+
evt.preventDefault();
15+
evt.stopPropagation();
16+
this.props.onIconClickHandler();
17+
}
918

1019
/**
1120
* Render the status message.
@@ -19,9 +28,16 @@ class ModalStatusMessage extends React.Component {
1928
<Panel className={classPrefix}>
2029
<div className="row">
2130
<div className="col-md-1">
22-
<i
23-
className={`fa fa-${this.props.icon} ${classPrefix}-icon`}
24-
aria-hidden="true"></i>
31+
{this.props.onIconClickHandler
32+
? (
33+
<i
34+
className={`fa fa-${this.props.icon} ${classPrefix}-icon ${classPrefix}-icon-interactible`}
35+
onClick={this.onIconClickHandler.bind(this)} />
36+
) : (
37+
<i
38+
className={`fa fa-${this.props.icon} ${classPrefix}-icon`}
39+
aria-hidden="true" />
40+
)}
2541
</div>
2642
<div className="col-md-11">
2743
<p
@@ -40,7 +56,8 @@ ModalStatusMessage.displayName = 'ModalStatusMessage';
4056
ModalStatusMessage.propTypes = {
4157
icon: PropTypes.string.isRequired,
4258
message: PropTypes.string.isRequired,
43-
type: PropTypes.string.isRequired
59+
type: PropTypes.string.isRequired,
60+
onIconClickHandler: PropTypes.func
4461
};
4562

4663
export default ModalStatusMessage;
Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,60 @@
1-
import React from 'react';
21
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';
45
import { ModalStatusMessage } from '../';
56

67
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+
});
2346
});
2447

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+
);
2853

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');
3656

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+
});
3959
});
4060
});

0 commit comments

Comments
 (0)