-
Notifications
You must be signed in to change notification settings - Fork 670
T1334896 - DateBox — Value isn't reset after selecting a date and clearing the input with Backspace in Firefox #35144
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
568ad47
T1334896
Raushen bdb9c38
Fix test
Raushen c65a1ff
Fix duplicate change event on focus out in mask mode
Raushen 8de9926
Fix comments
Raushen 34145a8
Fix comment
Raushen 0aac914
DateBox: compare the focus-out text as a string instead of relying on…
EugeniyKiyashko 51b3b46
DateBox: cover typing the original date back and clearing a DateRange…
EugeniyKiyashko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/devextreme/js/__internal/ui/__tests__/__mock__/model/date_box.ts
This file contains hidden or 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,19 @@ | ||
| import DateBox from '@ts/ui/date_box/date_box'; | ||
|
|
||
| import { DropDownEditorModel } from './drop_down_editor'; | ||
|
|
||
| const CLASSES = { | ||
| calendarCell: 'dx-calendar-cell', | ||
| }; | ||
|
|
||
| export class DateBoxModel extends DropDownEditorModel { | ||
| public getInstance(): DateBox { | ||
| return DateBox.getInstance(this.root); | ||
| } | ||
|
|
||
| public getCalendarCells(): HTMLElement[] { | ||
| const overlayContent = this.getOverlay().getElement(); | ||
|
|
||
| return Array.from(overlayContent?.querySelectorAll<HTMLElement>(`.${CLASSES.calendarCell}`) ?? []); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/devextreme/js/__internal/ui/__tests__/__mock__/model/date_range_box.ts
This file contains hidden or 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 DateRangeBox from '@ts/ui/date_range_box/date_range_box'; | ||
|
|
||
| import { DateBoxModel } from './date_box'; | ||
| import { DropDownEditorModel } from './drop_down_editor'; | ||
|
|
||
| const CLASSES = { | ||
| startDateBox: 'dx-start-datebox', | ||
| endDateBox: 'dx-end-datebox', | ||
| calendarCell: 'dx-calendar-cell', | ||
| }; | ||
|
|
||
| export class DateRangeBoxModel extends DropDownEditorModel { | ||
| public getInstance(): DateRangeBox { | ||
| return DateRangeBox.getInstance(this.root); | ||
| } | ||
|
|
||
| public getStartDateBox(): DateBoxModel { | ||
| return new DateBoxModel(this.root.querySelector(`.${CLASSES.startDateBox}`) as HTMLElement); | ||
| } | ||
|
|
||
| public getEndDateBox(): DateBoxModel { | ||
| return new DateBoxModel(this.root.querySelector(`.${CLASSES.endDateBox}`) as HTMLElement); | ||
| } | ||
|
|
||
| public getCalendarCells(): HTMLElement[] { | ||
| const overlayContent = this.getOverlay().getElement(); | ||
|
|
||
| return Array.from(overlayContent?.querySelectorAll<HTMLElement>(`.${CLASSES.calendarCell}`) ?? []); | ||
| } | ||
| } |
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
packages/devextreme/js/__internal/ui/__tests__/__mock__/model/text_editor.ts
This file contains hidden or 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,33 @@ | ||
| import { BaseModel } from './base_model'; | ||
|
|
||
| const CLASSES = { | ||
| input: 'dx-texteditor-input', | ||
| }; | ||
|
|
||
| export class TextEditorModel extends BaseModel { | ||
| public getInputElement(): HTMLInputElement { | ||
| return this.root.querySelector(`.${CLASSES.input}`) as HTMLInputElement; | ||
| } | ||
|
|
||
| public setInputText(text: string): void { | ||
| const input = this.getInputElement(); | ||
|
|
||
| input.value = text; | ||
| input.dispatchEvent(new Event('input', { bubbles: true })); | ||
| } | ||
|
|
||
| public clearInput(): void { | ||
| this.setInputText(''); | ||
| } | ||
|
|
||
| public pressKey(key: string): void { | ||
| const input = this.getInputElement(); | ||
|
|
||
| input.dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true })); | ||
| input.dispatchEvent(new KeyboardEvent('keyup', { key, bubbles: true })); | ||
| } | ||
|
|
||
| public blurInput(): void { | ||
| this.getInputElement().dispatchEvent(new FocusEvent('focusout', { bubbles: true })); | ||
| } | ||
| } |
165 changes: 165 additions & 0 deletions
165
packages/devextreme/js/__internal/ui/date_box/__tests__/date_box.test.ts
This file contains hidden or 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,165 @@ | ||
| import { | ||
| afterEach, beforeAll, describe, expect, it, jest, | ||
| } from '@jest/globals'; | ||
| import fx from '@js/common/core/animation/fx'; | ||
| import type { Properties } from '@js/ui/date_box'; | ||
| import DateBox from '@js/ui/date_box'; | ||
| import { DateBoxModel } from '@ts/ui/__tests__/__mock__/model/date_box'; | ||
|
|
||
| const dateBoxes: DateBox[] = []; | ||
|
|
||
| const createDateBox = (options: Partial<Properties> = {}): DateBoxModel => { | ||
| const element = document.body.appendChild(document.createElement('div')); | ||
|
|
||
| const instance = new DateBox(element, { | ||
| type: 'date', | ||
| pickerType: 'calendar', | ||
| ...options, | ||
| }); | ||
|
|
||
| dateBoxes.push(instance); | ||
|
|
||
| return new DateBoxModel(element); | ||
| }; | ||
|
|
||
| describe('DateBox commits the input text on focus out when the browser fires no change event', () => { | ||
| beforeAll(() => { | ||
| fx.off = true; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| dateBoxes.forEach((instance) => instance.dispose()); | ||
| dateBoxes.length = 0; | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('resets the value when the input is cleared after a calendar pick (T1334896)', () => { | ||
| const dateBox = createDateBox(); | ||
| const input = dateBox.getInputElement(); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
| expect(input.value).not.toBe(''); | ||
|
|
||
| dateBox.clearInput(); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toBeNull(); | ||
| expect(input.value).toBe(''); | ||
| }); | ||
|
|
||
| it('resets the value in mask mode when the input is cleared after a calendar pick (T1334896)', () => { | ||
| const dateBox = createDateBox({ useMaskBehavior: true }); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
|
|
||
| dateBox.clearInput(); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toBeNull(); | ||
| }); | ||
|
|
||
| it('commits the original date typed back after a calendar pick (T1334896)', () => { | ||
| const initialValue = new Date(2026, 8, 1); | ||
| const dateBox = createDateBox({ value: initialValue }); | ||
| const initialText = dateBox.getInputElement().value; | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[10].click(); | ||
| expect(dateBox.getInstance().option('value')).not.toEqual(initialValue); | ||
|
|
||
| dateBox.setInputText(initialText); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toEqual(initialValue); | ||
| }); | ||
|
|
||
| it('commits the text once when the browser does fire the change event (T1334896)', () => { | ||
| const onValueChanged = jest.fn(); | ||
| const dateBox = createDateBox({ onValueChanged }); | ||
| const input = dateBox.getInputElement(); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
| onValueChanged.mockClear(); | ||
|
|
||
| dateBox.clearInput(); | ||
| input.dispatchEvent(new Event('change', { bubbles: true })); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toBeNull(); | ||
| expect(onValueChanged).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not validate the same text again on focus out (T1334896)', () => { | ||
| const onOptionChanged = jest.fn<(e: { name: string }) => void>(); | ||
| const dateBox = createDateBox({ onOptionChanged }); | ||
| const input = dateBox.getInputElement(); | ||
|
|
||
| input.value = 'not a date'; | ||
| input.dispatchEvent(new Event('input', { bubbles: true })); | ||
| input.dispatchEvent(new Event('change', { bubbles: true })); | ||
|
|
||
| const validationChangesAfterChange = onOptionChanged.mock.calls | ||
| .filter(([{ name }]) => name === 'validationError').length; | ||
|
|
||
| dateBox.blurInput(); | ||
|
|
||
| const validationChangesAfterBlur = onOptionChanged.mock.calls | ||
| .filter(([{ name }]) => name === 'validationError').length; | ||
|
|
||
| expect(dateBox.getInstance().option('isValid')).toBe(false); | ||
| expect(validationChangesAfterBlur).toBe(validationChangesAfterChange); | ||
| }); | ||
|
|
||
| it('fires the change once on focus out in mask mode when the typed date is out of range (T1334896)', () => { | ||
| const onChange = jest.fn(); | ||
| const dateBox = createDateBox({ | ||
| useMaskBehavior: true, | ||
| value: new Date(2026, 8, 9), | ||
| max: new Date(2026, 8, 10), | ||
| onChange, | ||
| }); | ||
|
|
||
| dateBox.pressKey('ArrowUp'); | ||
| dateBox.pressKey('ArrowUp'); | ||
| dateBox.pressKey('ArrowUp'); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('isValid')).toBe(false); | ||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('resets the value on a repeated clear after a calendar pick (T1334896)', () => { | ||
| const dateBox = createDateBox(); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
| dateBox.clearInput(); | ||
| dateBox.blurInput(); | ||
| expect(dateBox.getInstance().option('value')).toBeNull(); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
| expect(dateBox.getInstance().option('value')).not.toBeNull(); | ||
|
|
||
| dateBox.clearInput(); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toBeNull(); | ||
| }); | ||
|
|
||
| it('keeps the value when valueChangeEvent excludes change (T1334896)', () => { | ||
| const dateBox = createDateBox({ valueChangeEvent: 'paste' }); | ||
|
|
||
| dateBox.open(); | ||
| dateBox.getCalendarCells()[0].click(); | ||
| const pickedValue = dateBox.getInstance().option('value'); | ||
|
|
||
| dateBox.clearInput(); | ||
| dateBox.blurInput(); | ||
|
|
||
| expect(dateBox.getInstance().option('value')).toEqual(pickedValue); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
46 changes: 46 additions & 0 deletions
46
packages/devextreme/js/__internal/ui/date_range_box/__tests__/date_range_box.test.ts
This file contains hidden or 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,46 @@ | ||
| import { | ||
| afterEach, beforeAll, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import fx from '@js/common/core/animation/fx'; | ||
| import type { Properties } from '@js/ui/date_range_box'; | ||
| import DateRangeBox from '@js/ui/date_range_box'; | ||
| import { DateRangeBoxModel } from '@ts/ui/__tests__/__mock__/model/date_range_box'; | ||
|
|
||
| const dateRangeBoxes: DateRangeBox[] = []; | ||
|
|
||
| const createDateRangeBox = (options: Partial<Properties> = {}): DateRangeBoxModel => { | ||
| const element = document.body.appendChild(document.createElement('div')); | ||
|
|
||
| const instance = new DateRangeBox(element, options); | ||
|
|
||
| dateRangeBoxes.push(instance); | ||
|
|
||
| return new DateRangeBoxModel(element); | ||
| }; | ||
|
|
||
| describe('DateRangeBox commits the input text on focus out when the browser fires no change event', () => { | ||
| beforeAll(() => { | ||
| fx.off = true; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| dateRangeBoxes.forEach((instance) => instance.dispose()); | ||
| dateRangeBoxes.length = 0; | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('resets the start date when the start input is cleared after a calendar pick (T1334896)', () => { | ||
| const dateRangeBox = createDateRangeBox(); | ||
| const startDateBox = dateRangeBox.getStartDateBox(); | ||
|
|
||
| dateRangeBox.open(); | ||
| dateRangeBox.getCalendarCells()[10].click(); | ||
| expect(dateRangeBox.getInstance().option('startDate')).not.toBeNull(); | ||
|
|
||
| startDateBox.clearInput(); | ||
| startDateBox.blurInput(); | ||
|
|
||
| expect(dateRangeBox.getInstance().option('startDate')).toBeNull(); | ||
| expect(startDateBox.getInputElement().value).toBe(''); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.