From 93039615a0694e8a0376e551eda73bf457b0daeb Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 12 Apr 2013 10:43:05 +0200 Subject: [PATCH] GraphViewer: Added test for design of Toolbox --- .../specGraphViewer/graphViewerUISpec.js | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerUISpec.js b/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerUISpec.js index 3758e244e6..aa50a41f2d 100644 --- a/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerUISpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerUISpec.js @@ -56,11 +56,19 @@ toBeTag: function(name) { var el = this.actual; this.message = function() { - return el.tagName.toLowerCase() + " to be a " + name; + return "Expected " + el.tagName.toLowerCase() + " to be a " + name; }; return el.tagName.toLowerCase() === name; }, + toBeOfClass: function(name) { + var el = this.actual; + this.message = function() { + return "Expected " + el.className + " to be " + name; + }; + return el.className === name; + }, + toBeADropdownMenu: function() { var div = this.actual, btn = div.children[0], @@ -69,19 +77,9 @@ this.message = function() { return "Expected " + msg; }; - if (div.className !== "btn-group pull-right") { - msg = "div class to be \"btn-group pull-right\""; - return false; - } - // Check the toggle button - if (btn === undefined || btn.tagName.toLowerCase() !== "button") { - msg = "first element has to be a button"; - return false; - } - if (btn.getAttribute("class") !== "btn btn-inverse btn-small dropdown-toggle") { - msg = "first elements class to be \"btn btn-inverse btn-small dropdown-toggle\""; - return false; - } + expect(div).toBeOfClass("btn-group pull-right"); + expect(btn).toBeTag("button"); + expect(btn).toBeOfClass("btn btn-inverse btn-small dropdown-toggle"); if (btn.getAttribute("data-toggle") !== "dropdown") { msg = "first elements data-toggle to be dropdown"; return false; @@ -137,6 +135,23 @@ describe('checking the toolbox', function() { var toolboxSelector = "#contentDiv #toolbox"; + beforeEach(function() { + this.addMatchers({ + toConformToToolboxLayout: function() { + var box = this.actual; + expect(box).toBeTag("div"); + expect(box.id).toEqual("toolbox"); + expect(box).toBeOfClass("btn-group btn-group-vertical pull-left toolbox"); + _.each(box.children, function(group) { + expect(group).toBeTag("div"); + expect(group).toBeOfClass("btn btn-group"); + expect(group.children.length).toEqual(2); + // Correctness of buttons is checked in eventDispatcherUISpec. + }); + } + }); + }); + it('should append the toolbox', function() { expect($(toolboxSelector).length).toEqual(1); }); @@ -148,6 +163,11 @@ expect($(toolboxSelector + " #control_delete").length).toEqual(1); expect($(toolboxSelector + " #control_connect").length).toEqual(1); }); + + it('should have the correct layout', function() { + expect($(toolboxSelector)[0]).toConformToToolboxLayout(); + }); + }); describe('checking the menubar', function() { @@ -224,8 +244,8 @@ describe('set up with jsonAdapter and click Expand rest default', function() { - - var waittime = 100, + // This waittime is rather opcimistic, on a slow machine this has to be increased + var waittime = 100, clickOnNode = function(id) { helper.simulateMouseEvent("click", id);