[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
}
],
"constants": [
{
"key": "DEFAULT_PATH",
"value": "mine",
"priority": "fallback"
}
],
"controllers": [
{
"key": "BrowseController",
@ -22,7 +29,8 @@
"$location",
"objectService",
"navigationService",
"urlService"
"urlService",
"DEFAULT_PATH"
]
},
{

View File

@ -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) {

View File

@ -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);