diff --git a/js/ui/lookup.js b/js/ui/lookup.js index 2aac043c3821..c9cb9aa5bbd0 100644 --- a/js/ui/lookup.js +++ b/js/ui/lookup.js @@ -1195,6 +1195,7 @@ var Lookup = DropDownList.inherit({ _renderInputValue: function() { return this.callBase().always((function() { + this._renderField(); this._refreshSelected(); this._setSubmitValue(); }).bind(this)); diff --git a/testing/tests/DevExpress.ui.widgets.editors/lookup.markup.tests.js b/testing/tests/DevExpress.ui.widgets.editors/lookup.markup.tests.js index f7f0bcef2545..9bb7a58c68f2 100644 --- a/testing/tests/DevExpress.ui.widgets.editors/lookup.markup.tests.js +++ b/testing/tests/DevExpress.ui.widgets.editors/lookup.markup.tests.js @@ -1,30 +1,29 @@ -import $ from "jquery"; -import Lookup from "ui/lookup"; -import executeAsyncMock from "../../helpers/executeAsyncMock.js"; -import fx from "animation/fx"; - -import "common.css!"; -import "generic_light.css!"; - -const { test, module, testStart } = QUnit; - -testStart(() => { - const markup = - `
-
-
-
- test -
-
`; +var $ = require("jquery"), + Lookup = require("ui/lookup"), + executeAsyncMock = require("../../helpers/executeAsyncMock.js"), + fx = require("animation/fx"); + +require("common.css!"); +require("generic_light.css!"); + +QUnit.testStart(function() { + var markup = + '
\ +
\ + \ +
\ +
\ + test\ +
\ +
'; $("#qunit-fixture").html(markup); }); -const LOOKUP_FIELD_CLASS = "dx-lookup-field"; +var LOOKUP_FIELD_CLASS = "dx-lookup-field"; -module("Lookup", { - beforeEach: () => { +QUnit.module("Lookup", { + beforeEach: function() { fx.off = true; executeAsyncMock.setup(); this.clock = sinon.useFakeTimers(); @@ -33,60 +32,61 @@ module("Lookup", { this.instance = this.element.dxLookup({ fullScreen: false }).dxLookup("instance"); this.$field = $(this.instance._$field); }, - afterEach: () => { + afterEach: function() { executeAsyncMock.teardown(); this.clock.restore(); fx.off = false; } -}, () => { - test("render dxLookup", (assert) => { - assert.ok(this.instance instanceof Lookup); - assert.ok(this.element.hasClass("dx-lookup"), "widget has class dx-lookup"); - assert.ok($(`.${LOOKUP_FIELD_CLASS}`, this.element).length, "widget contents field"); - assert.ok($(".dx-lookup-arrow", this.element).length, "widget contents arrow"); - }); +}); - test("regression: value is out of range (B231783)", (assert) => { - this.instance.option({ - dataSource: [1, 2, 3], - value: "wrongValue" - }); +QUnit.test("render dxLookup", function(assert) { + assert.ok(this.instance instanceof Lookup); + assert.ok(this.element.hasClass("dx-lookup"), "widget has class dx-lookup"); + assert.ok($("." + LOOKUP_FIELD_CLASS, this.element).length, "widget contents field"); + assert.ok($(".dx-lookup-arrow", this.element).length, "widget contents arrow"); +}); - assert.equal(this.$field.text(), "Select..."); +QUnit.test("regression: value is out of range (B231783)", function(assert) { + this.instance.option({ + dataSource: [1, 2, 3], + value: "wrongValue" }); - test("regression: B232016 - Lookup element has no 'dx-widget' CSS class", (assert) => { - assert.ok(this.element.hasClass("dx-widget")); - }); + assert.equal(this.$field.text(), "Select..."); +}); + +QUnit.test("regression: B232016 - Lookup element has no 'dx-widget' CSS class", function(assert) { + assert.ok(this.element.hasClass("dx-widget")); +}); - test("lookup empty class is attached when no item is selected", (assert) => { - const $lookup = this.element.dxLookup({ dataSource: [1, 2, 3], showClearButton: true, placeholder: "placeholder" }); - const LOOKUP_EMPTY_CLASS = "dx-lookup-empty"; +QUnit.test("lookup empty class is attached when no item is selected", function(assert) { + var $lookup = this.element.dxLookup({ dataSource: [1, 2, 3], showClearButton: true, placeholder: "placeholder" }), + LOOKUP_EMPTY_CLASS = "dx-lookup-empty"; - assert.ok($lookup.hasClass(LOOKUP_EMPTY_CLASS), "Lookup without preselected value has empty class"); - }); + assert.ok($lookup.hasClass(LOOKUP_EMPTY_CLASS), "Lookup without preselected value has empty class"); +}); - test("data source should be paginated by default", (assert) => { - assert.expect(1); +QUnit.test("data source should be paginated by default", function(assert) { + assert.expect(1); - const $element = $("#lookup").dxLookup({ + var $element = $("#lookup").dxLookup({ dataSource: [1, 2] - }); - const instance = $element.dxLookup("instance"); + }), + instance = $element.dxLookup("instance"); - assert.equal(instance._dataSource.paginate(), true, "pagination enabled by default"); - }); + assert.equal(instance._dataSource.paginate(), true, "pagination enabled by default"); +}); - test("T373464 - the 'fieldTemplate' should be used for rendering if the item is get asynchronously", (assert) => { - const fieldTemplateText = "Field template"; - const items = ["1", "2"]; - const $element = $("#lookup").dxLookup({ +QUnit.test("T373464 - the 'fieldTemplate' should be used for rendering if the item is get asynchronously", function(assert) { + var fieldTemplateText = "Field template", + items = ["1", "2"], + $element = $("#lookup").dxLookup({ fieldTemplate: function() { return fieldTemplateText; }, dataSource: { byKey: function(key) { - const d = $.Deferred(); + var d = $.Deferred(); setTimeout(function() { d.resolve(key); }, 0); @@ -99,94 +99,82 @@ module("Lookup", { value: items[0] }); - this.clock.tick(0); - assert.equal($element.find(`.${LOOKUP_FIELD_CLASS}`).text(), fieldTemplateText, "field template is used"); - }); - - - test("field template should be render one time per value rendering", (assert) => { - const fieldTemplateStub = sinon.stub().returns($("
")); - $("#widthRootStyle").dxLookup({ - fieldTemplate: fieldTemplateStub, - dataSource: [1, 2, 3], - value: 2 - }); - - assert.ok(fieldTemplateStub.calledOnce, "field template called once"); - }); + this.clock.tick(0); + assert.equal($element.find("." + LOOKUP_FIELD_CLASS).text(), fieldTemplateText, "field template is used"); }); -module("hidden input", () => { - test("a hidden input should be rendered", (assert) => { - const $element = $("#lookup").dxLookup(); - const $input = $element.find("input[type='hidden']"); +QUnit.module("hidden input"); - assert.equal($input.length, 1, "a hidden input is rendered"); - }); +QUnit.test("a hidden input should be rendered", function(assert) { + var $element = $("#lookup").dxLookup(), + $input = $element.find("input[type='hidden']"); - test("the hidden input should have correct value on widget init", (assert) => { - const $element = $("#lookup").dxLookup({ + assert.equal($input.length, 1, "a hidden input is rendered"); +}); + +QUnit.test("the hidden input should have correct value on widget init", function(assert) { + var $element = $("#lookup").dxLookup({ items: [1, 2, 3], value: 2 - }); - const $input = $element.find("input[type='hidden']"); + }), + $input = $element.find("input[type='hidden']"); - assert.equal($input.val(), "2", "input value is correct"); - }); + assert.equal($input.val(), "2", "input value is correct"); +}); - test("the hidden input should get display text as value if widget value is an object", (assert) => { - const items = [{ id: 1, text: "one" }]; - const $element = $("#lookup").dxLookup({ +QUnit.test("the hidden input should get display text as value if widget value is an object", function(assert) { + var items = [{ id: 1, text: "one" }], + $element = $("#lookup").dxLookup({ items: items, value: items[0], valueExpr: "this", displayExpr: "text" - }); - const $input = $element.find("input[type='hidden']"); + }), + $input = $element.find("input[type='hidden']"); - assert.equal($input.val(), items[0].text, "input value is correct"); - }); + assert.equal($input.val(), items[0].text, "input value is correct"); +}); - test("the hidden input should get value in respect of the 'valueExpr' option", (assert) => { - const items = [{ id: 1, text: "one" }]; - const $element = $("#lookup").dxLookup({ +QUnit.test("the hidden input should get value in respect of the 'valueExpr' option", function(assert) { + var items = [{ id: 1, text: "one" }], + $element = $("#lookup").dxLookup({ items: items, value: items[0].id, valueExpr: "id", displayExpr: "text" - }); - const $input = $element.find("input[type='hidden']"); + }), + $input = $element.find("input[type='hidden']"); - assert.equal($input.val(), items[0].id, "input value is correct"); - }); + assert.equal($input.val(), items[0].id, "input value is correct"); }); -module("options", { - beforeEach: () => { +QUnit.module("options", { + beforeEach: function() { fx.off = true; executeAsyncMock.setup(); this.clock = sinon.useFakeTimers(); }, - afterEach: () => { + afterEach: function() { executeAsyncMock.teardown(); fx.off = false; this.clock.restore(); } -}, () => { - test("hidden input should get the 'name' attribute with a correct value", (assert) => { - const expectedName = "lookup"; - const $element = $("#lookup").dxLookup({ +}); + +QUnit.test("hidden input should get the 'name' attribute with a correct value", function(assert) { + var expectedName = "lookup", + $element = $("#lookup").dxLookup({ name: expectedName - }); - const $input = $element.find("input[type='hidden']"); + }), + $input = $element.find("input[type='hidden']"); - assert.equal($input.attr("name"), expectedName, "input has correct 'name' attribute"); - }); + assert.equal($input.attr("name"), expectedName, "input has correct 'name' attribute"); +}); - test("displayExpr, valueExpr as functions (regression B230600)", (assert) => { - const instance = $("#lookup").dxLookup({ +QUnit.test("displayExpr, valueExpr as functions (regression B230600)", function(assert) { + var instance = $("#lookup").dxLookup({ dataSource: [1, 2], valueExpr: function(item) { return item * 2; @@ -195,90 +183,89 @@ module("options", { return "number " + item; }, value: 2 - }).dxLookup("instance"); - const $field = instance._$field; + }).dxLookup("instance"), + $field = instance._$field; - assert.equal($field.text(), "number 1"); - }); + assert.equal($field.text(), "number 1"); +}); - test("value", (assert) => { - const items = [1, 2, 3]; - const instance = $("#lookup").dxLookup({ dataSource: items, value: 1 }).dxLookup("instance"); - const $field = $(instance._$field); +QUnit.test("value", function(assert) { + var items = [1, 2, 3], + instance = $("#lookup").dxLookup({ dataSource: items, value: 1 }).dxLookup("instance"), + $field = $(instance._$field); - assert.equal($field.text(), 1, "field text is selected item value"); - assert.equal(instance.option("displayValue"), 1, "displayValue is selected item value"); - }); + assert.equal($field.text(), 1, "field text is selected item value"); + assert.equal(instance.option("displayValue"), 1, "displayValue is selected item value"); +}); - test("value should be assigned by reference", (assert) => { - const items = [{ name: "name" }]; - const instance = $("#lookup").dxLookup({ +QUnit.test("value should be assigned by reference", function(assert) { + var items = [{ name: "name" }], + instance = $("#lookup").dxLookup({ dataSource: items, value: items[0], displayExpr: "name" - }).dxLookup("instance"); - const $field = $(instance._$field); + }).dxLookup("instance"), + $field = $(instance._$field); - assert.equal($field.text(), "name", "item was found in items by reference"); - }); + assert.equal($field.text(), "name", "item was found in items by reference"); +}); - test("placeholder", (assert) => { - const instance = $("#lookup").dxLookup({ - dataSource: [] - }).dxLookup("instance"); +QUnit.test("placeholder", function(assert) { + var instance = $("#lookup").dxLookup({ + dataSource: [] + }) + .dxLookup("instance"); - assert.equal($(instance._$field).text(), "Select...", "default value"); - }); + assert.equal($(instance._$field).text(), "Select...", "default value"); +}); - test("fieldTemplate should be rendered", (assert) => { - $("#lookupFieldTemplate").dxLookup({ fieldTemplate: "field" }); +QUnit.test("fieldTemplate should be rendered", function(assert) { + $("#lookupFieldTemplate").dxLookup({ fieldTemplate: "field" }); - assert.equal($.trim($("#lookupFieldTemplate").text()), "test", "test was be rendered"); - }); + assert.equal($.trim($("#lookupFieldTemplate").text()), "test", "test was be rendered"); +}); - test("selected item should be passed as first argument if fieldTemplate is a function", (assert) => { - const items = [{ id: 1, text: "one", data: 11 }, { id: 2, text: "two", data: 22 }]; +QUnit.test("selected item should be passed as first argument if fieldTemplate is a function", function(assert) { + var items = [{ id: 1, text: "one", data: 11 }, { id: 2, text: "two", data: 22 }]; - $("#lookup").dxLookup({ - items: items, - valueExpr: "id", - displayExpr: "text", - value: items[1].id, - fieldTemplate: function(item) { - assert.deepEqual(item, items[1], "selected item is passed to fieldTemplate function"); + $("#lookup").dxLookup({ + items: items, + valueExpr: "id", + displayExpr: "text", + value: items[1].id, + fieldTemplate: function(item) { + assert.deepEqual(item, items[1], "selected item is passed to fieldTemplate function"); - return $("
").dxTextBox(); - } - }); + return $("
").dxTextBox(); + } }); }); -module("widget sizing render", () => { - test("constructor", (assert) => { - const $element = $("#lookup").dxLookup({ width: 400 }); - const instance = $element.dxLookup("instance"); +QUnit.module("widget sizing render"); - assert.strictEqual(instance.option("width"), 400); - assert.strictEqual($element.get(0).style.width, "400px", "outer width of the element must be equal to custom width"); - }); +QUnit.test("constructor", function(assert) { + var $element = $("#lookup").dxLookup({ width: 400 }), + instance = $element.dxLookup("instance"); + + assert.strictEqual(instance.option("width"), 400); + assert.strictEqual($element.get(0).style.width, "400px", "outer width of the element must be equal to custom width"); +}); - test("root with custom width", (assert) => { - const $element = $("#widthRootStyle").dxLookup(); - const instance = $element.dxLookup("instance"); +QUnit.test("root with custom width", function(assert) { + var $element = $("#widthRootStyle").dxLookup(), + instance = $element.dxLookup("instance"); - assert.strictEqual(instance.option("width"), undefined); - assert.strictEqual($element.get(0).style.width, "300px", "outer width of the element must be equal to custom width"); - }); + assert.strictEqual(instance.option("width"), undefined); + assert.strictEqual($element.get(0).style.width, "300px", "outer width of the element must be equal to custom width"); }); -module("aria accessibility", () => { - test("aria role", (assert) => { - const $element = $("#lookup").dxLookup(); - const $field = $element.find(`.${LOOKUP_FIELD_CLASS}:first`); +QUnit.module("aria accessibility"); - assert.equal($field.attr("role"), "combobox", "aria role is on the field"); - }); +QUnit.test("aria role", function(assert) { + var $element = $("#lookup").dxLookup(), + $field = $element.find("." + LOOKUP_FIELD_CLASS + ":first"); + assert.equal($field.attr("role"), "combobox", "aria role is on the field"); });