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

Add missing tests for a DateBox widget #11733

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions js/ui/date_box/ui.date_box.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ const DateBox = DropDownEditor.inherit({
break;
case 'showDropDownButton':
this._formatValidationIcon();
this.callBase.apply(this, arguments);
break;
case 'readOnly':
this.callBase.apply(this, arguments);
Expand Down
34 changes: 34 additions & 0 deletions testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,40 @@ module('Advanced caret', setupModule, () => {
assert.deepEqual(this.keyboard.caret(), { start: 3, end: 5 }, 'caret was moved');
});

test('Move caret to the next group if advanceCaret is changed at runtime', function(assert) {
San4es marked this conversation as resolved.
Show resolved Hide resolved
const startDate = new Date('10/10/2012 13:07');
const $dateBox = $('#dateBox').dxDateBox({
advanceCaret: true,
displayFormat: 'dd.MM',
value: startDate,
pickerType: 'calendar'
});
const dateBox = $dateBox.dxDateBox('instance');
const $input = this.$element.find('.dx-texteditor-input');
const keyboard = keyboardMock($input, true);

keyboard.type('15');
assert.deepEqual(keyboard.caret(), { start: 3, end: 5 }, 'caret was moved');

$input.trigger('focusout');
dateBox.option({
'value': startDate,
'advanceCaret': false
});

keyboard.type('15');
assert.deepEqual(keyboard.caret(), { start: 0, end: 2 }, 'caret was not moved if advanceCaret is false');

$input.trigger('focusout');
dateBox.option({
'value': startDate,
'advanceCaret': true
});

keyboard.type('15');
assert.deepEqual(keyboard.caret(), { start: 3, end: 5 }, 'caret was moved after option was changed at runtime');
});

test('Move caret to the next group when next digit will overflow', function(assert) {
this.instance.option({
advanceCaret: true,
Expand Down
123 changes: 122 additions & 1 deletion testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const BUTTONS_CONTAINER_CLASS = 'dx-texteditor-buttons-container';
const TODAY_CELL_CLASS = 'dx-calendar-today';
const GESTURE_COVER_CLASS = 'dx-gesture-cover';
const DROP_DOWN_BUTTON_CLASS = 'dx-dropdowneditor-button';
const DROP_DOWN_BUTTON_VISIBLE_CLASS = 'dx-dropdowneditor-button-visible';

const CALENDAR_APPLY_BUTTON_SELECTOR = '.dx-popup-done.dx-button';

Expand Down Expand Up @@ -905,6 +906,24 @@ QUnit.module('options changed callbacks', moduleConfig, () => {
assert.deepEqual(secondValue, calendar.option('value'), 'value in calendar is changed');
});

QUnit.test('dxDateBox should hide or show its DDButton on showDropDownButton option change', function(assert) {
const $dateBox = $('#dateBox').dxDateBox({
showDropDownButton: true,
value: new Date(),
type: 'date',
pickerType: 'calendar'
});
const dateBox = $dateBox.dxDateBox('instance');

assert.ok($dateBox.hasClass(DROP_DOWN_BUTTON_VISIBLE_CLASS));

dateBox.option('showDropDownButton', false);
assert.notOk($dateBox.hasClass(DROP_DOWN_BUTTON_VISIBLE_CLASS));

dateBox.option('showDropDownButton', true);
assert.ok($dateBox.hasClass(DROP_DOWN_BUTTON_VISIBLE_CLASS));
});

QUnit.test('buttons are removed after applyValueMode option is changed', function(assert) {
const dateBox = $('#dateBox').dxDateBox({
type: 'date',
Expand Down Expand Up @@ -1501,7 +1520,7 @@ QUnit.module('widget sizing render', {}, () => {

QUnit.test('component width calculation should consider buttons containers element', function(assert) {
const $parent = $('#parent-div');
$parent.css('width', 200);
$parent.css('display', 'inline-block');

const $element = $('#dateBox').appendTo($parent);
const component = $('#dateBox').dxDateBox({
Expand Down Expand Up @@ -2797,6 +2816,46 @@ QUnit.module('datebox with time component', {
}
});

QUnit.test('date box should chenge behavior if adaptivityEnabled option is changed at runtime', function(assert) {
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved
const originalWidthFunction = renderer.fn.width;
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved

try {
sinon.stub(renderer.fn, 'width').returns(300);

const $element = $('#dateBox').dxDateBox({
type: 'datetime',
pickerType: 'calendar',
adaptivityEnabled: true,
opened: true
});
const instance = $element.dxDateBox('instance');

instance.option('adaptivityEnabled', false);
instance.close();
instance.open();

let $content = $(instance._popup.$content());
let box = Box.getInstance($content.find(`.${BOX_CLASS}`));
let $clock = $content.find(`.${TIMEVIEW_CLOCK_CLASS}`);

assert.strictEqual(box.itemElements().eq(0).find(`.${TIMEVIEW_CLASS}`).length, 0, 'timeview is not rendered');
assert.strictEqual($clock.length, 1, 'clock is rendered');

instance.option('adaptivityEnabled', true);
instance.close();
instance.open();

$content = $(instance._popup.$content());
box = Box.getInstance($content.find(`.${BOX_CLASS}`));
$clock = $content.find(`.${TIMEVIEW_CLOCK_CLASS}`);

assert.strictEqual(box.itemElements().eq(0).find(`.${TIMEVIEW_CLASS}`).length, 1, 'timeview is rendered');
assert.strictEqual($clock.length, 0, 'clock is not rendered');
} finally {
renderer.fn.width = originalWidthFunction;
}
});

QUnit.test('date box should have compact view when showAnalogClock option is false', function(assert) {
const $element = $('#dateBox').dxDateBox({
type: 'datetime',
Expand All @@ -2818,6 +2877,32 @@ QUnit.module('datebox with time component', {
assert.equal($clock.length, 0, 'clock was not rendered');
});

QUnit.test('date box should chenge behavior if showAnalogClock option is changed at runtime', function(assert) {
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved
const $element = $('#dateBox').dxDateBox({
type: 'datetime',
pickerType: 'calendar',
showAnalogClock: false,
opened: true
});
const instance = $element.dxDateBox('instance');

let $content = $(instance._popup.$content());
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved
let box = Box.getInstance($content.find(`.${BOX_CLASS}`));
let $clock = $content.find(`.${TIMEVIEW_CLOCK_CLASS}`);
assert.strictEqual(box.itemElements().eq(0).find(`.${TIMEVIEW_CLASS}`).length, 1, 'timeview is rendered');
assert.strictEqual($clock.length, 0, 'clock is not rendered');

instance.option('showAnalogClock', true);
instance.close();
instance.open();

$content = $(instance._popup.$content());
box = Box.getInstance($content.find(`.${BOX_CLASS}`));
$clock = $content.find(`.${TIMEVIEW_CLOCK_CLASS}`);
assert.strictEqual(box.itemElements().eq(0).find(`.${TIMEVIEW_CLASS}`).length, 0, 'timeview is not rendered');
assert.strictEqual($clock.length, 1, 'clock is rendered');
});

QUnit.test('date box wrapper adaptivity class depends on the screen size', function(assert) {
const LARGE_SCREEN_SIZE = 2000;
const SMALL_SCREEN_SIZE = 300;
Expand Down Expand Up @@ -4189,6 +4274,24 @@ QUnit.module('datebox validation', {}, () => {
assert.equal(validationError, 'A lorem ipsum...', 'validation message is correct');
});

QUnit.test('change invalidDateMessage at runtime', function(assert) {
const $dateBox = $('#dateBox').dxDateBox({
pickerType: 'calendar',
invalidDateMessage: 'test message'
});
const dateBox = $dateBox.dxDateBox('instance');
const $input = $dateBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);

$input.val('ips');
$($input).trigger('change');

dateBox.option('invalidDateMessage', 'another test message');
$($input).trigger('change');

const validationError = $dateBox.dxDateBox('instance').option('validationError').message;
assert.equal(validationError, 'another test message', 'validation message is correct');
});

QUnit.test('dateOutOfRangeMessage', function(assert) {
const $dateBox = $('#dateBox').dxDateBox({
dateOutOfRangeMessage: 'A lorem ipsum...',
Expand All @@ -4205,6 +4308,24 @@ QUnit.module('datebox validation', {}, () => {
assert.equal(validationError, 'A lorem ipsum...', 'validation message is correct');
});

QUnit.test('change dateOutOfRangeMessage at runtime', function(assert) {
const $dateBox = $('#dateBox').dxDateBox({
dateOutOfRangeMessage: 'test message',
min: new Date(2015, 5, 5),
max: new Date(2016, 5, 5),
value: new Date(2017, 5, 5)
});
const dateBox = $dateBox.dxDateBox('instance');
const $input = $dateBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);

$($input).trigger('change');
dateBox.option('dateOutOfRangeMessage', 'another test message');
$($input).trigger('change');

const validationError = $dateBox.dxDateBox('instance').option('validationError').message;
alexander-kotov-dx marked this conversation as resolved.
Show resolved Hide resolved
assert.equal(validationError, 'another test message', 'validation message is correct');
});

QUnit.test('year is too big', function(assert) {
const $dateBox = $('#dateBox').dxDateBox({
displayFormat: 'd/M/y',
Expand Down