Skip to content

Commit ddaac3a

Browse files
Calendar: should not throw any errors if value is empty string (T1257679) (#28359)
Co-authored-by: EugeniyKiyashko <[email protected]>
1 parent 5e9032e commit ddaac3a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

packages/devextreme/js/__internal/ui/calendar/m_calendar.single.selection.strategy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ class CalendarSingleSelectionStrategy extends CalendarSelectionStrategy {
2727
}
2828

2929
getDefaultCurrentDate() {
30-
return this.dateOption('value');
30+
const date = this.dateOption('value');
31+
32+
if (date === '') {
33+
return new Date();
34+
}
35+
36+
return date;
3137
}
3238

3339
restoreValue(): void {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ QUnit.module('Navigator integration', {
325325
assert.equal($navigatorCaption.text(), 'July 2015', 'navigator caption is correct');
326326
});
327327

328+
QUnit.test('should not throw any errors if value on initialization is empty string (T1257679)', function(assert) {
329+
try {
330+
this.reinit({
331+
value: ''
332+
});
333+
} catch(e) {
334+
assert.ok(false, `error: ${e.message}`);
335+
} finally {
336+
assert.ok(true, 'there is no error');
337+
}
338+
});
339+
328340
QUnit.test('navigator caption should be changed during swipe', function(assert) {
329341
const $element = this.$element;
330342
const $navigatorCaption = this.$navigatorCaption;

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const LIST_CLASS = 'dx-list';
6969
const CLEAR_BUTTON_AREA_CLASS = 'dx-clear-button-area';
7070
const CALENDAR_CELL_CLASS = 'dx-calendar-cell';
7171
const CALENDAR_TODAY_BUTTON_CLASS = 'dx-calendar-today-button';
72+
const CALENDAR_CAPTION_BUTTON_CLASS = 'dx-calendar-caption-button';
73+
const CALENDAR_NAVIGATOR_NEXT_VIEW_CLASS = 'dx-calendar-navigator-next-view';
7274
const CALENDAR_NAVIGATOR_PREVIOUS_VIEW_CLASS = 'dx-calendar-navigator-previous-view';
7375
const DROPDOWNEDITOR_OVERLAY_CLASS = 'dx-dropdowneditor-overlay';
7476
const NUMBERBOX_CLASS = 'dx-numberbox';
@@ -6107,6 +6109,24 @@ QUnit.module('DateBox number and string value support', {
61076109
});
61086110
});
61096111

6112+
QUnit.test('should not throw any errors after clicking on the navigator caption button if the value is an empty string (T1257679)', function(assert) {
6113+
const dateBox = $('#dateBox').dxDateBox({
6114+
type: 'date',
6115+
pickerType: 'calendar',
6116+
value: '',
6117+
opened: true,
6118+
}).dxDateBox('instance');
6119+
6120+
try {
6121+
const $navigatorCaptionButton = dateBox._popup.$wrapper().find(`.${CALENDAR_CAPTION_BUTTON_CLASS}`);
6122+
6123+
$($navigatorCaptionButton).trigger('dxclick');
6124+
} catch(e) {
6125+
assert.ok(false, `error: ${e.message}`);
6126+
} finally {
6127+
assert.ok(true, 'there is no error');
6128+
}
6129+
});
61106130
});
61116131

61126132
testModule('native picker', function() {

0 commit comments

Comments
 (0)