-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80e7a01
commit 506023c
Showing
7 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { generateNotification } from './index' | ||
import React from 'react' | ||
import Button, { ButtonProps } from '../Button' | ||
import { Meta, Story } from '@storybook/react/types-6-0' | ||
|
||
export default { | ||
argTypes: { | ||
children: { control: 'text' } | ||
}, | ||
title: 'Notifications' | ||
} as Meta | ||
|
||
const Template: Story<ButtonProps> = args => ( | ||
<Button {...args}>{args.children}</Button> | ||
) | ||
|
||
export const Error = Template.bind({}) | ||
Error.args = { | ||
children: 'Error', | ||
onClick: () => | ||
generateNotification('error', 'Message for error notification') | ||
} | ||
|
||
export const Info = Template.bind({}) | ||
Info.args = { | ||
children: 'Info', | ||
onClick: () => generateNotification('info', 'Message for info notification') | ||
} | ||
|
||
export const Success = Template.bind({}) | ||
Success.args = { | ||
children: 'Success', | ||
onClick: () => | ||
generateNotification('success', 'Message for success notification') | ||
} | ||
|
||
export const Warning = Template.bind({}) | ||
Warning.args = { | ||
children: 'Warning', | ||
onClick: () => | ||
generateNotification('warning', 'Message for warning notification') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { generateNotification } from './index' | ||
import { notification } from 'antd' | ||
|
||
describe('Notification', () => { | ||
it('should render a notification with the message content', () => { | ||
generateNotification('error', 'something') | ||
|
||
const notification = document.querySelectorAll('.ant-notification')[0] | ||
|
||
expect(notification).toBeDefined() | ||
expect(notification.textContent).toBe('something') | ||
}) | ||
|
||
it('should use the notification api provided by AntD', () => { | ||
jest.spyOn(notification, 'error') | ||
|
||
const mockErrorNotification = 'Fake Error Notification' | ||
generateNotification('error', mockErrorNotification) | ||
|
||
expect(notification.error).toHaveBeenCalledWith({ | ||
message: mockErrorNotification | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'antd/lib/notification/style/index.css' | ||
import { IconType } from 'antd/lib/notification' | ||
import { notification } from 'antd' | ||
|
||
export const generateNotification = (type: IconType, message: string): void => | ||
notification[type]({ | ||
message | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters