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

Throw a warning message for toolbar.height and drawer.target options only once if widget was initialized with using these options #12945

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/ui/drawer/ui.drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const Drawer = Widget.inherit({
},

getOverlayTarget() {
return this.option('target') || this._$wrapper;
return this._options.silent('target') || this._$wrapper;
},

getOverlay() {
Expand Down
7 changes: 0 additions & 7 deletions js/ui/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@ const Toolbar = ToolbarBase.inherit({
this._menuStrategy.widgetOption(name, value);
},

_setDeprecatedOptions() {
this.callBase();
extend(this._deprecatedOptions, {
'height': { since: '20.1', message: 'Functionality associated with this option is not intended for the Toolbar widget.' }
});
},

/**
* @name dxToolbarMethods.registerKeyHandler
* @publicName registerKeyHandler(key, handler)
Expand Down
5 changes: 5 additions & 0 deletions js/ui/toolbar/ui.toolbar.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { each } from '../../core/utils/iterator';
import AsyncCollectionWidget from '../collection/ui.collection_widget.async';
import Promise from '../../core/polyfills/promise';
import { BindableTemplate } from '../../core/templates/bindable_template';
import errors from '../../core/errors';
import fx from '../../animation/fx';

const TOOLBAR_CLASS = 'dx-toolbar';
Expand Down Expand Up @@ -44,6 +45,10 @@ const ToolbarBase = AsyncCollectionWidget.inherit({
this._userOptions = options || {};

this.callBase(element, options);

if('height' in this._userOptions) {
errors.log('W0001', this.NAME, 'height', '20.1', 'Functionality associated with this option is not intended for the Toolbar widget.');
}
},

_getSynchronizableOptionsForCreateComponent: function() {
Expand Down
53 changes: 36 additions & 17 deletions testing/tests/DevExpress.ui.widgets/drawer.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,44 @@ QUnit.module('Drawer behavior', () => {
assert.ok($(instance._overlay.option('position').of).hasClass('dx-drawer-content'), 'target is ok');
});

QUnit.test('show warning if deprecated \'target\' option is used', function(assert) {
sinon.spy(errors, 'log');
['shrink', 'overlap', 'push'].forEach((openedStateMode) => {
QUnit.test(`warnings for deprecated 'target' option, ${openedStateMode}, target: notInitialized`, function(assert) {
sinon.spy(errors, 'log');
EugeniyKiyashko marked this conversation as resolved.
Show resolved Hide resolved

try {
$('#drawer').dxDrawer({
openedStateMode: 'overlap',
target: '#someID'
});
try {
$('#drawer').dxDrawer({
openedStateMode: openedStateMode
});

assert.deepEqual(errors.log.lastCall.args, [
'W0001',
'dxDrawer',
'target',
'20.1',
'Functionality associated with this option is not intended for the Drawer widget.'
], 'args of the log method');
} finally {
errors.log.restore();
}
assert.strictEqual(errors.log.callCount, 0, 'log.callCount');
} finally {
errors.log.restore();
}
});

[null, undefined, '#someID'].forEach((target) => {
QUnit.test(`warnings for deprecated 'target' option, openedStateMode: ${openedStateMode}, target: ${target}`, function(assert) {
sinon.spy(errors, 'log');

try {
$('#drawer').dxDrawer({
openedStateMode: openedStateMode,
target: target
});

assert.strictEqual(errors.log.callCount, 1, 'log.callCount');
assert.deepEqual(errors.log.firstCall.args, [
'W0001',
'dxDrawer',
'target',
'20.1',
'Functionality associated with this option is not intended for the Drawer widget.'
], 'args of the log method');
} finally {
errors.log.restore();
}
});
});
});

QUnit.test('content() function', function(assert) {
Expand Down
53 changes: 36 additions & 17 deletions testing/tests/DevExpress.ui.widgets/toolbar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,42 @@ QUnit.module('render', {
assert.ok(templateUsed);
assert.equal(this.element.find('.custom-template').length, 1);
});

QUnit.test('show warning if deprecated "height" option is used', function(assert) {
sinon.spy(errors, 'log');

try {
$('#toolbar').dxToolbar({
items: [ { location: 'before', text: 'text1' } ],
height: 50
});

assert.strictEqual(errors.log.callCount, 1, 'log.callCount');
assert.deepEqual(errors.log.firstCall.args, [
'W0001',
'dxToolbar',
'height',
'20.1',
'Functionality associated with this option is not intended for the Toolbar widget.'
], 'args of the log method');
} finally {
errors.log.restore();
}
});

QUnit.test('Warning messages not displaying if deprecated "height" option not used', function(assert) {
sinon.spy(errors, 'log');

try {
$('#toolbar').dxToolbar({
items: [ { location: 'before', text: 'text1' } ]
});

assert.strictEqual(errors.log.callCount, 0, 'log.callCount');
} finally {
errors.log.restore();
}
});
});

QUnit.module('toolbar with menu', {
Expand Down Expand Up @@ -1572,22 +1608,5 @@ QUnit.module('Waiting fonts for material theme', {

themes.isMaterial = origIsMaterial;
});

QUnit.test('show warning if deprecated "height" option is used', function(assert) {
sinon.spy(errors, 'log');

$('#toolbar').dxToolbar({
items: [ { location: 'before', text: 'text1' } ],
height: 50
});

assert.deepEqual(errors.log.lastCall.args, [
'W0001',
'dxToolbar',
'height',
'20.1',
'Functionality associated with this option is not intended for the Toolbar widget.'
], 'args of the log method');
});
});