-
Notifications
You must be signed in to change notification settings - Fork 87
feat: datetimepicker validation improvements #8986
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
base: main
Are you sure you want to change the base?
Conversation
}; | ||
|
||
export const individualPickerUpdateTestSetup = (individualPickerTest) => { | ||
['date-picker', 'time-picker'].forEach((pickerType) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to simplify or restructure these tests somehow to improve readability? The deep nesting is making it tricky to understand the test cases. Maybe it would be easier to follow if the tests were more explicit, even if it would lead to some duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with that approach, but it seemed to bloat the tests by quite a lot. But I don't have a strong opinion, and if you think it is hard to read I can change it. Maybe we can keep ['date-picker', 'time-picker'].forEach(...)
and explicitly add tests for different states&updates. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can keep ['date-picker', 'time-picker'].forEach(...) and explicitly add tests for different states&updates
This might help! Let's give it a try. While this would increase bloat, it should simplify debugging in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separated the tests.
|
* empty => parsable | change | ||
* empty => unparsable | unparsable-change | ||
* parsable => empty | change | ||
* parsable => parsable | change | ||
* parsable => unparsable | change | ||
* unparsable => empty | unparsable-change | ||
* unparsable => parsable | change | ||
* unparsable => unparsable | unparsable-change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest including the incomplete
scenario in this list separately.
* @fires {Event} change - Fired when the user commits a value change. | ||
* @fires {Event} unparsable-change - Fired when the user commits an unparsable value change and there is no change event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @fires {Event} unparsable-change - Fired when the user commits an unparsable value change and there is no change event. | |
* @fires {Event} unparsable-change - Fired when the user commits an unparsable or incomplete value change and there is no change event. |
@@ -60,16 +60,395 @@ const fixtures = { | |||
expect(dateTimePicker.invalid).to.equal(false); | |||
}); | |||
|
|||
it('should validate on date-picker blur', () => { | |||
['date-picker', 'time-picker'].forEach((pickerType) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a value-commit.test.js
file and move all new tests there. Validation and change events are both part of the value commit flow, so testing them together in one place would make sense. Example:
web-components/packages/date-picker/test/value-commit.test.js
Lines 12 to 43 in 7c2b6e5
function expectNoValueCommit() { | |
expect(valueChangedSpy).to.be.not.called; | |
expect(validateSpy).to.be.not.called; | |
expect(changeSpy).to.be.not.called; | |
} | |
function expectValueCommit(value) { | |
expect(valueChangedSpy).to.be.calledOnce; | |
// TODO: Optimize the number of validation runs. | |
expect(validateSpy).to.be.called; | |
expect(validateSpy.firstCall).to.be.calledAfter(valueChangedSpy.firstCall); | |
expect(unparsableChangeSpy).to.be.not.called; | |
expect(changeSpy).to.be.calledOnce; | |
expect(changeSpy.firstCall).to.be.calledAfter(validateSpy.firstCall); | |
expect(datePicker.value).to.equal(value); | |
} | |
function expectUnparsableValueCommit() { | |
expect(valueChangedSpy).to.be.not.called; | |
// TODO: Optimize the number of validation runs. | |
expect(validateSpy).to.be.called; | |
expect(changeSpy).to.be.not.called; | |
expect(unparsableChangeSpy).to.be.calledOnce; | |
expect(unparsableChangeSpy).to.be.calledAfter(validateSpy); | |
} | |
function expectValidationOnly() { | |
expect(valueChangedSpy).to.be.not.called; | |
// TODO: Optimize the number of validation runs. | |
expect(validateSpy).to.be.called; | |
expect(changeSpy).to.be.not.called; | |
} |
this.__committedUnparsableValue = this.__unparsableValue; | ||
} | ||
|
||
get __hasPendingValueChange() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get __hasPendingValueChange() { | |
/** @private */ | |
get __hasPendingValueChange() { |
@@ -315,12 +316,37 @@ export const DateTimePickerMixin = (superClass) => | |||
return [this.__datePicker, this.__timePicker]; | |||
} | |||
|
|||
get __filledPickers() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get __filledPickers() { | |
/** @private */ | |
get __filledPickers() { |
I think that is my misunderstanding rather than an implementation error. My understanding was that the validation should not run when the component is blurred with no change to the input even if it is required. |
Description
unparsable-change
event for the web component.min
and/ormax
DateTimePicker
is still being edited, the validation behaves the same for Enter, outside click, and blur.Based on the prototype implementation.
Part of #6697.
Type of change
Checklist