From 9b3810d19a7146b25728484efbd84adb3da60278 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 6 Mar 2020 15:48:25 +0800 Subject: [PATCH] =?UTF-8?q?BI-61182=20test:=20=E5=8D=95=E6=B5=8Bup=20to=20?= =?UTF-8?q?50%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/combo.textvaluecheck.test.js | 64 ++++ .../__test__/multiselect.loader.nobar.test.js | 304 +++++++++++++++++- .../singleselect.insert.combo.test.js | 121 +++++++ 3 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 src/case/combo/textvaluecheckcombo/__test__/combo.textvaluecheck.test.js create mode 100644 src/widget/singleselect/__test__/singleselect.insert.combo.test.js diff --git a/src/case/combo/textvaluecheckcombo/__test__/combo.textvaluecheck.test.js b/src/case/combo/textvaluecheckcombo/__test__/combo.textvaluecheck.test.js new file mode 100644 index 000000000..30b671401 --- /dev/null +++ b/src/case/combo/textvaluecheckcombo/__test__/combo.textvaluecheck.test.js @@ -0,0 +1,64 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2020/3/5 + */ + +describe("text_value_check_combo", function () { + + var items = BI.map(BI.makeArray(11, null), function(idx, v) { + return { + text: idx, + value: idx, + title: idx + }; + }); + + /** + * test_author_windy + **/ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.text_value_check_combo", + width: 220, + height: 24, + items: items + }); + widget.setValue(2); + expect(widget.getValue()[0]).to.equal(2); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("getValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.text_value_check_combo", + width: 220, + items: items, + value: 2 + }); + expect(widget.getValue()[0]).to.equal(2); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("点选选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.text_value_check_combo", + width: 220, + items: items + }); + widget.element.find(".bi-select-text-trigger").click(); + // 为什么要delay 300呢,因为按钮有debounce + BI.delay(function () { + widget.element.find(".bi-single-select-item:contains(10)").click(); + expect(widget.getValue()[0]).to.equal(10); + widget.destroy(); + done(); + }, 300); + }); +}); \ No newline at end of file diff --git a/src/widget/multiselect/__test__/multiselect.loader.nobar.test.js b/src/widget/multiselect/__test__/multiselect.loader.nobar.test.js index 324598714..f73e9be16 100644 --- a/src/widget/multiselect/__test__/multiselect.loader.nobar.test.js +++ b/src/widget/multiselect/__test__/multiselect.loader.nobar.test.js @@ -2,4 +2,306 @@ * @author windy * @version 2.0 * Created by windy on 2019/9/18 - */ \ No newline at end of file + */ + +describe("multi_select_no_bar_series", function () { + + var _getItemsByTimes = function (items, times) { + var res = []; + for (var i = (times - 1) * 100; items[i] && i < times * 100; i++) { + res.push(items[i]); + } + return res; + }; + + var _hasNextByTimes = function (items, times) { + return times * 100 < items.length; + }; + + var _itemsCreator = function (options, callback) { + var items = BI.map(BI.makeArray(100, null), function(idx, v) { + return { + text: idx, + value: idx, + title: idx + }; + }); + var keywords = (options.keywords || []).slice(); + if (options.keyword) { + keywords.push(options.keyword); + } + BI.each(keywords, function (i, kw) { + var search = BI.Func.getSearchResult(items, kw); + items = search.match.concat(search.find); + }); + if (options.selectedValues) {// 过滤 + var filter = BI.makeObject(options.selectedValues, true); + items = BI.filter(items, function (i, ob) { + return !filter[ob.value]; + }); + } + if (options.type == BI.MultiSelectCombo.REQ_GET_ALL_DATA) { + callback({ + items: items + }); + return; + } + if (options.type == BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { + callback({count: items.length}); + return; + } + callback({ + items: _getItemsByTimes(items, options.times), + hasNext: _hasNextByTimes(items, options.times) + }); + }; + + 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.multi_select_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + widget.setValue([1, 2]); + expect(widget.getValue()).to.deep.equal([1, 2]); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("getValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator, + value: [1, 2, 3] + }); + expect(widget.getValue()).to.deep.equal([1, 2, 3]); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("点选选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + 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(); + }); + // 取消勾选1、2 + BI.delay(function () { + BI.each(itemSelectorGetter([1,2]), function (idx, selector) { + widget.element.find(selector).click(); + }); + expect(widget.getValue()).to.deep.equal([2]); + widget.destroy(); + done(); + }, 300); + }, 300); + }); + + /** + * test_author_windy + **/ + it("搜索选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + 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([2, 12]); + widget.destroy(); + done(); + }); + }); + }); + }); + }); + + /** + * test_author_windy + **/ + it("查看已选", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_no_bar_combo", + width: 220, + itemsCreator: function (op, callback) { + callback(items); + }, + 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); + }); + }); + + /** + * test_author_windy + **/ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + widget.setValue([1, 2]); + expect(widget.getValue()).to.deep.equal([1, 2]); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("getValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator, + value: [1, 2, 3] + }); + expect(widget.getValue()).to.deep.equal([1, 2, 3]); + widget.destroy(); + }); + + + /** + * test_author_windy + **/ + it("点选选值1", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + 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(); + }); + // 取消勾选1、2、3 + BI.delay(function () { + BI.each(itemSelectorGetter([1,2]), function (idx, selector) { + widget.element.find(selector).click(); + }); + expect(widget.getValue()).to.deep.equal([2]); + widget.destroy(); + done(); + }, 300); + }, 300); + }); + + /** + * test_author_windy + **/ + it("搜索选值1", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + 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([2, 12]); + widget.destroy(); + done(); + }); + }); + }); + }); + }); + + /** + * test_author_windy + **/ + it("新增值1", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator + }); + 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"), "z", 50, function () { + BI.nextTick(function () { + widget.element.find(".bi-text-button:contains(+点击新增\"z\")").click(); + expect(widget.getValue()).to.deep.equal(["z"]); + widget.destroy(); + done(); + }); + }); + }); + }); + }); + + /** + * test_author_windy + **/ + it("查看已选1", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.multi_select_insert_no_bar_combo", + width: 220, + itemsCreator: _itemsCreator, + 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/singleselect/__test__/singleselect.insert.combo.test.js b/src/widget/singleselect/__test__/singleselect.insert.combo.test.js new file mode 100644 index 000000000..e45ff861e --- /dev/null +++ b/src/widget/singleselect/__test__/singleselect.insert.combo.test.js @@ -0,0 +1,121 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2020/3/5 + */ + +describe("single_select_insert_combo", function () { + + var items = BI.map(BI.makeArray(100, null), function(idx, v) { + return { + text: idx, + value: idx, + title: idx + }; + }); + + var itemSelectorGetter = function (array) { + return BI.map(array, function (idx, num) { + return ".bi-single-select-popup-view .bi-loader .bi-button-group .bi-single-select-radio-item:nth-child(" + num + ")"; + }); + }; + + var searchItemSelectorGetter = function (array) { + return BI.map(array, function (idx, num) { + return ".bi-single-select-search-pane .bi-loader .bi-button-group .bi-single-select-radio-item:nth-child(" + num + ")"; + }); + }; + + /** + * test_author_windy + **/ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.single_select_insert_combo", + width: 220, + itemsCreator: function (op, callback) { + callback(items); + } + }); + widget.setValue(1); + expect(widget.getValue()).to.equal(1); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("getValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.single_select_insert_combo", + width: 220, + itemsCreator: function (op, callback) { + callback(items); + }, + value: 1 + }); + expect(widget.getValue()).to.equal(1); + widget.destroy(); + }); + + /** + * test_author_windy + **/ + it("点选选值", function (done) { + var start = BI.getTime(); + var widget = BI.Test.createWidget({ + type: "bi.single_select_insert_combo", + width: 220, + itemsCreator: function (op, callback) { + callback({ + items: items, + hasNext: false + }); + } + }); + widget.populate(); + widget.element.find(".bi-single-select-trigger").click(); + // 为什么要delay 300呢,因为按钮有debounce + BI.delay(function () { + // 点选1 + BI.each(itemSelectorGetter([1]), function (idx, selector) { + widget.element.find(selector).click(); + }); + expect(widget.getValue()).to.equal(0); + widget.destroy(); + done(); + }, 300); + }); + + /** + * test_author_windy + **/ + it("搜索选值", function (done) { + var widget = BI.Test.createWidget({ + type: "bi.single_select_insert_combo", + width: 220, + itemsCreator: function (op, callback) { + callback({ + items: items, + hasNext: false + }); + } + }); + BI.nextTick(function () { + widget.element.find(".bi-single-select-trigger .tip-text-style").click(); + // 这边为啥要加呢,因为input的setValue中有nextTick + BI.nextTick(function () { + BI.Test.triggerKeyDown(widget.element.find(".bi-single-select-trigger .bi-input"), "2", 50, function () { + BI.nextTick(function () { + BI.each(searchItemSelectorGetter([3]), function (idx, selector) { + widget.element.find(selector).click(); + }); + expect(widget.getValue()).to.equal(2); + widget.destroy(); + done(); + }); + }); + }); + }); + }); +}); \ No newline at end of file