diff --git a/src/actions/dialog.test.js b/src/actions/dialog.test.js index 4ce08ef3b..059f5b93c 100644 --- a/src/actions/dialog.test.js +++ b/src/actions/dialog.test.js @@ -1,6 +1,14 @@ import { expect } from 'chai'; import actionTypes from '../constants/actions'; -import { dialogDisplayed, dialogHidden } from './dialog'; +import { + dialogDisplayed, + alertDialogDisplayed, + successAlertDialogDisplayed, + errorAlertDialogDisplayed, + dialogHidden, +} from './dialog'; +import Alert from '../components/dialog/alert'; + describe('actions: dialog', () => { describe('dialogDisplayed', () => { @@ -18,6 +26,70 @@ describe('actions: dialog', () => { }); }); + describe('alertDialogDisplayed', () => { + it('should create an action to show alert dialog', () => { + const data = { + title: 'success', + text: 'some text', + }; + + const expectedAction = { + data: { + title: data.title, + type: undefined, + childComponent: Alert, + childComponentProps: { + text: data.text, + }, + }, + type: actionTypes.dialogDisplayed, + }; + expect(alertDialogDisplayed(data)).to.be.deep.equal(expectedAction); + }); + }); + + describe('successAlertDialogDisplayed', () => { + it('should create an action to show alert dialog', () => { + const data = { + text: 'some text', + }; + + const expectedAction = { + data: { + title: 'Success', + type: 'success', + childComponent: Alert, + childComponentProps: { + text: data.text, + }, + }, + type: actionTypes.dialogDisplayed, + }; + expect(successAlertDialogDisplayed(data)).to.be.deep.equal(expectedAction); + }); + }); + + describe('errorAlertDialogDisplayed', () => { + it('should create an action to show alert dialog', () => { + const data = { + text: 'some text', + }; + + const expectedAction = { + data: { + title: 'Error', + type: 'error', + childComponent: Alert, + childComponentProps: { + text: data.text, + }, + }, + type: actionTypes.dialogDisplayed, + }; + expect(errorAlertDialogDisplayed(data)).to.be.deep.equal(expectedAction); + }); + }); + describe('dialogHidden', () => { it('should create an action to hide dialog', () => { const expectedAction = { diff --git a/src/components/dialog/alert.test.js b/src/components/dialog/alert.test.js new file mode 100644 index 000000000..2037101f0 --- /dev/null +++ b/src/components/dialog/alert.test.js @@ -0,0 +1,34 @@ +import React from 'react'; +import chai, { expect } from 'chai'; +import { mount } from 'enzyme'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import chaiEnzyme from 'chai-enzyme'; +import Alert from './alert'; + +chai.use(sinonChai); +chai.use(chaiEnzyme()); // Note the invocation at the end + +describe('Alert', () => { + let wrapper; + let closeSpy; + const text = 'some random text'; + + beforeEach(() => { + closeSpy = sinon.spy(); + wrapper = mount(); + }); + + it('renders paragraph with props.text', () => { + expect(wrapper.find('p').text()).to.equal(text); + }); + + it('renders "Ok" Button', () => { + expect(wrapper.find('Button').text()).to.equal('Ok'); + }); + + it('renders "Ok" Button that calls props.closeDialog on click', () => { + wrapper.find('Button').simulate('click'); + expect(closeSpy).to.have.been.calledWith(); + }); +});