From 0e5905648383938c137cd89f50cdc2e5837cbd50 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 16 Jan 2020 16:01:00 +0800 Subject: [PATCH] =?UTF-8?q?BI-52072=20test:=20single=5Fselect=5Fcombo?= =?UTF-8?q?=E5=92=8Cyear=5Fmonth=5Finterval=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/singleselect.combo.test.js | 121 ++++++++++++++++++ .../__test__/yearmonthinterval.test.js | 102 +++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 src/widget/singleselect/__test__/singleselect.combo.test.js create mode 100644 src/widget/yearmonthinterval/__test__/yearmonthinterval.test.js diff --git a/src/widget/singleselect/__test__/singleselect.combo.test.js b/src/widget/singleselect/__test__/singleselect.combo.test.js new file mode 100644 index 000000000..b1faa526b --- /dev/null +++ b/src/widget/singleselect/__test__/singleselect.combo.test.js @@ -0,0 +1,121 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2020/1/16 + */ +describe("single_select_combo", 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-single-select-popup-view .bi-loader .bi-button-group .bi-single-select-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-item:nth-child(" + num + ")"; + }); + }; + + /** + * test_author_windy + **/ + it("setValue", function () { + var widget = BI.Test.createWidget({ + type: "bi.single_select_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_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 widget = BI.Test.createWidget({ + type: "bi.single_select_combo", + allowNoSelect: true, + 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_combo", + allowNoSelect: true, + 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 diff --git a/src/widget/yearmonthinterval/__test__/yearmonthinterval.test.js b/src/widget/yearmonthinterval/__test__/yearmonthinterval.test.js new file mode 100644 index 000000000..7e116f3af --- /dev/null +++ b/src/widget/yearmonthinterval/__test__/yearmonthinterval.test.js @@ -0,0 +1,102 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2020/1/16 + */ +describe("YearMonthInterval", function () { + + before(function () { + BI.holidays = { + "2010-02-28": true, + "2010-02-27": true + }; + }); + + /** + * test_author_windy + */ + it("defaultValue", function () { + var dateCombo = BI.Test.createWidget({ + type: "bi.year_month_interval", + value: { + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + } + }); + expect(dateCombo.getValue()).eql({ + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + dateCombo.destroy(); + + }); + + /** + * test_author_windy + */ + it("setValue", function () { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30 + }); + dateCombo.setValue({ + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + expect(dateCombo.getValue()).eql({ + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + dateCombo.destroy(); + + }); +}); \ No newline at end of file