From e5139f3e84bc097cdd5ec0f27c2e75b0cfd25fa5 Mon Sep 17 00:00:00 2001 From: Heiko Kernbach Date: Tue, 6 May 2014 14:45:43 +0200 Subject: [PATCH] 100% coverage of navigationView --- .../frontend/js/views/navigationView.js | 7 +- .../test/specs/views/modalViewSpec.js | 29 ++++ .../test/specs/views/navigationViewSpec.js | 128 +++++++++++++++++- 3 files changed, 156 insertions(+), 8 deletions(-) diff --git a/js/apps/system/aardvark/frontend/js/views/navigationView.js b/js/apps/system/aardvark/frontend/js/views/navigationView.js index ceaaa15c33..d5b6fe79ba 100644 --- a/js/apps/system/aardvark/frontend/js/views/navigationView.js +++ b/js/apps/system/aardvark/frontend/js/views/navigationView.js @@ -85,13 +85,12 @@ }, handleSelectNavigation: function () { - $("#arangoCollectionSelect").change(function () { - var navigateTo = $(this).find("option:selected").val(); - window.App.navigate(navigateTo, {trigger: true}); + var self = this; + $("#arangoCollectionSelect").change(function() { + self.navigateBySelect(); }); }, - selectMenuItem: function (menuItem) { $('.navlist li').removeClass('active'); if (menuItem) { diff --git a/js/apps/system/aardvark/test/specs/views/modalViewSpec.js b/js/apps/system/aardvark/test/specs/views/modalViewSpec.js index 76c2f57b44..ede95a4862 100644 --- a/js/apps/system/aardvark/test/specs/views/modalViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/modalViewSpec.js @@ -501,5 +501,34 @@ expect($.fn.click).toHaveBeenCalled(); }); + /*it("test focused button navigation (direction right)", function() { + + testee.enabledHotkey = false; + var btnObj = {}, + title = "Save", + buttons = [], + cbs = { + callback: function() { + } + }, + btn, + testShow = testee.show.bind(testee, "modalTable.ejs", "My Modal"); + + spyOn(cbs, "callback").andCallThrough(); + btnObj = testee.createSuccessButton(title, cbs.callback); + buttons.push(btnObj); + testShow(buttons); + btn = $(".button-" + btnObj.type, $(div)); + + spyOn($.fn, "next"); + spyOn($.fn, "is").andReturn(true); + + btn.focus(); + testee.navigateThroughButtons('right'); + expect($.fn.next).toHaveBeenCalled(); + + console.log(testee); + });*/ + }); }()); diff --git a/js/apps/system/aardvark/test/specs/views/navigationViewSpec.js b/js/apps/system/aardvark/test/specs/views/navigationViewSpec.js index b33c11bf2d..4ff9cd0cc8 100644 --- a/js/apps/system/aardvark/test/specs/views/navigationViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/navigationViewSpec.js @@ -79,7 +79,7 @@ beforeEach(function() { view = new window.NavigationView( - {userCollection : UserCollectionDummy, currentDB : window.currentDB} + {userCollection : UserCollectionDummy, currentDB : window.currentDB} ); view.render(); }); @@ -127,13 +127,132 @@ expect(window.App.navigate).toHaveBeenCalledWith("graph", {trigger: true}); }); + it("should handle selected database render", function() { + spyOn(view.dbSelectionView, "render"); + view.handleSelectDatabase(); + expect(view.dbSelectionView.render).toHaveBeenCalled(); + }); + + it("should navigate to the selected value from options div", function() { + var toNavigate = "#collections" + $("#arangoCollectionSelect").val(toNavigate); + view.navigateBySelect(); + expect(window.App.navigate).toHaveBeenCalledWith(toNavigate, {trigger: true}); + }); + + it("should navigate automatic to the selected value from options div", function() { + spyOn($.fn, "change").andCallFake(function(a){ + a(); + }); + spyOn(view, "navigateBySelect"); + view.handleSelectNavigation(); + expect($.fn.change).toHaveBeenCalledWith(jasmine.any(Function)); + expect(view.navigateBySelect).toHaveBeenCalled(); + }); + + it("should render selectMenuItems correctly", function() { + var entry = "tools-menu"; + view.selectMenuItem(entry); + var toBeActiveClass = $('.' + entry); + var toBeFalseClass1 = $('.' + "graphviewer-menu"); + var toBeFalseClass2 = $('.' + "databases-menu"); + var toBeFalseClass3 = $('.' + "query-menu"); + var toBeFalseClass4 = $('.' + "collections-menu"); + var toBeFalseClass5 = $('.' + "applications-menu"); + expect(toBeActiveClass.hasClass("active")).toBeTruthy(); + expect(toBeFalseClass1.hasClass("active")).toBeFalsy(); + expect(toBeFalseClass2.hasClass("active")).toBeFalsy(); + expect(toBeFalseClass3.hasClass("active")).toBeFalsy(); + expect(toBeFalseClass4.hasClass("active")).toBeFalsy(); + expect(toBeFalseClass5.hasClass("active")).toBeFalsy(); + }); + + it("should show dropdown for menu item: links", function() { + var e = { + target: { + id: "links" + } + }; + spyOn($.fn, "show"); + view.showDropdown(e); + expect($.fn.show).toHaveBeenCalledWith(200); + }); + + it("should show dropdown for menu item: tools", function() { + var e = { + target: { + id: "tools" + } + }; + spyOn($.fn, "show"); + view.showDropdown(e); + expect($.fn.show).toHaveBeenCalledWith(200); + }); + + it("should show dropdown for menu item: dbselection", function() { + var e = { + target: { + id: "dbselection" + } + }; + spyOn($.fn, "show"); + view.showDropdown(e); + expect($.fn.show).toHaveBeenCalledWith(200); + }); + + it("should hide dropdown for menu item: linkDropdown", function() { + spyOn($.fn, "hide"); + $('#linkDropdown').mouseenter().mouseleave(); + expect($.fn.hide).toHaveBeenCalled(); + }); + + it("should hide dropdown for menu item: toolsDropdown", function() { + spyOn($.fn, "hide"); + $('#toolsDropdown').mouseenter().mouseleave(); + expect($.fn.hide).toHaveBeenCalled(); + }); + + it("should hide dropdown for menu item: dbSelect", function() { + spyOn($.fn, "hide"); + $('#dbSelect').mouseenter().mouseleave(); + expect($.fn.hide).toHaveBeenCalled(); + }); + + it("should navigateByTab: tools", function() { + spyOn($.fn, "slideToggle"); + $('#tools').click(); + expect($.fn.slideToggle).toHaveBeenCalled(); + }); + + it("should navigateByTab: links", function() { + spyOn($.fn, "slideToggle"); + $('#links').click(); + expect($.fn.slideToggle).toHaveBeenCalled(); + }); + + it("should navigateByTab: dbSelection", function() { + $('#tools').attr("id", "dbselection"); + spyOn($.fn, "slideToggle"); + $('#dbselection').click(); + expect($.fn.slideToggle).toHaveBeenCalled(); + $('#dbselection').attr("id", "tools"); + }); + + it("should navigateByTab: blank", function() { + $('#tools').attr("id", ""); + $('#links').attr("id", ""); + spyOn($.fn, "attr"); + $('.tab').click(); + expect($.fn.attr).toHaveBeenCalled(); + }); + }); describe("in _system database", function() { beforeEach(function() { view = new window.NavigationView( - {userCollection : UserCollectionDummy, currentDB : window.currentDB} + {userCollection : UserCollectionDummy, currentDB : window.currentDB} ); view.render(); }); @@ -152,11 +271,11 @@ curName = "firstDB"; isSystem = false; view = new window.NavigationView( - {userCollection : UserCollectionDummy, currentDB : window.currentDB} + {userCollection : UserCollectionDummy, currentDB : window.currentDB} ); view.render(); }); - + it("should not offer a logs tab", function() { var tab = $("#logs", $(div)); expect(tab.length).toEqual(0); @@ -165,4 +284,5 @@ }); + }());