[Browse] Specify default selection in a constant

https://github.com/nasa/openmctweb/issues/401
This commit is contained in:
Victor Woeltjen 2015-12-11 12:31:06 -08:00
parent 89a93e2966
commit 5f7f349f29
3 changed files with 45 additions and 54 deletions

View File

@ -12,6 +12,13 @@
"reloadOnSearch": false "reloadOnSearch": false
} }
], ],
"constants": [
{
"key": "DEFAULT_PATH",
"value": "mine",
"priority": "fallback"
}
],
"controllers": [ "controllers": [
{ {
"key": "BrowseController", "key": "BrowseController",
@ -22,7 +29,8 @@
"$location", "$location",
"objectService", "objectService",
"navigationService", "navigationService",
"urlService" "urlService",
"DEFAULT_PATH"
] ]
}, },
{ {

View File

@ -30,8 +30,7 @@ define(
function () { function () {
"use strict"; "use strict";
var ROOT_ID = "ROOT", var ROOT_ID = "ROOT";
DEFAULT_PATH = "mine";
/** /**
* The BrowseController is used to populate the initial scope in Browse * The BrowseController is used to populate the initial scope in Browse
@ -43,9 +42,17 @@ define(
* @memberof platform/commonUI/browse * @memberof platform/commonUI/browse
* @constructor * @constructor
*/ */
function BrowseController($scope, $route, $location, objectService, navigationService, urlService) { function BrowseController(
$scope,
$route,
$location,
objectService,
navigationService,
urlService,
defaultPath
) {
var path = [ROOT_ID].concat( var path = [ROOT_ID].concat(
($route.current.params.ids || DEFAULT_PATH).split("/") ($route.current.params.ids || defaultPath).split("/")
); );
function updateRoute(domainObject) { function updateRoute(domainObject) {

View File

@ -39,6 +39,7 @@ define(
mockUrlService, mockUrlService,
mockDomainObject, mockDomainObject,
mockNextObject, mockNextObject,
testDefaultRoot,
controller; controller;
function mockPromise(value) { function mockPromise(value) {
@ -49,7 +50,21 @@ define(
}; };
} }
function instantiateController() {
controller = new BrowseController(
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService,
mockUrlService,
testDefaultRoot
);
}
beforeEach(function () { beforeEach(function () {
testDefaultRoot = "some-root-level-domain-object";
mockScope = jasmine.createSpyObj( mockScope = jasmine.createSpyObj(
"$scope", "$scope",
[ "$on", "$watch" ] [ "$on", "$watch" ]
@ -100,41 +115,20 @@ define(
])); ]));
mockNextObject.useCapability.andReturn(undefined); mockNextObject.useCapability.andReturn(undefined);
mockNextObject.getId.andReturn("next"); mockNextObject.getId.andReturn("next");
mockDomainObject.getId.andReturn("mine"); mockDomainObject.getId.andReturn(testDefaultRoot);
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService,
mockUrlService
);
}); });
it("uses composition to set the navigated object, if there is none", function () { it("uses composition to set the navigated object, if there is none", function () {
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService,
mockUrlService
);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDomainObject); .toHaveBeenCalledWith(mockDomainObject);
}); });
it("does not try to override navigation", function () { it("does not try to override navigation", function () {
mockNavigationService.getNavigation.andReturn(mockDomainObject); mockNavigationService.getNavigation.andReturn(mockDomainObject);
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService,
mockUrlService
);
expect(mockScope.navigatedObject).toBe(mockDomainObject); expect(mockScope.navigatedObject).toBe(mockDomainObject);
}); });
@ -161,14 +155,8 @@ define(
}); });
it("uses route parameters to choose initially-navigated object", function () { it("uses route parameters to choose initially-navigated object", function () {
mockRoute.current.params.ids = "mine/next"; mockRoute.current.params.ids = testDefaultRoot + "/next";
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService
);
expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockScope.navigatedObject).toBe(mockNextObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockNextObject); .toHaveBeenCalledWith(mockNextObject);
@ -178,14 +166,8 @@ define(
// Idea here is that if we get a bad path of IDs, // Idea here is that if we get a bad path of IDs,
// browse controller should traverse down it until // browse controller should traverse down it until
// it hits an invalid ID. // it hits an invalid ID.
mockRoute.current.params.ids = "mine/junk"; mockRoute.current.params.ids = testDefaultRoot + "/junk";
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService
);
expect(mockScope.navigatedObject).toBe(mockDomainObject); expect(mockScope.navigatedObject).toBe(mockDomainObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDomainObject); .toHaveBeenCalledWith(mockDomainObject);
@ -195,14 +177,8 @@ define(
// Idea here is that if we get a path which passes // Idea here is that if we get a path which passes
// through an object without a composition, browse controller // through an object without a composition, browse controller
// should stop at it since remaining IDs cannot be loaded. // should stop at it since remaining IDs cannot be loaded.
mockRoute.current.params.ids = "mine/next/junk"; mockRoute.current.params.ids = testDefaultRoot + "/next/junk";
controller = new BrowseController( instantiateController();
mockScope,
mockRoute,
mockLocation,
mockObjectService,
mockNavigationService
);
expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockScope.navigatedObject).toBe(mockNextObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockNextObject); .toHaveBeenCalledWith(mockNextObject);