From bdf8b4d3f11fd57c65e8a9b088caf90f586a35fb Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 29 Jul 2015 13:22:47 -0700 Subject: [PATCH] [Mobile] Test for Back Arrow Added tests for the backarrow and when it appears/disappears. --- .../browse/test/BrowseControllerSpec.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index 181121574a..658a08d5aa 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -245,14 +245,78 @@ define( ); }); + it("checks if the user is current navigated to the root", function () { + var mockContext = jasmine.createSpyObj('context', ['getParent']), + mockParentContext = jasmine.createSpyObj('context', ['getParent']), + mockParent = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ), + mockGrandparent = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ); + mockNavigationService = jasmine.createSpyObj( + "navigationService", + [ + "getNavigation", + "setNavigation", + "addListener", + "removeListener" + ] + ); + + mockRoute.current.params.ids = "ROOT/mine"; + mockParent.getId.andReturn("ROOT"); + + mockDomainObject.getCapability.andCallFake(function (c) { + return c === 'context' && mockContext; + }); + + mockNavigationService.getNavigation.andReturn(mockDomainObject); + mockContext.getParent.andReturn(mockParent); + mockParent.getCapability.andCallFake(function (c) { + return c === 'context' && mockParentContext; + }); + mockParentContext.getParent.andReturn(mockGrandparent); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + + mockScope.checkRoot(); + + mockRoute.current.params.ids = "mine/junk"; + mockParent.getId.andReturn("mine"); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + + mockScope.checkRoot(); + }); + // Mocks the back arrow call that // lets the html code know the back // arrow navigation needs to be done it("calls the backArrow function", function () { var mockContext = jasmine.createSpyObj('context', ['getParent']), + mockParentContext = jasmine.createSpyObj('context', ['getParent']), mockParent = jasmine.createSpyObj( "domainObject", [ "getId", "getCapability", "getModel", "useCapability" ] + ), + mockGrandparent = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] ); mockNavigationService = jasmine.createSpyObj( "navigationService", @@ -273,6 +337,36 @@ define( mockNavigationService.getNavigation.andReturn(mockDomainObject); mockContext.getParent.andReturn(mockParent); + mockParent.getCapability.andCallFake(function (c) { + return c === 'context' && mockParentContext; + }); + mockParentContext.getParent.andReturn(mockGrandparent); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + + mockScope.backArrow(); + + mockRoute.current.params.ids = "mine/lessjunk/morejunk"; + mockGrandparent.getId.andReturn("mine"); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + + mockScope.backArrow(); + + mockRoute.current.params.ids = "ROOT/mine"; + mockParent.getId.andReturn("ROOT"); controller = new BrowseController( mockScope,