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

Improve onError validation #1730

Merged
merged 27 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5563142
Introduce reason-based validation
dmtrKovalenko Apr 30, 2020
70b66d4
Remove dead validation code
dmtrKovalenko Apr 30, 2020
e9a0687
Implement new validation for TimePicker and DateTimePicker
dmtrKovalenko Apr 30, 2020
4f2207f
Remove redux form docs example
dmtrKovalenko Apr 30, 2020
868358a
Add Formik with validation schema example
dmtrKovalenko Apr 30, 2020
679ea8d
More tests
dmtrKovalenko Apr 30, 2020
a501984
TimePicker validation tests
dmtrKovalenko Apr 30, 2020
a1a6b42
Move parsing min/max date up to the root component
dmtrKovalenko May 1, 2020
5ca8ef2
Use touched state in the formik example
dmtrKovalenko May 1, 2020
3af9888
Remove console.logs
dmtrKovalenko May 1, 2020
71981e0
Merge conflicts
dmtrKovalenko May 1, 2020
cbe5fc4
Fix lint and build errors
dmtrKovalenko May 1, 2020
3eddd8b
Remove visual regression flakiness with time validation
dmtrKovalenko May 1, 2020
f21609c
Remove emptyInputText
dmtrKovalenko May 1, 2020
754a95b
Fix validation tests
dmtrKovalenko May 1, 2020
58f12c7
Commit .size-snapshot
dmtrKovalenko May 1, 2020
e349496
Implement validation for DateRangePicker.tsx
dmtrKovalenko May 1, 2020
5bce1e4
Add DateRange validation tests
dmtrKovalenko May 1, 2020
e4166a7
Fix linter
dmtrKovalenko May 1, 2020
860d6f5
Fix broken design of date rangepicker input parsing
dmtrKovalenko May 5, 2020
c73d4e7
Merge conflicts
dmtrKovalenko May 5, 2020
8dedc04
Remove <Code> from formik examples
dmtrKovalenko May 5, 2020
66eb022
Update yarn.lock
dmtrKovalenko May 5, 2020
af381ef
Update docs/pages/guides/FormikOurValidation.example.tsx
dmtrKovalenko May 5, 2020
1201eef
Update docs/pages/guides/FormikOurValidation.example.tsx
dmtrKovalenko May 5, 2020
79cea16
Update docs/pages/guides/FormikOurValidation.example.tsx
dmtrKovalenko May 5, 2020
806b63c
Update new forms example to be more consolidated with @materail-ui/core
dmtrKovalenko May 6, 2020
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
Prev Previous commit
Next Next commit
TimePicker validation tests
  • Loading branch information
dmtrKovalenko committed Apr 30, 2020
commit a501984df7b03784273fe312329af6447fb0c3cc
1 change: 1 addition & 0 deletions docs/pages/demo/timepicker/BasicTimePicker.example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function BasicTimePicker() {
renderInput={props => <TextField {...props} />}
label="12 hours"
value={selectedDate}
onError={console.log}
onChange={date => handleDateChange(date)}
/>

Expand Down
30 changes: 30 additions & 0 deletions lib/src/__tests__/Validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isWeekend } from 'date-fns';
import { MaterialUiPickersDate } from '../typings/date';
import { DesktopDatePicker } from '../DatePicker/DatePicker';
import { mountPickerWithState, utilsToUse } from './test-utils';
import { TimePickerProps, DesktopTimePicker } from '../TimePicker/TimePicker';

const disableWeekends = (date: MaterialUiPickersDate) => {
return isWeekend(utilsToUse.toJsDate(date));
Expand Down Expand Up @@ -55,3 +56,32 @@ describe('DatePicker validation', () => {
expect(onErrorMock).toHaveBeenCalledWith(null, expect.anything());
});
});

describe('TimePicker validation', () => {
const createTime = (time: string) => new Date('01/01/2000 ' + time);
const shouldDisableTime: TimePickerProps['shouldDisableTime'] = (value, _clockType) => {
return value === 10;
};

test.each`
props | input | expectedError
${{}} | ${'invalidText'} | ${'invalidDate'}
${{ minTime: createTime('08:00') }} | ${'03:00'} | ${'minTime'}
${{ maxTime: createTime('08:00') }} | ${'12:00'} | ${'maxTime'}
${{ shouldDisableTime }} | ${'10:00'} | ${'shouldDisableTime-hours'}
${{ shouldDisableTime }} | ${'00:10'} | ${'shouldDisableTime-minutes'}
`('TimePicker should dispatch onError $expectedError', ({ props, input, expectedError }) => {
const onErrorMock = jest.fn();
const component = mountPickerWithState(utilsToUse.date(), stateProps => (
<DesktopTimePicker ampm={false} {...stateProps} {...props} onError={onErrorMock} />
));

component.find('input').simulate('change', {
target: {
value: input,
},
});

expect(onErrorMock).toBeCalledWith(expectedError, expect.anything());
});
});