Skip to content

Commit df75349

Browse files
add tests
1 parent e4c55c9 commit df75349

2 files changed

Lines changed: 136 additions & 20 deletions

File tree

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

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import pointerMock from '../../helpers/pointerMock.js';
1515
import support from '__internal/core/utils/m_support';
1616
import typeUtils from 'core/utils/type';
1717
import uiDateUtils from '__internal/ui/date_box/date_utils';
18+
import DateBox from 'ui/date_box';
1819
import { normalizeKeyName } from 'common/core/events/utils/index';
1920

2021
import '../../helpers/calendarFixtures.js';
2122

22-
import 'ui/date_box';
2323
import 'ui/validator';
2424
import 'fluent_blue_light.css!';
2525

@@ -3395,6 +3395,7 @@ QUnit.module('Global formatting config (spec)', {
33953395
globalConfig[key] = value;
33963396
}
33973397
});
3398+
DateBox.defaultOptions([]);
33983399
},
33993400
}, () => {
34003401
QUnit.test('implicit date displayFormat uses global dateFormat', function(assert) {
@@ -3403,13 +3404,14 @@ QUnit.module('Global formatting config (spec)', {
34033404
dateFormat: 'dd/MM/yyyy',
34043405
});
34053406

3406-
const instance = $('#dateBox').dxDateBox({
3407+
const $element = $('#dateBox').dxDateBox({
34073408
type: 'date',
34083409
value: new Date(2020, 0, 2),
34093410
pickerType: 'calendar',
3410-
}).dxDateBox('instance');
3411+
});
3412+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
34113413

3412-
assert.strictEqual(instance.option('text'), '02/01/2020');
3414+
assert.strictEqual($input.val(), '02/01/2020');
34133415
});
34143416

34153417
QUnit.test('implicit datetime displayFormat uses global dateTimeFormat', function(assert) {
@@ -3418,13 +3420,30 @@ QUnit.module('Global formatting config (spec)', {
34183420
dateTimeFormat: 'dd/MM/yyyy, HH:mm',
34193421
});
34203422

3421-
const instance = $('#dateBox').dxDateBox({
3423+
const $element = $('#dateBox').dxDateBox({
34223424
type: 'datetime',
34233425
value: new Date(2020, 0, 2, 14, 5),
34243426
pickerType: 'calendar',
3425-
}).dxDateBox('instance');
3427+
});
3428+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
34263429

3427-
assert.strictEqual(instance.option('text'), '02/01/2020, 14:05');
3430+
assert.strictEqual($input.val(), '02/01/2020, 14:05');
3431+
});
3432+
3433+
QUnit.test('implicit time displayFormat uses global timeFormat', function(assert) {
3434+
config({
3435+
...config(),
3436+
timeFormat: 'HH:mm:ss',
3437+
});
3438+
3439+
const $element = $('#dateBox').dxDateBox({
3440+
type: 'time',
3441+
value: new Date(2020, 0, 2, 14, 5, 6),
3442+
pickerType: 'calendar',
3443+
});
3444+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
3445+
3446+
assert.strictEqual($input.val(), '14:05:06');
34283447
});
34293448

34303449
QUnit.test('explicit displayFormat keeps priority over global dateFormat', function(assert) {
@@ -3433,14 +3452,36 @@ QUnit.module('Global formatting config (spec)', {
34333452
dateFormat: 'dd/MM/yyyy',
34343453
});
34353454

3436-
const instance = $('#dateBox').dxDateBox({
3455+
const $element = $('#dateBox').dxDateBox({
34373456
type: 'date',
34383457
value: new Date(2020, 0, 2),
34393458
displayFormat: 'shortDate',
34403459
pickerType: 'calendar',
3441-
}).dxDateBox('instance');
3460+
});
3461+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
3462+
3463+
assert.strictEqual($input.val(), '1/2/2020');
3464+
});
34423465

3443-
assert.strictEqual(instance.option('text'), '1/2/2020');
3466+
QUnit.test('defaultOptions displayFormat keeps priority over global dateFormat', function(assert) {
3467+
config({
3468+
...config(),
3469+
dateFormat: 'dd/MM/yyyy',
3470+
});
3471+
DateBox.defaultOptions({
3472+
options: {
3473+
displayFormat: 'yyyy-MM-dd',
3474+
},
3475+
});
3476+
3477+
const $element = $('#dateBox').dxDateBox({
3478+
type: 'date',
3479+
value: new Date(2020, 0, 2),
3480+
pickerType: 'calendar',
3481+
});
3482+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
3483+
3484+
assert.strictEqual($input.val(), '2020-01-02');
34443485
});
34453486

34463487
QUnit.test('implicit DateBox uses dateTimeFormatPresets.shortDate when no dateFormat is set', function(assert) {
@@ -3451,13 +3492,14 @@ QUnit.module('Global formatting config (spec)', {
34513492
},
34523493
});
34533494

3454-
const instance = $('#dateBox').dxDateBox({
3495+
const $element = $('#dateBox').dxDateBox({
34553496
type: 'date',
34563497
value: new Date(2020, 0, 2),
34573498
pickerType: 'calendar',
3458-
}).dxDateBox('instance');
3499+
});
3500+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
34593501

3460-
assert.strictEqual(instance.option('text'), '02/01/2020');
3502+
assert.strictEqual($input.val(), '02/01/2020');
34613503
});
34623504

