Browse Source

BI-48236 test: 测试text和button的点击方法

master
windy 5 years ago
parent
commit
7b61625dbd
  1. 28
      karma.conf.js
  2. 12
      test/utils.js
  3. 24
      test/widget/button.test.js
  4. 27
      test/widget/text.test.js

28
karma.conf.js

@ -26,6 +26,24 @@ module.exports = function (config) {
"src/core/plugin.js",
"src/core/**/*.js",
"src/data/**/*.js",
"src/data/**/*.js",
"src/data/**/*.js",
"src/third/**/*.js",
"src/base/pane.js",
"src/base/single/single.js",
"src/base/single/text.js",
"src/base/single/button/button.basic.js",
"src/base/single/button/button.node.js",
"src/base/single/tip/tip.js",
"src/base/combination/group.button.js",
"src/base/combination/tree.button.js",
"src/base/tree/ztree/treeview.js",
"src/base/tree/ztree/asynctree.js",
"src/base/tree/ztree/parttree.js",
"src/base/tree/ztree/list/listtreeview.js",
"src/base/tree/ztree/list/listasynctree.js",
"src/base/tree/ztree/list/listparttree.js",
"src/base/**/*.js",
"src/**/*.test.js",
"test/**/*.js"
],
@ -36,7 +54,8 @@ module.exports = function (config) {
preprocessors: {
"src/core/alias.js": "coverage",
"src/core/base.js": "coverage",
"src/core/func/date.js": "coverage"
"src/core/func/date.js": "coverage",
"src/base/**/*.js": "coverage"
},
@ -45,13 +64,18 @@ module.exports = function (config) {
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["progress", "coverage"],
browserDisconnectTolerance: 3,
browserDisconnectTimeout : 300000,
browserNoActivityTimeout : 300000,
coverageReporter: {
// specify a common output directory
dir: "coverage/",
reporters: [
// reporters not supporting the `file` property
{ type: "html", subdir: "report-html" },
{ type: "json-summary", subdir: "report-json-summary" }
{ type: "json-summary", subdir: "report-json-summary" },
{ type: "cobertura", subdir: "report-cobertura"}
]
},

12
test/utils.js

@ -0,0 +1,12 @@
!(function () {
BI.Test = {};
_.extend(BI.Test, {
createWidget: function (widgetJson) {
var widget = BI.createWidget(widgetJson);
widget._isRoot = true;
widget._mount();
widget.element.appendTo("body");
return widget;
}
})
})();

24
test/widget/button.test.js

@ -0,0 +1,24 @@
/**
* Created by windy on 2018/01/23.
*/
describe("ButtonTest", function () {
/**
* test_author_windy
*/
it("EventClickTest", function (done) {
var button = BI.Test.createWidget({
type: "bi.button",
text: "CCC",
handler: function () {
this.setText("click");
}
});
BI.nextTick(function () {
button.element.click();
expect(button.element[0].querySelector(".bi-text").textContent).to.equal("click");
done();
});
});
});

27
test/widget/text.test.js

@ -0,0 +1,27 @@
/**
* Created by windy on 2018/01/23.
*/
describe("TextTest", function () {
/**
* test_author_windy
*/
it("setText", function () {
var text = BI.Test.createWidget({
type: "bi.text"
});
text.setText("AAA");
expect(text.element[0].textContent).to.equal("AAA");
});
/**
* test_author_windy
*/
it("setStyle", function () {
var text = BI.Test.createWidget({
type: "bi.text"
});
text.setStyle({"color": "red"});
expect(text.element[0].style.color).to.equal("red");
});
});
Loading…
Cancel
Save