From 3bed4a4f0453cf9f3a51bf5ab0558521dc8c0a65 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Wed, 9 Oct 2019 16:55:59 +0800 Subject: [PATCH] =?UTF-8?q?BI-52072=20test:=20=E6=95=B0=E5=80=BC=E5=8C=BA?= =?UTF-8?q?=E9=97=B4=E5=92=8C=E5=8F=AF=E6=A0=87=E7=BA=A2=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E4=B8=8B=E6=8B=89=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/numberinterval.test.js | 88 ++++++++++ .../multitextvalue.combo.search.test.js | 154 ++++++++++++++++++ .../combo.textvaluedownlist.js | 100 ++++++++++++ .../trigger.textvaluedownlist.js | 55 +++++++ 4 files changed, 397 insertions(+) create mode 100644 src/widget/numberinterval/__test__/numberinterval.test.js create mode 100644 src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js create mode 100644 src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js create mode 100644 src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js diff --git a/src/widget/numberinterval/__test__/numberinterval.test.js b/src/widget/numberinterval/__test__/numberinterval.test.js new file mode 100644 index 0000000000..2b5d9fd625 --- /dev/null +++ b/src/widget/numberinterval/__test__/numberinterval.test.js @@ -0,0 +1,88 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2019/9/27 + */ + +describe("NumberInterval", function () { + + /** + * test_author_windy + */ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.number_interval", + }); + widget.setValue({ + max: 10, + min: 2, + closeMin: true, + closeMax: true + }); + expect(widget.getValue()).to.deep.equal({ + max: "10", + min: "2", + closeMin: true, + closeMax: true + }); + widget.destroy(); + }); + + /** + * test_author_windy + */ + it("defaultValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.number_interval", + max: 10, + min: 2, + closeMin: true, + closeMax: true + }); + expect(widget.getValue()).to.deep.equal({ + max: "10", + min: "2", + closeMin: true, + closeMax: true + }); + widget.destroy(); + }); + + /** + * test_author_windy + */ + it("输入报错单editor输入不合法报错", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.number_interval", + width: 200, + height: 24 + }); + widget.element.find(".number-interval-small-editor .bi-input").click(); + BI.Test.triggerKeyDown(widget.element.find(".number-interval-small-editor .bi-input"), "A", 65, function () { + expect(widget.element.children(".bi-tip").length).to.not.equal(0); + widget.destroy(); + done(); + }); + }); + + + /** + * test_author_windy + */ + it("输入报错区间不合法报错", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.number_interval", + width: 200, + height: 24 + }); + widget.element.find(".number-interval-small-editor .bi-input").click(); + BI.Test.triggerKeyDown(widget.element.find(".number-interval-small-editor .bi-input"), "2", 50, function () { + widget.element.find(".number-interval-big-editor .bi-input").click(); + BI.Test.triggerKeyDown(widget.element.find(".number-interval-big-editor .bi-input"), "1", 49, function () { + expect(widget.element.children(".bi-tip").length).to.not.equal(0); + widget.destroy(); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js b/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js new file mode 100644 index 0000000000..f9d8007733 --- /dev/null +++ b/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js @@ -0,0 +1,154 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2019/9/27 + */ + +describe("multitextvaluecombo", function () { + + var items = BI.map(BI.makeArray(1000, null), function(idx, v) { + return { + text: idx, + value: idx, + title: idx + }; + }); + + var itemSelectorGetter = function (array) { + return BI.map(array, function (idx, num) { + return ".bi-multi-select-popup-view .bi-loader .bi-button-group .bi-multi-select-item:nth-child(" + num + ")"; + }); + }; + + var searchItemSelectorGetter = function (array) { + return BI.map(array, function (idx, num) { + return ".bi-multi-select-search-pane .bi-loader .bi-button-group .bi-multi-select-item:nth-child(" + num + ")"; + }); + }; + + /** + * test_author_windy + **/ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.search_multi_text_value_combo", + width: 220, + items: items + }); + widget.setValue({ + type: 1, + value: [1, 2] + }); + expect(widget.getValue()).to.deep.equal({ + type: 1, + value: [1, 2] + }); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("getValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.search_multi_text_value_combo", + width: 220, + items: items, + value: { + type: 2, + value: [1, 2, 3] + } + }); + expect(widget.getValue()).to.deep.equal({ + type: 2, + value: [1, 2, 3] + }); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("点选选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.search_multi_text_value_combo", + width: 220, + items: items + }); + widget.element.find(".bi-multi-select-trigger").click(); + // 为什么要delay 300呢,因为按钮有debounce + BI.delay(function () { + // 点选1、2、3 + BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) { + widget.element.find(selector).click(); + }); + // 点全选 + widget.element.find(".bi-multi-select-popup-view .bi-label:contains(全选)").click(); + // 取消勾选1、2、3 + BI.delay(function () { + BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) { + widget.element.find(selector).click(); + }); + var value = widget.getValue(); + expect(value.type).to.equal(2); + expect(value.value).to.deep.equal([0, 1, 2]); + widget.destroy(); + done(); + }, 300); + }, 300); + }); + + /** + * test_author_windy + **/ + it("搜索选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.search_multi_text_value_combo", + width: 220, + items: items + }); + BI.nextTick(function () { + widget.element.find(".bi-multi-select-trigger .tip-text-style").click(); + // 这边为啥要加呢,因为input的setValue中有nextTick + BI.nextTick(function () { + BI.Test.triggerKeyDown(widget.element.find(".bi-multi-select-trigger .bi-input"), "2", 50, function () { + BI.nextTick(function () { + BI.each(searchItemSelectorGetter([1,2]), function (idx, selector) { + widget.element.find(selector).click(); + }); + expect(widget.getValue()).to.deep.equal({ + type: 1, + value: [2, 12] + }); + widget.destroy(); + done(); + }); + }); + }); + }); + }); + + /** + * test_author_windy + **/ + it("查看已选", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.search_multi_text_value_combo", + width: 220, + items: items, + value: { + type: 1, + value: [1, 2] + } + }); + BI.nextTick(function () { + widget.element.find(".bi-multi-select-check-selected-button").click(); + BI.delay(function () { + expect(widget.element.find(".display-list-item").length).to.equal(2); + widget.destroy(); + done(); + }, 300); + }); + }); + +}); \ No newline at end of file diff --git a/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js b/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js new file mode 100644 index 0000000000..734395889f --- /dev/null +++ b/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js @@ -0,0 +1,100 @@ +/** + * @class BI.TextValueDownListCombo + * @extend BI.Widget + */ +BI.TextValueDownListCombo = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.TextValueDownListCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-text-value-down-list-combo", + height: 24, + attributes: { + tabIndex: 0 + } + }); + }, + + _init: function () { + BI.TextValueDownListCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this._createValueMap(); + + var value; + if(BI.isNotNull(o.value)) { + value = this._digest(o.value); + } + this.trigger = BI.createWidget({ + type: "bi.down_list_select_text_trigger", + cls: "text-value-down-list-trigger", + height: o.height, + items: o.items, + text: o.text, + value: value + }); + + this.combo = BI.createWidget({ + type: "bi.down_list_combo", + element: this, + chooseType: BI.Selection.Single, + adjustLength: 2, + height: o.height, + el: this.trigger, + value: BI.isNull(value) ? [] : [value], + items: BI.deepClone(o.items) + }); + + this.combo.on(BI.DownListCombo.EVENT_CHANGE, function () { + var currentVal = self.combo.getValue()[0].value; + if (currentVal !== self.value) { + self.setValue(currentVal); + self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); + } + }); + + this.combo.on(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, function () { + var currentVal = self.combo.getValue()[0].childValue; + if (currentVal !== self.value) { + self.setValue(currentVal); + self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); + } + }); + }, + + _createValueMap: function () { + var self = this; + this.valueMap = {}; + BI.each(BI.flatten(this.options.items), function (idx, item) { + if (BI.has(item, "el")) { + BI.each(item.children, function (id, it) { + self.valueMap[it.value] = {value: item.el.value, childValue: it.value}; + }); + } else { + self.valueMap[item.value] = {value: item.value}; + } + }); + }, + + _digest: function (v) { + this.value = v; + return this.valueMap[v]; + }, + + setValue: function (v) { + v = this._digest(v); + this.combo.setValue([v]); + this.trigger.setValue(v); + }, + + getValue: function () { + var v = this.combo.getValue()[0]; + return [v.childValue || v.value]; + }, + + populate: function (items) { + this.options.items = BI.flatten(items); + this.combo.populate(items); + this._createValueMap(); + } +}); +BI.TextValueDownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.text_value_down_list_combo", BI.TextValueDownListCombo); \ No newline at end of file diff --git a/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js b/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js new file mode 100644 index 0000000000..b335ce5c1b --- /dev/null +++ b/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js @@ -0,0 +1,55 @@ +/** + * 选择字段trigger, downlist专用 + * 显示形式为 父亲值(儿子值) + * + * @class BI.DownListSelectTextTrigger + * @extends BI.Trigger + */ +BI.DownListSelectTextTrigger = BI.inherit(BI.Trigger, { + + _defaultConfig: function () { + return BI.extend(BI.DownListSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-down-list-select-text-trigger", + height: 24, + text: "" + }); + }, + + _init: function () { + BI.DownListSelectTextTrigger.superclass._init.apply(this, arguments); + var o = this.options; + this.trigger = BI.createWidget({ + type: "bi.select_text_trigger", + element: this, + height: o.height, + items: this._formatItemArray(o.items), + text: o.text, + value: BI.isNull(o.value) ? "" : o.value.childValue || o.value.value + }); + }, + + _formatItemArray: function () { + var sourceArray = BI.flatten(BI.deepClone(this.options.items)); + var targetArray = []; + BI.each(sourceArray, function (idx, item) { + if(BI.has(item, "el")) { + BI.each(item.children, function (id, it) { + it.text = item.el.text + "(" + it.text + ")"; + }); + targetArray = BI.concat(targetArray, item.children); + }else{ + targetArray.push(item); + } + }); + return targetArray; + }, + + setValue: function (vals) { + this.trigger.setValue(vals.childValue || vals.value); + }, + + populate: function (items) { + this.trigger.populate(this._formatItemArray(items)); + } +}); +BI.shortcut("bi.down_list_select_text_trigger", BI.DownListSelectTextTrigger); \ No newline at end of file