Browse Source

KERNEL-3477 test: 单测覆盖率53.2%

es6
windy 5 years ago
parent
commit
5c09b2dc3d
  1. 38
      src/base/collection/__test__/collection.test.js
  2. 33
      src/base/layer/__test__/layer.popover.test.js
  3. 23
      src/base/single/iframe/__test__/iframe.test.js
  4. 23
      src/base/single/img/__test__/img.test.js
  5. 19
      src/base/single/link/__test__/link.test.js
  6. 81
      src/case/pager/__test__/pager.test.js
  7. 33
      src/case/segment/__test__/segment.test.js

38
src/base/collection/__test__/collection.test.js

@ -0,0 +1,38 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("CollectionTest", function () {
/**
* test_author_windy
*/
it("collection", function () {
var items = [];
var cellCount = 100;
for (var i = 0; i < cellCount; i++) {
items[i] = {
type: "bi.label",
text: i
};
}
var grid = BI.Test.createWidget({
type: "bi.collection_view",
width: 400,
height: 300,
items: items,
cellSizeAndPositionGetter: function (index) {
return {
x: index % 10 * 50,
y: Math.floor(index / 10) * 50,
width: 50,
height: 50
};
}
});
// TODO 列表展示类控件不知道该测什么,先标记一下
grid.destroy();
});
});

33
src/base/layer/__test__/layer.popover.test.js

@ -0,0 +1,33 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("PopoverTest", function () {
/**
* test_author_windy
*/
it("BarPopover", function (done) {
var id = BI.UUID();
BI.Popovers.remove(id);
BI.Popovers.create(id, {
type: "bi.bar_popover",
size: "normal",
header: {
type: "bi.label",
text: "这个是header"
},
body: {
type: "bi.label",
text: "这个是body"
}
}).open(id);
BI.delay(function () {
expect(BI.Widget._renderEngine.createElement("body").find(".bi-popup-view .bi-z-index-mask").length).to.equal(1);
BI.Popovers.remove(id);
done();
}, 100);
});
});

23
src/base/single/iframe/__test__/iframe.test.js

@ -0,0 +1,23 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("IframeTest", function () {
/**
* test_author_windy
*/
it("directionPager", function () {
var a = BI.Test.createWidget({
type: "bi.iframe"
});
a.setSrc("http://www.baidu.com");
a.setName("testIFrame");
expect(a.element.attr("src"), "http://www.baidu.com");
expect(a.getSrc(), "http://www.baidu.com");
expect(a.getName(), "testIFrame");
a.destroy();
});
});

23
src/base/single/img/__test__/img.test.js

@ -0,0 +1,23 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("ImgTest", function () {
/**
* test_author_windy
*/
it("img", function () {
var a = BI.Test.createWidget({
type: "bi.img",
iconWidth: 36,
iconHeight: 36
});
a.setSrc("test.png");
expect(a.element.attr("src")).to.equal("test.png");
expect(a.getSrc()).to.equal("test.png");
a.destroy();
});
});

19
src/base/single/link/__test__/link.test.js

@ -0,0 +1,19 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("LinkTest", function () {
/**
* test_author_windy
*/
it("link", function () {
var a = BI.Test.createWidget({
type: "bi.link"
});
expect(a.element.is('a')).to.equal(true);
a.destroy();
});
});

81
src/case/pager/__test__/pager.test.js

@ -0,0 +1,81 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("PagerTest", function () {
/**
* test_author_windy
*/
it("allCountPager", function () {
var a = BI.Test.createWidget({
type: "bi.all_count_pager",
pages: 3,
curr: 1,
count: 1000
});
a.setCount(888);
expect(a.element.find(".row-count").text()).to.equal("888");
a.setAllPages(777);
a.setValue(4);
expect(a.element.find(".bi-input").val()).to.equal("4");
expect(a.getCurrentPage()).to.equal(4);
expect(a.hasPrev()).to.equal(false);
expect(a.hasNext()).to.equal(true);
a.populate();
expect(a.element.find(".bi-input").val()).to.equal("4");
a.setPagerVisible(false);
expect(a.element.find(".bi-pager").css("display")).to.equal("none");
a.destroy();
});
/**
* test_author_windy
*/
it("directionPager", function () {
var a = BI.Test.createWidget({
type: "bi.direction_pager",
horizontal: {
pages: false, // 总页数
curr: 1, // 初始化当前页, pages为数字时可用
hasPrev: function (v) {
return v > 1;
},
hasNext: function () {
return true;
},
firstPage: 1
},
vertical: {
pages: false, // 总页数
curr: 1, // 初始化当前页, pages为数字时可用
hasPrev: function (v) {
return v > 1;
},
hasNext: function () {
return true;
},
firstPage: 1
}
});
a.populate();
a.setVPage(2);
expect(a.getVPage()).to.equal(1);
a.setHPage(2);
expect(a.getHPage()).to.equal(1);
expect(a.hasVNext()).to.equal(true);
expect(a.hasHNext()).to.equal(true);
expect(a.hasVPrev()).to.equal(false);
expect(a.hasHPrev()).to.equal(false);
a.setHPagerVisible(false)
a.setVPagerVisible(false)
expect(a.element.find(".bi-pager").css("display")).to.equal("none");
a.clear();
a.destroy();
});
});

33
src/case/segment/__test__/segment.test.js

@ -0,0 +1,33 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/3/17
*/
describe("SegmentTest", function () {
/**
* test_author_windy
*/
it("segment", function () {
var a = BI.Test.createWidget({
type: "bi.segment",
items: [{
text: "1",
value: 1
}, {
text: "2",
value: 2
}, {
text: "3",
value: 3
}]
});
a.setValue(2);
expect(a.getValue()[0]).to.equal(2);
a.setEnable(false);
a.setEnabledValue(3);
a.setValue(3);
expect(a.getValue()[0]).to.equal(3);
a.destroy();
});
});
Loading…
Cancel
Save