-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(date-picker): class to function component & write tests
- Loading branch information
Luckened
committed
Oct 14, 2020
1 parent
ede530c
commit 5e4ee42
Showing
3 changed files
with
179 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from '../../test/utils'; | ||
import DatePicker from './DatePicker'; | ||
|
||
describe('<DatePicker />', () => { | ||
it('should call onAccept correctly', () => { | ||
const handleAccept = jest.fn(); | ||
|
||
const { getByTestId } = renderWithTheme( | ||
<DatePicker onAccept={handleAccept} /> | ||
); | ||
|
||
const okButton = getByTestId('ok'); | ||
okButton.click(); | ||
expect(handleAccept).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call onCancel correctly', () => { | ||
const handleCancel = jest.fn(); | ||
|
||
const { getByTestId } = renderWithTheme( | ||
<DatePicker onCancel={handleCancel} /> | ||
); | ||
|
||
const cancelButton = getByTestId('cancel'); | ||
cancelButton.click(); | ||
expect(handleCancel).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,29 +1,30 @@ | ||
// 猸曪笍 DON'T SHOW DATEPICKER BEFORE IT'S FINISHED AND TESTED 猸曪笍 | ||
import React from 'react'; | ||
import DatePicker from './DatePicker'; | ||
|
||
// import React from 'react'; | ||
// import { DatePicker } from 'react95'; | ||
export default { | ||
title: 'DatePicker', | ||
component: DatePicker, | ||
decorators: [ | ||
story => ( | ||
<div | ||
style={{ | ||
padding: '5rem', | ||
background: 'teal' | ||
}} | ||
> | ||
{story()} | ||
</div> | ||
) | ||
] | ||
}; | ||
|
||
// export default { | ||
// title: 'DatePicker', | ||
// component: DatePicker, | ||
// decorators: [ | ||
// story => ( | ||
// <div | ||
// style={{ | ||
// padding: '5rem', | ||
// background: 'teal' | ||
// }} | ||
// > | ||
// {story()} | ||
// </div> | ||
// ) | ||
// ] | ||
// }; | ||
export const Default = () => ( | ||
<DatePicker | ||
onAccept={date => alert(`selected day is: ${date}`)} | ||
onCancel={() => alert('Cancel')} | ||
/> | ||
); | ||
|
||
// export const Default = () => ( | ||
// <DatePicker onAccept={date => console.log(date)} /> | ||
// ); | ||
|
||
// Default.story = { | ||
// name: 'default' | ||
// }; | ||
Default.story = { | ||
name: 'default' | ||
}; |