mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Windowing] Comment/Formatting
Reformatted code and added comments to the unit test. Also refined the NewTabActionSpec unit test to be clearer. WTD 16.
This commit is contained in:
parent
13eef59e4f
commit
6863af9cd9
@ -47,8 +47,14 @@ define(
|
||||
return domainObject.getId();
|
||||
}),
|
||||
viewPath = "?view=" + $location.search().view,
|
||||
// Parses the path together. Starts with the
|
||||
// default index.html file, then the mode passed
|
||||
// into the service, followed by ids in the url
|
||||
// joined by '/', and lastly the view path from
|
||||
// the current location
|
||||
path = "index.html#/" + mode + "/" +
|
||||
ids.slice(1).join("/") + viewPath;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,7 @@ define(
|
||||
DEFAULT_PATH = "/mine";
|
||||
/**
|
||||
* The new tab action allows a domain object to be opened
|
||||
* into a new browser tab. (Currently this is a stub, present
|
||||
* to allow the control to appear in the appropriate location in
|
||||
* the user interface.)
|
||||
* into a new browser tab.
|
||||
* @constructor
|
||||
*/
|
||||
function NewTabAction(urlService, $window, context) {
|
||||
|
@ -30,12 +30,12 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The url service", function () {
|
||||
var mockUrl,
|
||||
mockUrlFor,
|
||||
urlService,
|
||||
var urlService,
|
||||
mockLocation;
|
||||
|
||||
beforeEach(function () {
|
||||
// Creates a mockLocation, used to
|
||||
// do the view search
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
[ "path", "search" ]
|
||||
@ -45,6 +45,9 @@ define(
|
||||
});
|
||||
|
||||
it("Get url for a domainObject and mode", function () {
|
||||
// The mockDomainObject is initialized as a
|
||||
// spy object to ultimately be passed into the
|
||||
// urlService urlFor function
|
||||
var mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability", "getModel", "useCapability" ]
|
||||
@ -54,22 +57,31 @@ define(
|
||||
{ key: 'abc' },
|
||||
{ key: 'def', someKey: 'some value' },
|
||||
{ key: 'xyz' }
|
||||
];
|
||||
],
|
||||
mockMode = "browse";
|
||||
|
||||
// The mockContext is set a path
|
||||
// for the mockDomainObject
|
||||
mockContext.getPath.andReturn(
|
||||
[mockDomainObject]
|
||||
);
|
||||
|
||||
// view capability used with the testviews made
|
||||
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||
return (c === 'view') && testViews;
|
||||
});
|
||||
|
||||
// context capability used with the mockContext created
|
||||
// so the variables including context in the urlFor are
|
||||
// initialized and reached
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
return c === 'context' && mockContext;
|
||||
});
|
||||
|
||||
// Uses the mockLocation to get the current
|
||||
// "mock" website's view
|
||||
mockLocation.search.andReturn({ view: 'def' });
|
||||
urlService.urlFor("browse", mockDomainObject);
|
||||
urlService.urlFor(mockMode, mockDomainObject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -27,38 +27,50 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The new tab action", function () {
|
||||
var action,
|
||||
action2,
|
||||
var actionSelected,
|
||||
actionCurrent,
|
||||
mockWindow,
|
||||
mockDomainObject,
|
||||
mockContext,
|
||||
mock2Context,
|
||||
mockContextCurrent,
|
||||
mockContextSelected,
|
||||
mockUrlService;
|
||||
|
||||
beforeEach(function () {
|
||||
// Creates a mockWindow from $window, then
|
||||
// the mockWindow's location.href is set
|
||||
// to a mock Url
|
||||
mockWindow = jasmine.createSpyObj("$window", ["open", "location"]);
|
||||
|
||||
mockContext = jasmine.createSpyObj("context", ["selectedObject",
|
||||
// Context if the current object is selected
|
||||
// For example, when the top right new tab
|
||||
// button is clicked, the user is using the
|
||||
// current domainObject
|
||||
mockContextCurrent = jasmine.createSpyObj("context", ["domainObject"]);
|
||||
|
||||
// Context if the selected object is selected
|
||||
// For example, when an object in the left
|
||||
// tree is opened in a new tab using the
|
||||
// context menu
|
||||
mockContextSelected = jasmine.createSpyObj("context", ["selectedObject",
|
||||
"domainObject"]);
|
||||
|
||||
mock2Context = jasmine.createSpyObj("context", ["domainObject"]);
|
||||
|
||||
// Mocks the urlService used to make the new tab's url from a
|
||||
// domainObject and mode
|
||||
mockUrlService = jasmine.createSpyObj("urlService", ["urlFor"]);
|
||||
|
||||
// Action done using the current context or mockContextCurrent
|
||||
actionCurrent = new NewTabAction(mockUrlService, mockWindow,
|
||||
mockContextCurrent);
|
||||
|
||||
action = new NewTabAction(mockUrlService, mockWindow, mockContext);
|
||||
action2 = new NewTabAction(mockUrlService, mockWindow, mock2Context);
|
||||
// Action done using the selected context or mockContextSelected
|
||||
actionSelected = new NewTabAction(mockUrlService, mockWindow,
|
||||
mockContextSelected);
|
||||
|
||||
});
|
||||
|
||||
it("New tab with current url is opened", function () {
|
||||
// The expection is that the mockWindow
|
||||
// will be called with it's location.href
|
||||
action.perform();
|
||||
action2.perform();
|
||||
actionCurrent.perform();
|
||||
});
|
||||
|
||||
it("New tab with a selected url is opened", function () {
|
||||
actionSelected.perform();
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user