From 80319e21c8f1faeaf8bbc4da1c9d8dfac11b9a55 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 26 Dec 2019 19:25:30 +0800 Subject: [PATCH] =?UTF-8?q?BI-52072=20test:=20=E5=B9=B4=E6=9C=88=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/combo.yearmonth.test.js | 254 ++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 src/widget/yearmonth/__test__/combo.yearmonth.test.js diff --git a/src/widget/yearmonth/__test__/combo.yearmonth.test.js b/src/widget/yearmonth/__test__/combo.yearmonth.test.js new file mode 100644 index 000000000..08684f804 --- /dev/null +++ b/src/widget/yearmonth/__test__/combo.yearmonth.test.js @@ -0,0 +1,254 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2019/12/26 + */ + +describe("YearMonthCombo", function () { + + before(function () { + BI.holidays = { + "2010-02-28": true, + "2010-02-27": true + }; + }); + + /** + * test_author_windy + */ + it("defaultValue", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + value: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + BI.nextTick(function () { + expect(dateCombo.element.find(".bi-year-month-trigger .bi-center-layout:first-child .bi-label").text()).to.equal("2018年1月"); + dateCombo.destroy(); + done(); + }); + + }); + + /** + * test_author_windy + */ + it("测试输入值收起下拉清空值下拉出现", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30 + }); + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + // 输入8, 检查popup是否收起 + BI.Test.triggerKeyDown(dateCombo.element.find(".bi-year-month-trigger .bi-input"), "4", 52, function () { + BI.nextTick(function () { + expect(dateCombo.element.find(".bi-year-month-trigger + .bi-popup-view").css("display")).to.equal("none"); + // 清空输入, 检查popup是否弹出 + BI.Test.triggerKeyDown(dateCombo.element.find(".bi-year-month-trigger .bi-input"), "", BI.KeyCode.BACKSPACE, function () { + BI.nextTick(function () { + expect(dateCombo.element.find(".bi-year-month-trigger + .bi-popup-view").css("display")).to.equal("block"); + dateCombo.destroy(); + done(); + }); + }); + }); + }); + }); + + }); + + /** + * test_author_windy + */ + it("trigger的confirm-下拉面板选值confirm", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30 + }); + // 点击日期,是否收起下拉 + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + dateCombo.element.find(".bi-static-year-month-card .bi-list-item-select:first-child").click(); + expect(dateCombo.element.find(".bi-year-month-trigger + .bi-popup-view").css("display")).to.equal("none"); + dateCombo.destroy(); + done(); + }) + + }); + + /** + * test_author_windy + */ + it("下拉后直接点击外部的触发的confirm", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30, + }); + // 点击日期,是否收起下拉 + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + var input = dateCombo.element.find(".bi-year-month-trigger .bi-input"); + BI.Test.triggerKeyDown(input, null, BI.KeyCode.ENTER, function () { + BI.delay(function () { + expect(dateCombo.element.find(".bi-year-month-trigger + .bi-popup-view").css("display")).to.equal("none"); + dateCombo.destroy(); + done(); + }, 300); + }); + }) + }); + }); + + + /** + * test_author_windy + */ + it("点击清空", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30, + value: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-popup .bi-text:contains(清除)").parent().click(); + expect(BI.isNull(dateCombo.getValue())).to.equal(true); + dateCombo.destroy(); + done(); + }) + }); + + /** + * test_author_windy + */ + it("点击本季度", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30 + }); + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-popup .bi-text:contains(本月)").parent().click(); + var date = BI.getDate(); + expect(dateCombo.getValue()).to.deep.equal({ + type: 1, + value: { + year: date.getFullYear(), + month: date.getMonth() + 1 + } + }); + dateCombo.destroy(); + done(); + }) + }); + + + /** + * test_author_windy + */ + it("点击确定", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30, + value: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-popup .bi-text:contains(确定)").parent().click(); + expect(dateCombo.getValue()).to.deep.equal({ + type: 1, + value: { + year: 2018, + month: 1 + } + }); + dateCombo.destroy(); + done(); + }) + }); + + /** + * test_author_windy + */ + it("测试动态默认值", function () { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30, + value: { + type: 2, + value: { + year: -1, + month: -1 + } + } + }); + expect(dateCombo.getValue()).to.deep.equal({ + type: 2, + value: { + year: -1, + month: -1 + } + }); + dateCombo.destroy(); + }); + + + /** + * test_author_windy + */ + it("trigger的输入日期后confirm", function (done) { + var dateCombo = BI.Test.createWidget({ + type: "bi.dynamic_year_month_combo", + width: 220, + height: 30, + value: { + type: 1, + value: { + year: 2018, + month: 1 + } + } + }); + BI.nextTick(function () { + dateCombo.element.find(".bi-year-month-trigger .bi-basic-button").click(); + BI.nextTick(function () { + var input = dateCombo.element.find(".bi-year-month-trigger .bi-input"); + input.val("2"); + BI.Test.triggerKeyDown(dateCombo.element.find(".bi-year-month-trigger .bi-input"), null, BI.KeyCode.ENTER, function () { + BI.delay(function () { + expect(dateCombo.element.find(".bi-year-month-trigger .bi-text-button").text()).to.equal("2018年2月"); + dateCombo.destroy(); + done(); + }, 300); + }); + }); + }) + + }); +}); \ No newline at end of file