34633505
QUnit.test('dateFormat takes priority over dateTimeFormatPresets.shortDate for implicit DateBox', function(assert) {
@@ -3469,14 +3511,15 @@ QUnit.module('Global formatting config (spec)', {
34693511
},
34703512
});
34713513

3472-
const instance = $('#dateBox').dxDateBox({
3514+
const $element = $('#dateBox').dxDateBox({
34733515
type: 'date',
34743516
value: new Date(2020, 0, 2),
34753517
pickerType: 'calendar',
3476-
}).dxDateBox('instance');
3518+
});
3519+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
34773520

34783521
// dateFormat wins over dateTimeFormatPresets for implicit case
3479-
assert.strictEqual(instance.option('text'), '2020-01-02');
3522+
assert.strictEqual($input.val(), '2020-01-02');
34803523
});
34813524

34823525
QUnit.test('explicit displayFormat: "shortDate" uses dateTimeFormatPresets override', function(assert) {
@@ -3487,13 +3530,14 @@ QUnit.module('Global formatting config (spec)', {
34873530
},
34883531
});
34893532

3490-
const instance = $('#dateBox').dxDateBox({
3533+
const $element = $('#dateBox').dxDateBox({
34913534
type: 'date',
34923535
value: new Date(2020, 0, 2),
34933536
displayFormat: 'shortDate',
34943537
pickerType: 'calendar',
3495-
}).dxDateBox('instance');
3538+
});
3539+
const $input = $element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
34963540

3497-
assert.strictEqual(instance.option('text'), '02/01/2020');
3541+
assert.strictEqual($input.val(), '02/01/2020');
34983542
});
34993543
});

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/numberbox.localization.tests.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import $ from 'jquery';
2+
import config from 'core/config';
23
import localization from 'localization';
4+
import NumberBox from 'ui/number_box';
35

46
import keyboardMock from '../../helpers/keyboardMock.js';
57

6-
import 'ui/number_box';
78
import 'ui/validator';
89
import 'ui/text_box/ui.text_editor';
910

@@ -66,3 +67,74 @@ QUnit.module('localization: separator keys', moduleConfig, () => {
6667
}
6768
});
6869
});
70+
71+
QUnit.module('localization: global number format', {
72+
beforeEach: function() {
73+
this.savedConfig = { ...config() };
74+
this.savedLocale = localization.locale();
75+
localization.locale('en');
76+
},
77+
78+
afterEach: function() {
79+
localization.locale(this.savedLocale);
80+
config(this.savedConfig);
81+
NumberBox.defaultOptions([]);
82+
},
83+
}, () => {
84+
QUnit.test('uses global numberFormat when local format is not set', function(assert) {
85+
config({
86+
...config(),
87+
numberFormat: '#,##0.00',
88+
});
89+
90+
const $element = $('#numberbox').dxNumberBox({
91+
value: 1234.5,
92+
useMaskBehavior: true,
93+
});
94+
const $input = $element.find(TEXTEDITOR_INPUT_CLASS);
95+
96+
assert.strictEqual($input.val(), '1,234.50', 'text uses global format');
97+
});
98+
99+
QUnit.test('local format option has priority over global numberFormat', function(assert) {
100+
config({
101+
...config(),
102+
numberFormat: '#,##0.00',
103+
});
104+
105+
const $element = $('#numberbox').dxNumberBox({
106+
value: 1234.5,
107+
useMaskBehavior: true,
108+
format: {
109+
type: 'fixedPoint',
110+
precision: 0,
111+
},
112+
});
113+
const $input = $element.find(TEXTEDITOR_INPUT_CLASS);
114+
115+
assert.strictEqual($input.val(), '1,235', 'local format wins over global');
116+
});
117+
118+
QUnit.test('defaultOptions format has priority over global numberFormat', function(assert) {
119+
config({
120+
...config(),
121+
numberFormat: '#,##0.00',
122+
});
123+
NumberBox.defaultOptions({
124+
options: {
125+
format: {
126+
type: 'fixedPoint',
127+
precision: 0,
128+
},
129+
},
130+
});
131+
132+
const $element = $('#numberbox').dxNumberBox({
133+
value: 1234.5,
134+
useMaskBehavior: true,
135+
});
136+
const $input = $element.find(TEXTEDITOR_INPUT_CLASS);
137+
138+
assert.strictEqual($input.val(), '1,235', 'defaultOptions format wins over global');
139+
});
140+
});

0 commit comments

Comments
 (0)