Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(notification): refactor component to use hooks #5072

Merged
merged 5 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 23 additions & 67 deletions packages/react/src/components/Notification/Notification-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('ToastNotification', () => {
});
describe('events and state', () => {
it('initial open state set to true', () => {
const mountedToast = mount(
const wrapper = mount(
<ToastNotification
kind="error"
title="this is a title"
Expand All @@ -158,11 +158,11 @@ describe('ToastNotification', () => {
/>
);

expect(mountedToast.state().open).toBe(true);
expect(wrapper.children().length > 0).toBe(true);
});

it('sets open state to false when close button is clicked', () => {
const mountedToast = mount(
const wrapper = mount(
<ToastNotification
kind="error"
title="this is a title"
Expand All @@ -171,12 +171,12 @@ describe('ToastNotification', () => {
/>
);

mountedToast.find('button').simulate('click');
expect(mountedToast.state().open).toEqual(false);
wrapper.find('button').simulate('click');
expect(wrapper.children().length).toBe(0);
});

it('renders null when open state is false', () => {
const mountedToast = mount(
const wrapper = mount(
<ToastNotification
kind="error"
title="this is a title"
Expand All @@ -185,8 +185,8 @@ describe('ToastNotification', () => {
/>
);

mountedToast.setState({ open: false });
expect(mountedToast.html()).toBeNull();
wrapper.find('button').simulate('click');
expect(wrapper.html()).toBeNull();
});
});
});
Expand Down Expand Up @@ -261,88 +261,44 @@ describe('InlineNotification', () => {

describe('events and state', () => {
it('initial open state set to true', () => {
const mountedInline = mount(
const wrapper = mount(
<InlineNotification
title="this is a title"
subtitle="this is a subtitle"
kind="error"
/>
);

expect(mountedInline.state().open).toBe(true);
expect(wrapper.children().length > 0).toBe(true);
});

it('sets open state to false when close button is clicked', () => {
const mountedInline = mount(<InlineNotification {...props} />);
const wrapper = mount(
<InlineNotification
kind="success"
title="title"
subtitle="subtitle"
iconDescription="description"
/>
);

mountedInline.find('button').simulate('click');
expect(mountedInline.state().open).toEqual(false);
wrapper.find('button').simulate('click');
expect(wrapper.children().length).toBe(0);
});

it('renders null when open state is false', () => {
const mountedInline = mount(
const wrapper = mount(
<InlineNotification
title="this is a title"
subtitle="this is a subtitle"
kind="error"
/>
);

mountedInline.setState({ open: false });
expect(mountedInline.html()).toBeNull();
wrapper.find('button').simulate('click');
expect(wrapper.html()).toBeNull();
});
});
});

// Deprecated

const props = {
kind: 'success',
title: 'title',
subtitle: 'subtitle',
iconDescription: 'description',
};

describe('events and state', () => {
it('initial open state set to true', () => {
const mountedToast = mount(
<ToastNotification {...props} caption="caption" />
);
const mountedInline = mount(<InlineNotification {...props} />);

expect(mountedToast.state().open).toBe(true);
expect(mountedInline.state().open).toBe(true);
});

it('sets open state to false when close button is clicked', () => {
const mountedToast = mount(
<ToastNotification {...props} caption="caption" />
);
const mountedInline = mount(<InlineNotification {...props} />);

mountedToast.find('button').simulate('click');
mountedInline.find('button').simulate('click');
expect(mountedToast.state().open).toEqual(false);
expect(mountedInline.state().open).toEqual(false);
});

it('close button is not shown if hideCloseButton prop set', () => {
const mountedToast = mount(
<ToastNotification {...props} hideCloseButton={true} />
);

expect(mountedToast.find('button')).toHaveLength(0);
});

it('renders null when open state is false', () => {
const mountedToast = mount(
<ToastNotification {...props} caption="caption" />
);
const mountedInline = mount(<InlineNotification {...props} />);

mountedToast.setState({ open: false });
mountedInline.setState({ open: false });
expect(mountedToast.html()).toBeNull();
expect(mountedInline.html()).toBeNull();
});
});
Loading