brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [60/71] [abbrv] brooklyn-ui git commit: Move util test specs to util/
Date Mon, 01 Feb 2016 17:52:59 GMT
Move util test specs to util/


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/817b10e5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/817b10e5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/817b10e5

Branch: refs/heads/0.7.0-incubating
Commit: 817b10e598ad36718f0d86d2ca2b4a26b95fa275
Parents: 86fdc10
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Mon May 18 12:08:31 2015 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri May 29 14:38:52 2015 +0100

----------------------------------------------------------------------
 .../src/test/javascript/specs/brooklyn-spec.js  | 129 ----------------
 .../javascript/specs/brooklyn-utils-spec.js     | 151 -------------------
 .../test/javascript/specs/util/brooklyn-spec.js | 129 ++++++++++++++++
 .../specs/util/brooklyn-utils-spec.js           | 151 +++++++++++++++++++
 4 files changed, 280 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/817b10e5/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js b/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
deleted file mode 100644
index 3fcfcc2..0000000
--- a/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-define([
-    "brooklyn", "backbone"
-], function (B, Backbone) {
-
-    describe("view", function () {
-        describe("form", function() {
-            var formTemplate = _.template('<form>' +
-                '<input name="id" type="text"/>' +
-                '<input name="initialvalue" type="text" value="present"/>' +
-                '<button type="submit" class="submit">Submit</button>' +
-                '</form>');
-
-            it("should set existing values on the model", function() {
-                var form = new B.view.Form({template: formTemplate, onSubmit: function()
{}});
-                expect(form.model.get("initialvalue")).toBe("present");
-                expect(form.model.get("id")).toBe("");
-            });
-
-            it("should maintain a model as inputs change", function () {
-                var form = new B.view.Form({
-                    template: formTemplate,
-                    onSubmit: function() {}
-                });
-                // simulate id entry
-                form.$("[name=id]").val("987");
-                form.$("[name=id]").trigger("change");
-                expect(form.model.get("id")).toBe("987");
-            });
-
-            it("should call the onSubmit callback when the form is submitted", function ()
{
-                var wasCalled = false;
-                var onSubmit = function (model) {
-                    wasCalled = true;
-                };
-                var form = new B.view.Form({
-                    template: formTemplate,
-                    onSubmit: onSubmit
-                });
-                console.log(form.$(".submit"));
-                form.$("form").trigger("submit");
-                expect(wasCalled).toBe(true);
-            });
-
-            it("should fail if called without template or onSubmit", function () {
-                try {
-                    new B.view.Form({template: ""});
-                    fail;
-                } catch (e) {
-                    // expected
-                }
-                try {
-                    new B.view.Form({onSubmit: function() {}});
-                    fail;
-                } catch (e) {
-                    // expected
-                }
-
-            });
-        });
-    });
-
-    describe("_.stripComments", function () {
-        it("should strip a basic comment", function () {
-            var text = "<p>abc</p>\n <!-- comment-here --> <p>cba</p>";
-            expect(_.stripComments(text)).toBe("<p>abc</p>\n  <p>cba</p>");
-        });
-
-        it("should return an empty string for an empty comment", function () {
-            expect(_.stripComments("<!---->")).toBe("");
-            expect(_.stripComments("<!-- -->")).toBe("");
-        });
-
-        it("should strip multiple comments", function () {
-            var text = "a<!-- one -->b<!--two-->c<!-- three  -->";
-            expect(_.stripComments(text)).toBe("abc");
-        });
-
-        it("should strip trailing newlines", function () {
-            expect(_.stripComments("<!-- a -->\nb")).toBe("b");
-            expect(_.stripComments("<!-- a -->\rb")).toBe("b");
-        });
-
-        it("should leave text with no comments untouched", function () {
-            var text = "<p>abc</p>";
-            expect(_.stripComments(text)).toBe(text);
-        });
-
-        it("should remove the Apache license header from an HTML template", function () {
-            var text = "<!--\n" +
-                    "Licensed to the Apache Software Foundation (ASF) under one\n" +
-                    "or more contributor license agreements.  See the NOTICE file\n" +
-                    "distributed with this work for additional information\n" +
-                    "regarding copyright ownership.  The ASF licenses this file\n" +
-                    "to you under the Apache License, Version 2.0 (the\n" +
-                    "\"License\"); you may not use this file except in compliance\n" +
-                    "with the License.  You may obtain a copy of the License at\n" +
-                    "\n" +
-                     "http://www.apache.org/licenses/LICENSE-2.0\n" +
-                    "\n" +
-                    "Unless required by applicable law or agreed to in writing,\n" +
-                    "software distributed under the License is distributed on an\n" +
-                    "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
-                    "KIND, either express or implied.  See the License for the\n" +
-                    "specific language governing permissions and limitations\n" +
-                    "under the License.\n" +
-                    "-->\n" +
-                    "real content";
-            expect(_.stripComments(text)).toBe("real content");
-        });
-    });
-});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/817b10e5/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js b/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
deleted file mode 100644
index 4c21f50..0000000
--- a/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-define([
-    'brooklyn-utils', "backbone"
-], function (Util, Backbone) {
-
-    describe('Rounding numbers', function () {
-
-        var round = Util.roundIfNumberToNumDecimalPlaces;
-
-        it("should round in the correct direction", function() {
-            // unchanged
-            expect(round(1, 2)).toBe(1);
-            expect(round(1.1, 1)).toBe(1.1);
-            expect(round(1.9, 1)).toBe(1.9);
-            expect(round(1.123123123, 6)).toBe(1.123123);
-            expect(round(-22.222, 3)).toBe(-22.222);
-
-            // up
-            expect(round(1.9, 0)).toBe(2);
-            expect(round(1.5, 0)).toBe(2);
-            expect(round(1.49, 1)).toBe(1.5);
-
-            // down
-            expect(round(1.01, 1)).toBe(1.0);
-            expect(round(1.49, 0)).toBe(1);
-            expect(round(1.249, 1)).toBe(1.2);
-            expect(round(1.0000000000000000000001, 0)).toBe(1);
-        });
-
-        it("should round negative numbers correctly", function() {
-            // up
-            expect(round(-10, 0)).toBe(-10);
-            expect(round(-10.49999, 0)).toBe(-10);
-
-            // down
-            expect(round(-10.5, 0)).toBe(-11);
-            expect(round(-10.50001, 0)).toBe(-11);
-            expect(round(-10.49999, 1)).toBe(-10.5);
-        });
-
-        it("should ignore non-numeric values", function() {
-            expect(round("xyz", 1)).toBe("xyz");
-            expect(round("2.4", 0)).toBe("2.4");
-            expect(round({a: 2}, 0)).toEqual({a: 2});
-        });
-
-        it("should ignore negative mantissas", function() {
-            expect(round(10.5, -1)).toBe(10.5);
-            expect(round(100, -1)).toBe(100);
-            expect(round(0, -1)).toBe(0);
-        });
-
-    });
-
-    describe("pathOf", function() {
-
-        it("should extract the path component of a URI", function() {
-            expect(Util.pathOf("http://www.example.com/path/to/resource#more?a=b&c=d")).toBe("/path/to/resource");
-        });
-
-        it("should return an empty path for an empty URL", function() {
-            expect(Util.pathOf("")).toBe("");
-        });
-
-        it("should handle input without domain", function() {
-            expect(Util.pathOf("/a/b/c/d#e")).toBe("/a/b/c/d");
-        })
-    });
-
-    describe("inputValue", function () {
-        it("should return inputs as strings", function () {
-            expect(Util.inputValue($('<input type="text" value="bob"/>'))).toBe("bob");
-            expect(Util.inputValue($('<textarea rows="10" cols="5">content</textarea>'))).toBe("content");
-        });
-
-        it("should return true/false for checkboxes", function () {
-            var input = $('<input type="checkbox" checked/>');
-            expect(Util.inputValue(input)).toBe(true);
-            input = $('<input type="checkbox" />');
-            expect(Util.inputValue(input)).toBe(false);
-        });
-    });
-
-    describe("bindModelFromForm", function () {
-        // pretend to be a Backbone model without bringing in Backbone as a dependency
-        var TestModel = Backbone.Model.extend({
-            urlRoot: function () {
-                return "/foo/bar/";
-            }
-        });
-        var form = $("<form>" +
-            "<input name='id' type='input' value='text'/>" +
-            "<input name='bool' type='checkbox' checked/>" +
-            "</form>");
-
-        it("should create a new model if given a constructor", function () {
-            var model = Util.bindModelFromForm(TestModel, form);
-            expect(model instanceof TestModel).toBe(true);
-            expect(model.url()).toBe("/foo/bar/text");
-            var inputs = model.attributes;
-            expect(_.keys(inputs).length).toBe(2);
-            expect(inputs.id).toBe("text");
-            expect(inputs.bool).toBe(true);
-        });
-
-        it("should update an existing model", function () {
-            var model = new TestModel({initialAttribute: "xyz"});
-            Util.bindModelFromForm(model, form);
-            var inputs = model.attributes;
-            expect(_.keys(inputs).length).toBe(3);
-            expect(inputs.id).toBe("text");
-            expect(inputs.bool).toBe(true);
-            expect(inputs.initialAttribute).toBe("xyz");
-        });
-    });
-
-    describe("extractError", function () {
-        it("should extract the response message", function () {
-            var m = Util.extractError({ responseText: '{"message": "hello"}'}, "default");
-            expect(m).toBe("hello");
-        });
-
-        it("should return the default on invalid JSON", function () {
-            var m = Util.extractError({ responseText: "<html></html>"}, "default");
-            expect(m).toBe("default");
-        });
-
-        it("should return the default if the response has no message", function () {
-            var m = Util.extractError({ a: '{"b": "c"}'}, "default");
-            expect(m).toBe("default");
-        });
-    });
-
-});

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/817b10e5/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
new file mode 100644
index 0000000..3fcfcc2
--- /dev/null
+++ b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+define([
+    "brooklyn", "backbone"
+], function (B, Backbone) {
+
+    describe("view", function () {
+        describe("form", function() {
+            var formTemplate = _.template('<form>' +
+                '<input name="id" type="text"/>' +
+                '<input name="initialvalue" type="text" value="present"/>' +
+                '<button type="submit" class="submit">Submit</button>' +
+                '</form>');
+
+            it("should set existing values on the model", function() {
+                var form = new B.view.Form({template: formTemplate, onSubmit: function()
{}});
+                expect(form.model.get("initialvalue")).toBe("present");
+                expect(form.model.get("id")).toBe("");
+            });
+
+            it("should maintain a model as inputs change", function () {
+                var form = new B.view.Form({
+                    template: formTemplate,
+                    onSubmit: function() {}
+                });
+                // simulate id entry
+                form.$("[name=id]").val("987");
+                form.$("[name=id]").trigger("change");
+                expect(form.model.get("id")).toBe("987");
+            });
+
+            it("should call the onSubmit callback when the form is submitted", function ()
{
+                var wasCalled = false;
+                var onSubmit = function (model) {
+                    wasCalled = true;
+                };
+                var form = new B.view.Form({
+                    template: formTemplate,
+                    onSubmit: onSubmit
+                });
+                console.log(form.$(".submit"));
+                form.$("form").trigger("submit");
+                expect(wasCalled).toBe(true);
+            });
+
+            it("should fail if called without template or onSubmit", function () {
+                try {
+                    new B.view.Form({template: ""});
+                    fail;
+                } catch (e) {
+                    // expected
+                }
+                try {
+                    new B.view.Form({onSubmit: function() {}});
+                    fail;
+                } catch (e) {
+                    // expected
+                }
+
+            });
+        });
+    });
+
+    describe("_.stripComments", function () {
+        it("should strip a basic comment", function () {
+            var text = "<p>abc</p>\n <!-- comment-here --> <p>cba</p>";
+            expect(_.stripComments(text)).toBe("<p>abc</p>\n  <p>cba</p>");
+        });
+
+        it("should return an empty string for an empty comment", function () {
+            expect(_.stripComments("<!---->")).toBe("");
+            expect(_.stripComments("<!-- -->")).toBe("");
+        });
+
+        it("should strip multiple comments", function () {
+            var text = "a<!-- one -->b<!--two-->c<!-- three  -->";
+            expect(_.stripComments(text)).toBe("abc");
+        });
+
+        it("should strip trailing newlines", function () {
+            expect(_.stripComments("<!-- a -->\nb")).toBe("b");
+            expect(_.stripComments("<!-- a -->\rb")).toBe("b");
+        });
+
+        it("should leave text with no comments untouched", function () {
+            var text = "<p>abc</p>";
+            expect(_.stripComments(text)).toBe(text);
+        });
+
+        it("should remove the Apache license header from an HTML template", function () {
+            var text = "<!--\n" +
+                    "Licensed to the Apache Software Foundation (ASF) under one\n" +
+                    "or more contributor license agreements.  See the NOTICE file\n" +
+                    "distributed with this work for additional information\n" +
+                    "regarding copyright ownership.  The ASF licenses this file\n" +
+                    "to you under the Apache License, Version 2.0 (the\n" +
+                    "\"License\"); you may not use this file except in compliance\n" +
+                    "with the License.  You may obtain a copy of the License at\n" +
+                    "\n" +
+                     "http://www.apache.org/licenses/LICENSE-2.0\n" +
+                    "\n" +
+                    "Unless required by applicable law or agreed to in writing,\n" +
+                    "software distributed under the License is distributed on an\n" +
+                    "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+                    "KIND, either express or implied.  See the License for the\n" +
+                    "specific language governing permissions and limitations\n" +
+                    "under the License.\n" +
+                    "-->\n" +
+                    "real content";
+            expect(_.stripComments(text)).toBe("real content");
+        });
+    });
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/817b10e5/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js b/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
new file mode 100644
index 0000000..4c21f50
--- /dev/null
+++ b/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+define([
+    'brooklyn-utils', "backbone"
+], function (Util, Backbone) {
+
+    describe('Rounding numbers', function () {
+
+        var round = Util.roundIfNumberToNumDecimalPlaces;
+
+        it("should round in the correct direction", function() {
+            // unchanged
+            expect(round(1, 2)).toBe(1);
+            expect(round(1.1, 1)).toBe(1.1);
+            expect(round(1.9, 1)).toBe(1.9);
+            expect(round(1.123123123, 6)).toBe(1.123123);
+            expect(round(-22.222, 3)).toBe(-22.222);
+
+            // up
+            expect(round(1.9, 0)).toBe(2);
+            expect(round(1.5, 0)).toBe(2);
+            expect(round(1.49, 1)).toBe(1.5);
+
+            // down
+            expect(round(1.01, 1)).toBe(1.0);
+            expect(round(1.49, 0)).toBe(1);
+            expect(round(1.249, 1)).toBe(1.2);
+            expect(round(1.0000000000000000000001, 0)).toBe(1);
+        });
+
+        it("should round negative numbers correctly", function() {
+            // up
+            expect(round(-10, 0)).toBe(-10);
+            expect(round(-10.49999, 0)).toBe(-10);
+
+            // down
+            expect(round(-10.5, 0)).toBe(-11);
+            expect(round(-10.50001, 0)).toBe(-11);
+            expect(round(-10.49999, 1)).toBe(-10.5);
+        });
+
+        it("should ignore non-numeric values", function() {
+            expect(round("xyz", 1)).toBe("xyz");
+            expect(round("2.4", 0)).toBe("2.4");
+            expect(round({a: 2}, 0)).toEqual({a: 2});
+        });
+
+        it("should ignore negative mantissas", function() {
+            expect(round(10.5, -1)).toBe(10.5);
+            expect(round(100, -1)).toBe(100);
+            expect(round(0, -1)).toBe(0);
+        });
+
+    });
+
+    describe("pathOf", function() {
+
+        it("should extract the path component of a URI", function() {
+            expect(Util.pathOf("http://www.example.com/path/to/resource#more?a=b&c=d")).toBe("/path/to/resource");
+        });
+
+        it("should return an empty path for an empty URL", function() {
+            expect(Util.pathOf("")).toBe("");
+        });
+
+        it("should handle input without domain", function() {
+            expect(Util.pathOf("/a/b/c/d#e")).toBe("/a/b/c/d");
+        })
+    });
+
+    describe("inputValue", function () {
+        it("should return inputs as strings", function () {
+            expect(Util.inputValue($('<input type="text" value="bob"/>'))).toBe("bob");
+            expect(Util.inputValue($('<textarea rows="10" cols="5">content</textarea>'))).toBe("content");
+        });
+
+        it("should return true/false for checkboxes", function () {
+            var input = $('<input type="checkbox" checked/>');
+            expect(Util.inputValue(input)).toBe(true);
+            input = $('<input type="checkbox" />');
+            expect(Util.inputValue(input)).toBe(false);
+        });
+    });
+
+    describe("bindModelFromForm", function () {
+        // pretend to be a Backbone model without bringing in Backbone as a dependency
+        var TestModel = Backbone.Model.extend({
+            urlRoot: function () {
+                return "/foo/bar/";
+            }
+        });
+        var form = $("<form>" +
+            "<input name='id' type='input' value='text'/>" +
+            "<input name='bool' type='checkbox' checked/>" +
+            "</form>");
+
+        it("should create a new model if given a constructor", function () {
+            var model = Util.bindModelFromForm(TestModel, form);
+            expect(model instanceof TestModel).toBe(true);
+            expect(model.url()).toBe("/foo/bar/text");
+            var inputs = model.attributes;
+            expect(_.keys(inputs).length).toBe(2);
+            expect(inputs.id).toBe("text");
+            expect(inputs.bool).toBe(true);
+        });
+
+        it("should update an existing model", function () {
+            var model = new TestModel({initialAttribute: "xyz"});
+            Util.bindModelFromForm(model, form);
+            var inputs = model.attributes;
+            expect(_.keys(inputs).length).toBe(3);
+            expect(inputs.id).toBe("text");
+            expect(inputs.bool).toBe(true);
+            expect(inputs.initialAttribute).toBe("xyz");
+        });
+    });
+
+    describe("extractError", function () {
+        it("should extract the response message", function () {
+            var m = Util.extractError({ responseText: '{"message": "hello"}'}, "default");
+            expect(m).toBe("hello");
+        });
+
+        it("should return the default on invalid JSON", function () {
+            var m = Util.extractError({ responseText: "<html></html>"}, "default");
+            expect(m).toBe("default");
+        });
+
+        it("should return the default if the response has no message", function () {
+            var m = Util.extractError({ a: '{"b": "c"}'}, "default");
+            expect(m).toBe("default");
+        });
+    });
+
+});


Mime
View raw message