From 6c9bc4d0a3cc9cdd82af927c6aaf558312297672 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 15 Oct 2020 15:37:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E4=B8=AA=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- karma.conf.js | 2 + src/core/__test__/context.test.js | 151 ++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/core/__test__/context.test.js diff --git a/karma.conf.js b/karma.conf.js index 4f41f3088..2ab764d6d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -58,6 +58,8 @@ module.exports = function (config) { "src/case/**/*.js", "src/widget/**/*.js", "src/component/**/*.js", + "dist/fix/fix.js", + "dist/fix/fix.compact.js", "src/**/*.test.js", "test/**/*.js" ], diff --git a/src/core/__test__/context.test.js b/src/core/__test__/context.test.js new file mode 100644 index 000000000..21738072d --- /dev/null +++ b/src/core/__test__/context.test.js @@ -0,0 +1,151 @@ +/** + * Created by windy on 2018/01/23. + */ +describe("contextTest", function () { + + before(function () { + }); + + /** + * test_author_guy + */ + it("context测试", function () { + + 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 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" + }); + + expect(demo.child.model.currContext).to.equal("默认context"); + demo.child.store.changeContext(); + expect(demo.model.context).to.equal("改变后的context"); + demo.destroy(); + + }); + + /** + * test_author_guy + */ + it("inject测试", function () { + + 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, { + inject: ["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 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" + }); + + expect(demo.child.model.currContext).to.equal("默认context"); + demo.child.store.changeContext(); + expect(demo.model.context).to.equal("默认context"); + demo.destroy(); + + }); + +});