From bb7bddb7aa6d56204e7bcde52441fd299c553cc3 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 20 Dec 2017 19:39:46 -0700 Subject: [PATCH] toast component jest tests (#215) * toast jest tests * using test style guide this time * test each color value --- .../global_toast_list.test.js.snap | 6 +- .../toast/__snapshots__/toast.test.js.snap | 101 +++++++++++++++++- .../toast/global_toast_list.test.js | 4 +- src/components/toast/toast.js | 2 + src/components/toast/toast.test.js | 56 +++++++++- 5 files changed, 162 insertions(+), 7 deletions(-) diff --git a/src/components/toast/__snapshots__/global_toast_list.test.js.snap b/src/components/toast/__snapshots__/global_toast_list.test.js.snap index 447a1162053..812fd7b0fc9 100644 --- a/src/components/toast/__snapshots__/global_toast_list.test.js.snap +++ b/src/components/toast/__snapshots__/global_toast_list.test.js.snap @@ -5,5 +5,9 @@ exports[`EuiGlobalToastList is rendered 1`] = ` aria-label="aria-label" class="euiGlobalToastList testClass1 testClass2" data-test-subj="test subject string" -/> +> +
+ hi +
+ `; diff --git a/src/components/toast/__snapshots__/toast.test.js.snap b/src/components/toast/__snapshots__/toast.test.js.snap index aa7bae612bd..18f05d0483d 100644 --- a/src/components/toast/__snapshots__/toast.test.js.snap +++ b/src/components/toast/__snapshots__/toast.test.js.snap @@ -1,5 +1,97 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`EuiToast Props color danger is rendered 1`] = ` +
+
+ +
+
+`; + +exports[`EuiToast Props color primary is rendered 1`] = ` +
+
+ +
+
+`; + +exports[`EuiToast Props color success is rendered 1`] = ` +
+
+ +
+
+`; + +exports[`EuiToast Props color warning is rendered 1`] = ` +
+
+ +
+
+`; + +exports[`EuiToast Props iconType is rendered 1`] = ` +
+
+
+
+`; + +exports[`EuiToast Props title is rendered 1`] = ` +
+
+ + toast title + +
+
+`; + exports[`EuiToast is rendered 1`] = `
+
+

+ Hi +

+
`; diff --git a/src/components/toast/global_toast_list.test.js b/src/components/toast/global_toast_list.test.js index d65854b5b64..0980bb37402 100644 --- a/src/components/toast/global_toast_list.test.js +++ b/src/components/toast/global_toast_list.test.js @@ -7,7 +7,9 @@ import { EuiGlobalToastList } from './global_toast_list'; describe('EuiGlobalToastList', () => { test('is rendered', () => { const component = render( - + +
hi
+
); expect(component) diff --git a/src/components/toast/toast.js b/src/components/toast/toast.js index 633677bc19d..90615cc5cb7 100644 --- a/src/components/toast/toast.js +++ b/src/components/toast/toast.js @@ -48,6 +48,7 @@ export const EuiToast = ({ title, color, iconType, onClose, children, className, className="euiToast__closeButton" aria-label="Dismiss toast" onClick={onClose} + data-test-subj="toastCloseButton" > { test('is rendered', () => { const component = render( - + +

Hi

+
); expect(component) .toMatchSnapshot(); }); + + describe('Props', () => { + describe('title', () => { + test('is rendered', () => { + const component = ; + expect(shallow(component)).toMatchSnapshot(); + }); + }); + + describe('color', () => { + COLORS.forEach(color => { + test(`${color} is rendered`, () => { + const component = ; + expect(shallow(component)).toMatchSnapshot(); + }); + }); + }); + + describe('iconType', () => { + test('is rendered', () => { + const component = ; + expect(shallow(component)).toMatchSnapshot(); + }); + }); + + describe('onClose', () => { + test('is called when the close button is clicked', () => { + const onCloseHandler = sinon.stub(); + + const component = shallow( + + ); + const closeButton = findTestSubject(component, 'toastCloseButton'); + closeButton.simulate('click'); + + sinon.assert.calledOnce(onCloseHandler); + }); + }); + }); });