From ae825e5b445b3443cabff2a03e1e34fdcf556960 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 24 Jan 2019 16:02:23 +0800 Subject: [PATCH] =?UTF-8?q?BI-38818=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.ie.js | 2 +- dist/bundle.js | 2 +- dist/core.js | 2 +- dist/demo.js | 25 +++++- dist/fineui.ie.js | 2 +- dist/fineui.js | 2 +- dist/fineui_without_jquery_polyfill.js | 2 +- dist/utils.js | 2 +- karma.conf.js | 1 + private/prepare.js | 6 ++ src/core/alias.js | 2 +- test/utils/alias.test.js | 18 ++++ test/utils/base.test.js | 110 +++++++++++++++++++++++++ test/utils/date.test.js | 31 +++++++ 14 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 private/prepare.js create mode 100644 test/utils/base.test.js create mode 100644 test/utils/date.test.js diff --git a/dist/bundle.ie.js b/dist/bundle.ie.js index 15160b02a5..44fe78be83 100644 --- a/dist/bundle.ie.js +++ b/dist/bundle.ie.js @@ -16121,7 +16121,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/bundle.js b/dist/bundle.js index dcc7dacc08..55f4f3beab 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -16121,7 +16121,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/core.js b/dist/core.js index 44f04a8934..49ff7643c8 100644 --- a/dist/core.js +++ b/dist/core.js @@ -16121,7 +16121,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/demo.js b/dist/demo.js index 2f6091a0e2..70cb9c9e32 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -6158,7 +6158,30 @@ Demo.HtapeLayout = BI.inherit(BI.Widget, { }; } }); -BI.shortcut("demo.htape", Demo.HtapeLayout);/** +BI.shortcut("demo.htape", Demo.HtapeLayout);Demo.InlineVerticalLayout = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-absolute" + }, + render: function () { + return { + type: "bi.inline_vertical_adapt", + items: [{ + type: "bi.label", + text: "绝对布局", + cls: "layout-bg1", + width: 300, + height: 200 + }, { + type: "bi.label", + text: "绝对布局", + cls: "layout-bg1", + width: 300, + height: 100 + }] + }; + } +}); +BI.shortcut("demo.inline_vertical", Demo.InlineVerticalLayout);/** * Created by User on 2017/3/22. */ Demo.LeftRightVerticalAdaptLayout = BI.inherit(BI.Widget, { diff --git a/dist/fineui.ie.js b/dist/fineui.ie.js index 9ab48ee925..43221bc828 100644 --- a/dist/fineui.ie.js +++ b/dist/fineui.ie.js @@ -16366,7 +16366,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/fineui.js b/dist/fineui.js index 5413b8f7da..685a54c79f 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -16366,7 +16366,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/fineui_without_jquery_polyfill.js b/dist/fineui_without_jquery_polyfill.js index 819c5c35d2..9c1e289d8d 100644 --- a/dist/fineui_without_jquery_polyfill.js +++ b/dist/fineui_without_jquery_polyfill.js @@ -15867,7 +15867,7 @@ BI.ShowAction = BI.inherit(BI.Action, { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/dist/utils.js b/dist/utils.js index 1545020347..13fbf14edc 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -13126,7 +13126,7 @@ if (!_global.BI) { BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/karma.conf.js b/karma.conf.js index c6b36f407f..a1dc441221 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -25,6 +25,7 @@ module.exports = function (config) { "src/core/wrapper/layout.js", "src/core/plugin.js", "src/core/**/*.js", + "private/prepare.js", "src/data/**/*.js", "src/**/*.test.js", "test/**/*.test.js" diff --git a/private/prepare.js b/private/prepare.js new file mode 100644 index 0000000000..849a7aa0f6 --- /dev/null +++ b/private/prepare.js @@ -0,0 +1,6 @@ +!(function () { + // 先把准备环境准备好 + while(BI.prepares && BI.prepares.length > 0) { + BI.prepares.shift()(); + } +})(); \ No newline at end of file diff --git a/src/core/alias.js b/src/core/alias.js index b937115f89..30a963cefe 100644 --- a/src/core/alias.js +++ b/src/core/alias.js @@ -630,7 +630,7 @@ BI.decodeURIComponent = function (url) { var reserveSpecialCharsMap = {}; BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar; + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); url = url || ""; url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { diff --git a/test/utils/alias.test.js b/test/utils/alias.test.js index 5be5540ed6..d2b18b6abc 100644 --- a/test/utils/alias.test.js +++ b/test/utils/alias.test.js @@ -3,6 +3,14 @@ */ describe("aliasFunctionTest", function () { + before(function () { + BI.specialCharsMap = { + "\\\\": "0", + ".": "1", + "/": "2" + }; + }); + /** * test_author_windy */ @@ -13,4 +21,14 @@ describe("aliasFunctionTest", function () { expect(encodeString).to.equal("<a>1 2&</a>"); expect(BI.htmlDecode(encodeString)).to.equal(targetString); }); + + /** + * test_author_windy + */ + it("encodeURIComponent和decodeURIComponent", function () { + var targetString = "tableName./\\"; + var encodeString = BI.encodeURIComponent(targetString); + expect(encodeString).to.equal("tableName120"); + expect(BI.decodeURIComponent(encodeString)).to.equal(targetString); + }); }); diff --git a/test/utils/base.test.js b/test/utils/base.test.js new file mode 100644 index 0000000000..a6c942fc85 --- /dev/null +++ b/test/utils/base.test.js @@ -0,0 +1,110 @@ +/** + * Created by windy on 2018/01/24. + */ +describe("baseFunctionTest", function () { + + before(function () { + + }); + + /** + * test_author_windy + */ + it("formatEl和stripEL", function () { + var obj1 = { + type: "a", + pro: {}, + items: [] + }; + + var obj2 = { + el: { + type: "a", + pro: {}, + items: [] + } + }; + expect(BI.formatEL(obj1)).to.deep.equal(obj2); + expect(BI.formatEL(obj2)).to.deep.equal(obj2); + expect(BI.stripEL(obj1)).to.deep.equal(obj1); + expect(BI.stripEL(obj2)).to.deep.equal(obj1); + }); + + /** + * test_author_windy + */ + it("encodeURIComponent和decodeURIComponent", function () { + var targetString = "tableName./\\"; + var encodeString = BI.encodeURIComponent(targetString); + expect(encodeString).to.equal("tableName120"); + expect(BI.decodeURIComponent(encodeString)).to.equal(targetString); + }); + + /** + * test_author_windy + */ + it("count", function () { + var a = []; + expect(BI.count(1, 100)).to.equal(99); + BI.count(0, 100, function (v) { + a[v] = 0; + }); + expect(a.length).to.equal(100); + }); + + /** + * test_author_windy + */ + it("concat", function () { + expect(BI.concat([1], [2])).to.deep.equal([1, 2]); + expect(BI.concat(1, 2)).to.equal("12"); + expect(BI.concat("1", "2")).to.equal("12"); + expect(BI.concat({a: 1}, {b: 1})).to.deep.equal({a: 1, b: 1}); + }); + + /** + * test_author_windy + */ + it("remove", function () { + var a = [1, 2, 3, 4, 5, 6]; + BI.remove(a, function (i, v) { + return v === 4; + }); + expect(a).to.deep.equal([1, 2, 3, 5, 6]); + var b = { + a: 1, + b: 2 + }; + BI.remove(b, function (key) { + return key === "a"; + }); + expect(b).to.deep.equal({ + b: 2 + }); + }); + + /** + * test_author_windy + */ + it("removeAt", function () { + var a = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + BI.removeAt(a, 2); + expect(a).to.deep.equal([1, 2, 4, 5, 6, 7, 8, 9]); + var b = { + a: 1, + b: 2 + }; + BI.removeAt(b, "a"); + expect(b).to.deep.equal({ + b: 2 + }); + }); + + /** + * test_author_windy + */ + it("makeArray", function () { + var a = BI.makeArray(2, 1); + expect(a).to.deep.equal([1, 1, 1]); + }); +}); diff --git a/test/utils/date.test.js b/test/utils/date.test.js new file mode 100644 index 0000000000..042fd16f5d --- /dev/null +++ b/test/utils/date.test.js @@ -0,0 +1,31 @@ +/** + * Created by windy on 2018/01/23. + */ +describe("dateFunctionTest", function () { + + before(function () { + + }); + + /** + * test_author_windy + */ + it("getWeekNumber", function () { + expect(BI.print(BI.getDate(2005, 0, 1), "%Y-%W")).to.equal("2004-53"); + expect(BI.print(BI.getDate(2005, 0, 2), "%Y-%W")).to.equal("2004-53"); + expect(BI.print(BI.getDate(2005, 11, 31), "%Y-%W")).to.equal("2005-52"); + expect(BI.print(BI.getDate(2007, 0, 1), "%Y-%W")).to.equal("2007-01"); + expect(BI.print(BI.getDate(2007, 11, 30), "%Y-%W")).to.equal("2007-52"); + expect(BI.print(BI.getDate(2007, 11, 31), "%Y-%W")).to.equal("2008-01"); + expect(BI.print(BI.getDate(2008, 0, 1), "%Y-%W")).to.equal("2008-01"); + expect(BI.print(BI.getDate(2008, 11, 28), "%Y-%W")).to.equal("2008-52"); + expect(BI.print(BI.getDate(2008, 11, 29), "%Y-%W")).to.equal("2009-01"); + expect(BI.print(BI.getDate(2008, 11, 30), "%Y-%W")).to.equal("2009-01"); + expect(BI.print(BI.getDate(2008, 11, 31), "%Y-%W")).to.equal("2009-01"); + expect(BI.print(BI.getDate(2009, 0, 1), "%Y-%W")).to.equal("2009-01"); + expect(BI.print(BI.getDate(2009, 11, 31), "%Y-%W")).to.equal("2009-53"); + expect(BI.print(BI.getDate(2010, 0, 1), "%Y-%W")).to.equal("2009-53"); + expect(BI.print(BI.getDate(2010, 0, 2), "%Y-%W")).to.equal("2009-53"); + expect(BI.print(BI.getDate(2010, 0, 3), "%Y-%W")).to.equal("2009-53"); + }); +});