Browse Source

Pull request #1546: 无JIRA任务 补充一些单测

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'e03f1074c93849a2c9fd555c91bf9fa03be6b7b2':
  补充一些单测
es6
guy 4 years ago
parent
commit
216ec8ee9a
  1. 171
      src/core/__test__/context.test.js

171
src/core/__test__/context.test.js

@ -77,6 +77,177 @@ describe("contextTest", function () {
});
/**
* test_author_guy
*/
it("异步context测试-loader的populate测试", function (done) {
var ParentStore = BI.inherit(Fix.Model, {
state: function () {
return {
context: "默认context"
};
},
childContext: ["context"]
});
BI.model("demo.model.parent_store", ParentStore);
var ChildStore = BI.inherit(Fix.Model, {
context: ["context"],
computed: {
currContext: function () {
return this.model.context;
}
},
actions: {
changeContext: function () {
this.model.context = "改变后的context";
}
}
});
BI.model("demo.model.child_store", ChildStore);
var Label = BI.inherit(BI.Widget, {
_store: function () {
return BI.Models.getModel("demo.model.child_store");
},
render: function () {
return {
type: "bi.label",
text: this.model.currContext
};
}
});
BI.shortcut("demo.label", Label);
var Demo = BI.inherit(BI.Widget, {
_store: function () {
return BI.Models.getModel("demo.model.parent_store");
},
render: function () {
var items = BI.map([1, 2, 3], function (i, v) {
return {
text: v,
value: v,
title: v
};
});
var self = this;
this.labels = {};
return {
type: "bi.loader",
ref: function (_ref) {
self.child = _ref;
},
itemsCreator: function (options, populate) {
setTimeout(function () {
populate(BI.map(items.slice((options.times - 1) * 10, options.times * 10), function (i, v) {
return BI.extend(v, {
type: "demo.label",
ref: function (_ref) {
self.labels[i] = _ref;
},
height: 25
});
}));
}, 0);
},
hasNext: function (options) {
return options.times * 10 < items.length;
}
};
}
});
BI.shortcut("demo.demo", Demo);
var demo = BI.Test.createWidget({
type: "demo.demo"
});
demo.child.populate();
setTimeout(function () {
expect(demo.labels[0].model.currContext).to.equal("默认context");
demo.destroy();
done();
}, 0);
});
/**
* test_author_guy
*/
it("异步context测试-beforeInit测试", function (done) {
var ParentStore = BI.inherit(Fix.Model, {
state: function () {
return {
context: "默认context"
};
},
childContext: ["context"]
});
BI.model("demo.model.parent_store", ParentStore);
var ChildStore = BI.inherit(Fix.Model, {
context: ["context"],
computed: {
currContext: function () {
return this.model.context;
}
},
actions: {
changeContext: function () {
this.model.context = "改变后的context";
}
}
});
BI.model("demo.model.child_store", ChildStore);
var Label = BI.inherit(BI.Widget, {
_store: function () {
return BI.Models.getModel("demo.model.child_store");
},
render: function () {
return {
type: "bi.label",
text: this.model.currContext
};
}
});
BI.shortcut("demo.label", Label);
var Demo = BI.inherit(BI.Widget, {
_store: function () {
return BI.Models.getModel("demo.model.parent_store");
},
beforeInit: function (callback) {
setTimeout(callback, 0);
},
render: function () {
var self = this;
return {
type: "demo.label",
ref: function (_ref) {
self.child = _ref;
}
};
}
});
BI.shortcut("demo.demo", Demo);
var demo = BI.Test.createWidget({
type: "demo.demo"
});
setTimeout(function () {
expect(demo.child.model.currContext).to.equal("默认context");
demo.destroy();
done();
}, 0);
});
/**
* test_author_guy
*/

Loading…
Cancel
Save