|
| 1 | +import 'ui/select_box'; |
| 2 | +import 'ui/tag_box'; |
| 3 | +import 'ui/color_box'; |
| 4 | +import 'ui/drop_down_box'; |
| 5 | +import errors from 'core/errors'; |
| 6 | + |
| 7 | +const LICENSE_WARNING = 'W0022'; |
| 8 | + |
| 9 | +const FIELD_TEMPLATE_WARNING_ARGS = (componentName) => [ |
| 10 | + 'W0001', |
| 11 | + componentName, |
| 12 | + 'fieldTemplate', |
| 13 | + '25.2', |
| 14 | + 'Use the \'fieldAddons\' option instead', |
| 15 | +]; |
| 16 | + |
| 17 | +const FIELD_TEMPLATE_COMPONENTS = [ |
| 18 | + { name: 'dxSelectBox', selector: '#selectBox' }, |
| 19 | + { name: 'dxTagBox', selector: '#tagBox' }, |
| 20 | + { name: 'dxColorBox', selector: '#colorBox' }, |
| 21 | + { name: 'dxDropDownBox', selector: '#dropDownBox' }, |
| 22 | +]; |
| 23 | + |
| 24 | +QUnit.testStart(() => { |
| 25 | + const markup = |
| 26 | + '<div id="selectBox"></div>\ |
| 27 | + <div id="tagBox"></div>\ |
| 28 | + <div id="colorBox"></div>\ |
| 29 | + <div id="dropDownBox"></div>'; |
| 30 | + |
| 31 | + $('#qunit-fixture').html(markup); |
| 32 | +}); |
| 33 | + |
| 34 | +QUnit.module('Deprecated fieldTemplate', { |
| 35 | + beforeEach() { |
| 36 | + this.errorsSpy = sinon.spy(errors, 'log'); |
| 37 | + |
| 38 | + this.getFilteredWarnings = () => |
| 39 | + this.errorsSpy.getCalls().filter(({ args }) => args[0] !== LICENSE_WARNING); |
| 40 | + |
| 41 | + this.assertWarningIsCorrect = (assert, name) => { |
| 42 | + const warnings = this.getFilteredWarnings(); |
| 43 | + |
| 44 | + assert.strictEqual(warnings.length, 1, 'only one warning logged'); |
| 45 | + assert.deepEqual( |
| 46 | + warnings[0].args, |
| 47 | + FIELD_TEMPLATE_WARNING_ARGS(name), |
| 48 | + 'warning is raised with correct parameters' |
| 49 | + ); |
| 50 | + }; |
| 51 | + }, |
| 52 | + afterEach() { |
| 53 | + errors.log.restore(); |
| 54 | + }, |
| 55 | +}, () => { |
| 56 | + const fieldTemplate = () => $('<div>').dxTextBox(); |
| 57 | + |
| 58 | + FIELD_TEMPLATE_COMPONENTS.forEach(({ name, selector }) => { |
| 59 | + QUnit.test( |
| 60 | + `${name}: fieldTemplate should raise a deprecation warning on initialization`, |
| 61 | + function(assert) { |
| 62 | + $(selector)[name]({ fieldTemplate })[name]('instance'); |
| 63 | + this.assertWarningIsCorrect(assert, name); |
| 64 | + } |
| 65 | + ); |
| 66 | + |
| 67 | + QUnit.test( |
| 68 | + `${name}: fieldTemplate should raise a deprecation warning on option set`, |
| 69 | + function(assert) { |
| 70 | + const instance = $(selector)[name]()[name]('instance'); |
| 71 | + |
| 72 | + instance.option({ fieldTemplate }); |
| 73 | + |
| 74 | + this.assertWarningIsCorrect(assert, name); |
| 75 | + } |
| 76 | + ); |
| 77 | + |
| 78 | + QUnit.test(`${name}: does not log extra warning on value change call`, function(assert) { |
| 79 | + const instance = $(selector)[name]({ fieldTemplate })[name]('instance'); |
| 80 | + |
| 81 | + instance.option('value', ''); |
| 82 | + |
| 83 | + this.assertWarningIsCorrect(assert, name); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments