From 6ba7bf6918b84dbd11d19a0d8737c16ad57c79c3 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 6 Feb 2015 08:22:57 +0100 Subject: [PATCH] Increased test coverage of new foxx views. All positive pathes are now covered. Error handling not yet --- .../frontend/js/collections/foxxCollection.js | 8 +- .../js/views/applicationDetailView.js | 12 +- .../APP/frontend/js/views/foxxActiveView.js | 6 +- .../_admin/aardvark/APP/test/karma/files.json | 2 + .../specs/collections/foxxCollectionSpec.js | 28 ++++ .../specs/views/applicationDetailViewSpec.js | 128 ++++++++++++++++++ 6 files changed, 175 insertions(+), 9 deletions(-) diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/foxxCollection.js b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/foxxCollection.js index 265a5aafe4..eda795e45f 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/foxxCollection.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/foxxCollection.js @@ -15,12 +15,12 @@ comparator: function(item, item2) { var a, b; if (this.sortOptions.desc === true) { - a = item.get('name'); - b = item2.get('name'); + a = item.get('mount'); + b = item2.get('mount'); return a < b ? 1 : a > b ? -1 : 0; } - a = item.get('name'); - b = item2.get('name'); + a = item.get('mount'); + b = item2.get('mount'); return a > b ? 1 : a < b ? -1 : 0; }, diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/applicationDetailView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/applicationDetailView.js index 9c7d3078d9..ed7e2908b3 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/applicationDetailView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/applicationDetailView.js @@ -26,8 +26,8 @@ }, toggleDevelopment: function() { - this.model.toggleDevelopment(!this.model.get("development"), function() { - if (this.model.get("development")) { + this.model.toggleDevelopment(!this.model.isDevelopment(), function() { + if (this.model.isDevelopment()) { $("#app-switch-mode").val("Production"); $("#app-development-indicator").css("display", "inline"); } else { @@ -143,6 +143,14 @@ msg: "Has to be an integer." }]; /* falls through */ + case "number": + if (check === undefined) { + check = [{ + rule: Joi.number().optional().allow(""), + msg: "Has to be a number." + }]; + } + /* falls through */ default: if (check === undefined) { check = [{ diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/foxxActiveView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/foxxActiveView.js index 24f2aa4f70..b7cd11468f 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/foxxActiveView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/foxxActiveView.js @@ -22,17 +22,17 @@ toggle: function(type, shouldShow) { switch (type) { case "devel": - if (this.model.get("development") === true) { + if (this.model.isDevelopment()) { this._show = shouldShow; } break; case "production": - if (this.model.get("development") === false && this.model.get("system") === false) { + if (!this.model.isDevelopment() && !this.model.isSystem()) { this._show = shouldShow; } break; case "system": - if (this.model.get("system") === true) { + if (this.model.isSystem()) { this._show = shouldShow; } break; diff --git a/js/apps/system/_admin/aardvark/APP/test/karma/files.json b/js/apps/system/_admin/aardvark/APP/test/karma/files.json index 5bd9dfec80..f5eb575b07 100755 --- a/js/apps/system/_admin/aardvark/APP/test/karma/files.json +++ b/js/apps/system/_admin/aardvark/APP/test/karma/files.json @@ -5,6 +5,7 @@ { "pattern": "clusterFrontend/js/templates/*.ejs", "served": true, "included": false, "watched": true}, "frontend/js/lib/jquery-2.1.0.min.js", "test/mocks/overwriteAjax.js", + "test/mocks/createDummy.js", "frontend/js/lib/jquery-ui-1.9.2.custom.js", "frontend/js/lib/jquery.autogrow.js", "frontend/js/lib/jquery.jeditable.js", @@ -248,6 +249,7 @@ "test/specs/views/apiViewSpec.js", "test/specs/views/applicationsViewSpec.js", + "test/specs/views/applicationDetailViewSpec.js", "test/specs/views/modalViewSpec.js", "test/specs/views/editListEntryViewSpec.js", "test/specs/views/collectionsViewSpec.js", diff --git a/js/apps/system/_admin/aardvark/APP/test/specs/collections/foxxCollectionSpec.js b/js/apps/system/_admin/aardvark/APP/test/specs/collections/foxxCollectionSpec.js index f4d5617d46..c3235d559d 100644 --- a/js/apps/system/_admin/aardvark/APP/test/specs/collections/foxxCollectionSpec.js +++ b/js/apps/system/_admin/aardvark/APP/test/specs/collections/foxxCollectionSpec.js @@ -30,6 +30,34 @@ expect(col.url).toEqual("/_admin/aardvark/foxxes"); }); + describe("sorting apps", function() { + var first, second, third; + beforeEach(function() { + first = "/_test"; + second = "/aal"; + third = "/zztop"; + col.add({mount: second}); + col.add({mount: third}); + col.add({mount: first}); + }); + + it("should always be by mount", function() { + col.sort(); + expect(col.models[0].get("mount")).toEqual(first); + expect(col.models[1].get("mount")).toEqual(second); + expect(col.models[2].get("mount")).toEqual(third); + }); + + it("should be by mount and reversable", function() { + col.setSortingDesc(true); + col.sort(); + expect(col.models[2].get("mount")).toEqual(first); + expect(col.models[1].get("mount")).toEqual(second); + expect(col.models[0].get("mount")).toEqual(third); + }); + + }); + describe("installing apps", function() { it("should generate an app", function() { diff --git a/js/apps/system/_admin/aardvark/APP/test/specs/views/applicationDetailViewSpec.js b/js/apps/system/_admin/aardvark/APP/test/specs/views/applicationDetailViewSpec.js index e5ea4c8860..7cc8c58ccd 100644 --- a/js/apps/system/_admin/aardvark/APP/test/specs/views/applicationDetailViewSpec.js +++ b/js/apps/system/_admin/aardvark/APP/test/specs/views/applicationDetailViewSpec.js @@ -194,6 +194,131 @@ }); + describe("with different configuration types", function() { + var valid1, valid3, valid4, def; + + beforeEach(function() { + runs(function() { + valid1 = "Value"; + valid3 = "4.5"; + valid4 = "4"; + def = "default"; + + config.data.opt1 = { + type: "string", + description: "My String" + }; + config.data.opt2 = { + type: "boolean", + description: "My Bool" + }; + config.data.opt3 = { + type: "number", + description: "My Number" + }; + config.data.opt4 = { + type: "integer", + description: "My Integer" + }; + config.data.opt5 = { + type: "string", + description: "My String", + default: def + }; + view.render(); + $(buttonId).click(); + }); + + waitsFor(function () { + return $("#modal-dialog").css("display") === "block"; + }, "The configure App dialog should be shown", 750); + }); + + it("should not allow to configure if the string is empty", function() { + $("#app_config_opt1").val(""); + $("#app_config_opt3").val(valid3); + $("#app_config_opt4").val(valid4); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should not allow to configure if the number is empty", function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val(""); + $("#app_config_opt4").val(valid4); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should not allow to configure if the number is invalid", function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val("invalid"); + $("#app_config_opt4").val(valid4); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should not allow to configure if the integer is empty", function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val(valid3); + $("#app_config_opt4").val(""); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should not allow to configure if the integer is invalid", function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val(valid3); + $("#app_config_opt4").val("invalid"); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should not allow to configure if the integer is not integer", function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val(valid3); + $("#app_config_opt4").val("4.5"); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeTruthy(); + }); + + it("should allow to configure if all values are valid", function() { + runs(function() { + $("#app_config_opt1").val(valid1); + $("#app_config_opt3").val(valid3); + $("#app_config_opt4").val(valid4); + $("#app_config_opt4").keyup(); + expect($("#modalButton1").prop("disabled")).toBeFalsy(); + spyOn(appDummy, "setConfiguration").andCallFake(function(data, callback) { + callback({ + error: false + }); + }); + $("#modalButton1").click(); + }); + + waitsFor(function () { + return $("#modal-dialog").css("display") === "none"; + }, "The configure App dialog should be hidden.", 750); + + runs(function() { + expect(appDummy.setConfiguration).toHaveBeenCalledWith( + { + opt1: valid1, + opt2: false, + opt3: 4.5, + opt4: 4, + opt5: def + }, + jasmine.any(Function) + ); + }); + + }); + + }); + + }); describe("if not required", function() { @@ -207,6 +332,9 @@ it("the button should be disabled", function() { expect($(buttonId).hasClass("disabled")).toEqual(true); + spyOn(window.modalView, "show"); + $(buttonId).click(); + expect(window.modalView.show).not.toHaveBeenCalled(); }); });