From 5f7f349f29e3e707039501262ab6e1986dca82d7 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 11 Dec 2015 12:31:06 -0800 Subject: [PATCH] [Browse] Specify default selection in a constant https://github.com/nasa/openmctweb/issues/401 --- platform/commonUI/browse/bundle.json | 10 ++- .../commonUI/browse/src/BrowseController.js | 15 +++- .../browse/test/BrowseControllerSpec.js | 74 +++++++------------ 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index e290f296ff..c74c177769 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -12,6 +12,13 @@ "reloadOnSearch": false } ], + "constants": [ + { + "key": "DEFAULT_PATH", + "value": "mine", + "priority": "fallback" + } + ], "controllers": [ { "key": "BrowseController", @@ -22,7 +29,8 @@ "$location", "objectService", "navigationService", - "urlService" + "urlService", + "DEFAULT_PATH" ] }, { diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index 8c032f7de3..243ce16e5b 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -30,8 +30,7 @@ define( function () { "use strict"; - var ROOT_ID = "ROOT", - DEFAULT_PATH = "mine"; + var ROOT_ID = "ROOT"; /** * The BrowseController is used to populate the initial scope in Browse @@ -43,9 +42,17 @@ define( * @memberof platform/commonUI/browse * @constructor */ - function BrowseController($scope, $route, $location, objectService, navigationService, urlService) { + function BrowseController( + $scope, + $route, + $location, + objectService, + navigationService, + urlService, + defaultPath + ) { var path = [ROOT_ID].concat( - ($route.current.params.ids || DEFAULT_PATH).split("/") + ($route.current.params.ids || defaultPath).split("/") ); function updateRoute(domainObject) { diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index 7b8aab90fa..70447f4a80 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -39,6 +39,7 @@ define( mockUrlService, mockDomainObject, mockNextObject, + testDefaultRoot, controller; function mockPromise(value) { @@ -49,7 +50,21 @@ define( }; } + function instantiateController() { + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService, + mockUrlService, + testDefaultRoot + ); + } + beforeEach(function () { + testDefaultRoot = "some-root-level-domain-object"; + mockScope = jasmine.createSpyObj( "$scope", [ "$on", "$watch" ] @@ -100,41 +115,20 @@ define( ])); mockNextObject.useCapability.andReturn(undefined); mockNextObject.getId.andReturn("next"); - mockDomainObject.getId.andReturn("mine"); + mockDomainObject.getId.andReturn(testDefaultRoot); - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService - ); + instantiateController(); }); it("uses composition to set the navigated object, if there is none", function () { - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService - ); + instantiateController(); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockDomainObject); }); it("does not try to override navigation", function () { mockNavigationService.getNavigation.andReturn(mockDomainObject); - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService - ); + instantiateController(); expect(mockScope.navigatedObject).toBe(mockDomainObject); }); @@ -161,14 +155,8 @@ define( }); it("uses route parameters to choose initially-navigated object", function () { - mockRoute.current.params.ids = "mine/next"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); + mockRoute.current.params.ids = testDefaultRoot + "/next"; + instantiateController(); expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockNextObject); @@ -178,14 +166,8 @@ define( // Idea here is that if we get a bad path of IDs, // browse controller should traverse down it until // it hits an invalid ID. - mockRoute.current.params.ids = "mine/junk"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); + mockRoute.current.params.ids = testDefaultRoot + "/junk"; + instantiateController(); expect(mockScope.navigatedObject).toBe(mockDomainObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockDomainObject); @@ -195,14 +177,8 @@ define( // Idea here is that if we get a path which passes // through an object without a composition, browse controller // should stop at it since remaining IDs cannot be loaded. - mockRoute.current.params.ids = "mine/next/junk"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); + mockRoute.current.params.ids = testDefaultRoot + "/next/junk"; + instantiateController(); expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockNextObject);