Skip to content

Commit cff494c

Browse files
Alessandra Davilajoshblack
authored andcommitted
refactor(notification): refactor component to use hooks (#5072)
1 parent 02ba91c commit cff494c

File tree

2 files changed

+483
-542
lines changed

2 files changed

+483
-542
lines changed

packages/react/src/components/Notification/Notification-test.js

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('ToastNotification', () => {
149149
});
150150
describe('events and state', () => {
151151
it('initial open state set to true', () => {
152-
const mountedToast = mount(
152+
const wrapper = mount(
153153
<ToastNotification
154154
kind="error"
155155
title="this is a title"
@@ -158,11 +158,11 @@ describe('ToastNotification', () => {
158158
/>
159159
);
160160

161-
expect(mountedToast.state().open).toBe(true);
161+
expect(wrapper.children().length > 0).toBe(true);
162162
});
163163

164164
it('sets open state to false when close button is clicked', () => {
165-
const mountedToast = mount(
165+
const wrapper = mount(
166166
<ToastNotification
167167
kind="error"
168168
title="this is a title"
@@ -171,12 +171,12 @@ describe('ToastNotification', () => {
171171
/>
172172
);
173173

174-
mountedToast.find('button').simulate('click');
175-
expect(mountedToast.state().open).toEqual(false);
174+
wrapper.find('button').simulate('click');
175+
expect(wrapper.children().length).toBe(0);
176176
});
177177

178178
it('renders null when open state is false', () => {
179-
const mountedToast = mount(
179+
const wrapper = mount(
180180
<ToastNotification
181181
kind="error"
182182
title="this is a title"
@@ -185,8 +185,8 @@ describe('ToastNotification', () => {
185185
/>
186186
);
187187

188-
mountedToast.setState({ open: false });
189-
expect(mountedToast.html()).toBeNull();
188+
wrapper.find('button').simulate('click');
189+
expect(wrapper.html()).toBeNull();
190190
});
191191
});
192192
});
@@ -261,88 +261,44 @@ describe('InlineNotification', () => {
261261

262262
describe('events and state', () => {
263263
it('initial open state set to true', () => {
264-
const mountedInline = mount(
264+
const wrapper = mount(
265265
<InlineNotification
266266
title="this is a title"
267267
subtitle="this is a subtitle"
268268
kind="error"
269269
/>
270270
);
271271

272-
expect(mountedInline.state().open).toBe(true);
272+
expect(wrapper.children().length > 0).toBe(true);
273273
});
274274

275275
it('sets open state to false when close button is clicked', () => {
276-
const mountedInline = mount(<InlineNotification {...props} />);
276+
const wrapper = mount(
277+
<InlineNotification
278+
kind="success"
279+
title="title"
280+
subtitle="subtitle"
281+
iconDescription="description"
282+
/>
283+
);
277284

278-
mountedInline.find('button').simulate('click');
279-
expect(mountedInline.state().open).toEqual(false);
285+
wrapper.find('button').simulate('click');
286+
expect(wrapper.children().length).toBe(0);
280287
});
281288

282289
it('renders null when open state is false', () => {
283-
const mountedInline = mount(
290+
const wrapper = mount(
284291
<InlineNotification
285292
title="this is a title"
286293
subtitle="this is a subtitle"
287294
kind="error"
288295
/>
289296
);
290297

291-
mountedInline.setState({ open: false });
292-
expect(mountedInline.html()).toBeNull();
298+
wrapper.find('button').simulate('click');
299+
expect(wrapper.html()).toBeNull();
293300
});
294301
});
295302
});
296303

297304
// Deprecated
298-
299-
const props = {
300-
kind: 'success',
301-
title: 'title',
302-
subtitle: 'subtitle',
303-
iconDescription: 'description',
304-
};
305-
306-
describe('events and state', () => {
307-
it('initial open state set to true', () => {
308-
const mountedToast = mount(
309-
<ToastNotification {...props} caption="caption" />
310-
);
311-
const mountedInline = mount(<InlineNotification {...props} />);
312-
313-
expect(mountedToast.state().open).toBe(true);
314-
expect(mountedInline.state().open).toBe(true);
315-
});
316-
317-
it('sets open state to false when close button is clicked', () => {
318-
const mountedToast = mount(
319-
<ToastNotification {...props} caption="caption" />
320-
);
321-
const mountedInline = mount(<InlineNotification {...props} />);
322-
323-
mountedToast.find('button').simulate('click');
324-
mountedInline.find('button').simulate('click');
325-
expect(mountedToast.state().open).toEqual(false);
326-
expect(mountedInline.state().open).toEqual(false);
327-
});
328-
329-
it('close button is not shown if hideCloseButton prop set', () => {
330-
const mountedToast = mount(
331-
<ToastNotification {...props} hideCloseButton={true} />
332-
);
333-
334-
expect(mountedToast.find('button')).toHaveLength(0);
335-
});
336-
337-
it('renders null when open state is false', () => {
338-
const mountedToast = mount(
339-
<ToastNotification {...props} caption="caption" />
340-
);
341-
const mountedInline = mount(<InlineNotification {...props} />);
342-
343-
mountedToast.setState({ open: false });
344-
mountedInline.setState({ open: false });
345-
expect(mountedToast.html()).toBeNull();
346-
expect(mountedInline.html()).toBeNull();
347-
});
348-
});

0 commit comments

Comments
 (0)