mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 20:28:14 +00:00
[urlService] CleanUp/Refactor
Adjusted BrowseController's useRoute to use the urlService instead. Also adds urlService as a depency through bundle. Unit test also adjusted to account for a mockUrlService and a different value being passed into mockLocation.path(). WTD 16.
This commit is contained in:
@ -16,7 +16,7 @@
|
|||||||
{
|
{
|
||||||
"key": "BrowseController",
|
"key": "BrowseController",
|
||||||
"implementation": "BrowseController.js",
|
"implementation": "BrowseController.js",
|
||||||
"depends": [ "$scope", "$route", "$location", "objectService", "navigationService" ]
|
"depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "BrowseObjectController",
|
"key": "BrowseObjectController",
|
||||||
|
@ -41,19 +41,13 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function BrowseController($scope, $route, $location, objectService, navigationService) {
|
function BrowseController($scope, $route, $location, objectService, navigationService, urlService) {
|
||||||
var path = [ROOT_ID].concat(
|
var path = [ROOT_ID].concat(
|
||||||
($route.current.params.ids || DEFAULT_PATH).split("/")
|
($route.current.params.ids || DEFAULT_PATH).split("/")
|
||||||
);
|
);
|
||||||
|
|
||||||
function updateRoute(domainObject) {
|
function updateRoute(domainObject) {
|
||||||
var context = domainObject &&
|
var priorRoute = $route.current,
|
||||||
domainObject.getCapability('context'),
|
|
||||||
objectPath = context ? context.getPath() : [],
|
|
||||||
ids = objectPath.map(function (domainObject) {
|
|
||||||
return domainObject.getId();
|
|
||||||
}),
|
|
||||||
priorRoute = $route.current,
|
|
||||||
// Act as if params HADN'T changed to avoid page reload
|
// Act as if params HADN'T changed to avoid page reload
|
||||||
unlisten;
|
unlisten;
|
||||||
|
|
||||||
@ -61,8 +55,10 @@ define(
|
|||||||
$route.current = priorRoute;
|
$route.current = priorRoute;
|
||||||
unlisten();
|
unlisten();
|
||||||
});
|
});
|
||||||
|
// urlService.urlFor used to adjust current
|
||||||
$location.path("/browse/" + ids.slice(1).join("/"));
|
// path to new, addressed, path based on
|
||||||
|
// domainObject
|
||||||
|
$location.path(urlService.urlFor("browse", domainObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback for updating the in-scope reference to the object
|
// Callback for updating the in-scope reference to the object
|
||||||
|
@ -36,6 +36,7 @@ define(
|
|||||||
mockObjectService,
|
mockObjectService,
|
||||||
mockNavigationService,
|
mockNavigationService,
|
||||||
mockRootObject,
|
mockRootObject,
|
||||||
|
mockUrlService,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockNextObject,
|
mockNextObject,
|
||||||
controller;
|
controller;
|
||||||
@ -58,6 +59,10 @@ define(
|
|||||||
"$location",
|
"$location",
|
||||||
[ "path" ]
|
[ "path" ]
|
||||||
);
|
);
|
||||||
|
mockUrlService = jasmine.createSpyObj(
|
||||||
|
"urlService",
|
||||||
|
["urlFor"]
|
||||||
|
);
|
||||||
mockObjectService = jasmine.createSpyObj(
|
mockObjectService = jasmine.createSpyObj(
|
||||||
"objectService",
|
"objectService",
|
||||||
[ "getObjects" ]
|
[ "getObjects" ]
|
||||||
@ -102,7 +107,8 @@ define(
|
|||||||
mockRoute,
|
mockRoute,
|
||||||
mockLocation,
|
mockLocation,
|
||||||
mockObjectService,
|
mockObjectService,
|
||||||
mockNavigationService
|
mockNavigationService,
|
||||||
|
mockUrlService
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,7 +118,8 @@ define(
|
|||||||
mockRoute,
|
mockRoute,
|
||||||
mockLocation,
|
mockLocation,
|
||||||
mockObjectService,
|
mockObjectService,
|
||||||
mockNavigationService
|
mockNavigationService,
|
||||||
|
mockUrlService
|
||||||
);
|
);
|
||||||
expect(mockNavigationService.setNavigation)
|
expect(mockNavigationService.setNavigation)
|
||||||
.toHaveBeenCalledWith(mockDomainObject);
|
.toHaveBeenCalledWith(mockDomainObject);
|
||||||
@ -125,7 +132,8 @@ define(
|
|||||||
mockRoute,
|
mockRoute,
|
||||||
mockLocation,
|
mockLocation,
|
||||||
mockObjectService,
|
mockObjectService,
|
||||||
mockNavigationService
|
mockNavigationService,
|
||||||
|
mockUrlService
|
||||||
);
|
);
|
||||||
expect(mockScope.navigatedObject).toBe(mockDomainObject);
|
expect(mockScope.navigatedObject).toBe(mockDomainObject);
|
||||||
});
|
});
|
||||||
@ -200,7 +208,8 @@ define(
|
|||||||
|
|
||||||
it("updates the displayed route to reflect current navigation", function () {
|
it("updates the displayed route to reflect current navigation", function () {
|
||||||
var mockContext = jasmine.createSpyObj('context', ['getPath']),
|
var mockContext = jasmine.createSpyObj('context', ['getPath']),
|
||||||
mockUnlisten = jasmine.createSpy('unlisten');
|
mockUnlisten = jasmine.createSpy('unlisten'),
|
||||||
|
mockMode = "browse";
|
||||||
|
|
||||||
mockContext.getPath.andReturn(
|
mockContext.getPath.andReturn(
|
||||||
[mockRootObject, mockDomainObject, mockNextObject]
|
[mockRootObject, mockDomainObject, mockNextObject]
|
||||||
@ -213,7 +222,11 @@ define(
|
|||||||
mockNavigationService.addListener.mostRecentCall.args[0](
|
mockNavigationService.addListener.mostRecentCall.args[0](
|
||||||
mockNextObject
|
mockNextObject
|
||||||
);
|
);
|
||||||
expect(mockLocation.path).toHaveBeenCalledWith("/browse/mine/next");
|
// location.path to be called with the urlService's
|
||||||
|
// urlFor function with the next domainObject and mode
|
||||||
|
expect(mockLocation.path).toHaveBeenCalledWith(
|
||||||
|
mockUrlService.urlFor(mockMode, mockNextObject)
|
||||||
|
);
|
||||||
|
|
||||||
// Exercise the Angular workaround
|
// Exercise the Angular workaround
|
||||||
mockScope.$on.mostRecentCall.args[1]();
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
|
Reference in New Issue
Block a user