From 6863af9cd9f247691148fe5c176bc46bd963ee36 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 12:50:21 -0700 Subject: [PATCH] [Windowing] Comment/Formatting Reformatted code and added comments to the unit test. Also refined the NewTabActionSpec unit test to be clearer. WTD 16. --- .../browse/src/services/UrlService.js | 6 +++ .../browse/src/windowing/NewTabAction.js | 4 +- .../browse/test/services/UrlServiceSpec.js | 22 +++++++--- .../browse/test/windowing/NewTabActionSpec.js | 44 ++++++++++++------- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js index b227ab2c2f..e8b05c27be 100644 --- a/platform/commonUI/browse/src/services/UrlService.js +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -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; } diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 18fd4a7209..b9992a4cb9 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -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) { diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/browse/test/services/UrlServiceSpec.js index 1bba48bd8d..e6567c976e 100644 --- a/platform/commonUI/browse/test/services/UrlServiceSpec.js +++ b/platform/commonUI/browse/test/services/UrlServiceSpec.js @@ -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); }); }); } diff --git a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js index 986dcb832d..9698439642 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -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(); }); });