Skip to content

Commit 60d1b73

Browse files
author
Pete Richards
committed
Update tests and correct style
Update tests to reflect new functionality. Closes nasa#1360
1 parent 96c0544 commit 60d1b73

File tree

10 files changed

+170
-336
lines changed

10 files changed

+170
-336
lines changed

platform/commonUI/browse/src/navigation/NavigateAction.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ define(
4444
* navigation has been updated
4545
*/
4646
NavigateAction.prototype.perform = function () {
47-
var self = this,
48-
navigateTo = this.domainObject,
49-
currentObject = self.navigationService.getNavigation();
50-
5147
if (this.navigationService.shouldNavigate()) {
5248
this.navigationService.setNavigation(this.domainObject, true);
5349
return Promise.resolve({});

platform/commonUI/browse/test/BrowseControllerSpec.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
2525
*/
2626
define(
27-
["../src/BrowseController"],
28-
function (BrowseController) {
27+
[
28+
"../src/BrowseController",
29+
"../src/navigation/NavigationService"
30+
],
31+
function (
32+
BrowseController,
33+
NavigationService
34+
) {
2935

3036
describe("The browse controller", function () {
3137
var mockScope,
@@ -44,7 +50,7 @@ define(
4450
function waitsForNavigation() {
4551
var calls = mockNavigationService.setNavigation.calls.length;
4652
waitsFor(function () {
47-
return mockNavigationService.setNavigation.calls.length > calls ;
53+
return mockNavigationService.setNavigation.calls.length > calls;
4854
});
4955
}
5056

@@ -92,15 +98,16 @@ define(
9298
"objectService",
9399
["getObjects"]
94100
);
95-
mockNavigationService = jasmine.createSpyObj(
96-
"navigationService",
97-
[
98-
"getNavigation",
99-
"setNavigation",
100-
"addListener",
101-
"removeListener"
102-
]
103-
);
101+
mockNavigationService = new NavigationService({});
102+
[
103+
"getNavigation",
104+
"setNavigation",
105+
"addListener",
106+
"removeListener"
107+
].forEach(function (method) {
108+
spyOn(mockNavigationService, method)
109+
.andCallThrough();
110+
});
104111
mockRootObject = jasmine.createSpyObj(
105112
"rootObjectContainer",
106113
["getId", "getCapability", "getModel", "useCapability", "hasCapability"]

platform/commonUI/browse/test/navigation/NavigateActionSpec.js

Lines changed: 64 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -23,145 +23,74 @@
2323
/**
2424
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
2525
*/
26-
define(
27-
["../../src/navigation/NavigateAction"],
28-
function (NavigateAction) {
29-
30-
describe("The navigate action", function () {
31-
var mockNavigationService,
32-
mockQ,
33-
mockDomainObject,
34-
mockPolicyService,
35-
mockNavigatedObject,
36-
mockWindow,
37-
capabilities,
38-
action;
39-
40-
function mockPromise(value) {
41-
return {
42-
then: function (callback) {
43-
return mockPromise(callback(value));
44-
}
45-
};
46-
}
47-
48-
beforeEach(function () {
49-
capabilities = {};
50-
51-
mockQ = { when: mockPromise };
52-
mockNavigatedObject = jasmine.createSpyObj(
53-
"domainObject",
54-
[
55-
"getId",
56-
"getModel",
57-
"hasCapability",
58-
"getCapability"
59-
]
60-
);
61-
62-
capabilities.editor = jasmine.createSpyObj("editorCapability", [
63-
"isEditContextRoot",
64-
"finish"
65-
]);
66-
67-
mockNavigatedObject.getCapability.andCallFake(function (capability) {
68-
return capabilities[capability];
69-
});
70-
mockNavigatedObject.hasCapability.andReturn(false);
71-
72-
mockNavigationService = jasmine.createSpyObj(
73-
"navigationService",
74-
[
75-
"setNavigation",
76-
"getNavigation"
77-
]
78-
);
79-
mockNavigationService.getNavigation.andReturn(mockNavigatedObject);
80-
81-
mockDomainObject = jasmine.createSpyObj(
82-
"domainObject",
83-
[
84-
"getId",
85-
"getModel"
86-
]
87-
);
88-
89-
mockPolicyService = jasmine.createSpyObj("policyService",
90-
[
91-
"allow"
92-
]);
93-
mockWindow = jasmine.createSpyObj("$window",
94-
[
95-
"confirm"
96-
]);
97-
98-
action = new NavigateAction(
99-
mockNavigationService,
100-
mockQ,
101-
mockPolicyService,
102-
mockWindow,
103-
{ domainObject: mockDomainObject }
104-
);
105-
});
106-
107-
it("invokes the policy service to determine if navigation" +
108-
" allowed", function () {
109-
action.perform();
110-
expect(mockPolicyService.allow)
111-
.toHaveBeenCalledWith("navigation", jasmine.any(Object), jasmine.any(Object), jasmine.any(Function));
112-
});
113-
114-
it("prompts user if policy rejection", function () {
115-
action.perform();
116-
expect(mockPolicyService.allow).toHaveBeenCalled();
117-
mockPolicyService.allow.mostRecentCall.args[3]();
118-
expect(mockWindow.confirm).toHaveBeenCalled();
119-
});
120-
121-
describe("shows a prompt", function () {
122-
beforeEach(function () {
123-
// Ensure the allow callback is called synchronously
124-
mockPolicyService.allow.andCallFake(function () {
125-
return arguments[3]();
126-
});
127-
});
128-
it("does not navigate on prompt rejection", function () {
129-
mockWindow.confirm.andReturn(false);
130-
action.perform();
131-
expect(mockNavigationService.setNavigation)
132-
.not.toHaveBeenCalled();
133-
});
134-
135-
it("does navigate on prompt acceptance", function () {
136-
mockWindow.confirm.andReturn(true);
137-
action.perform();
138-
expect(mockNavigationService.setNavigation)
139-
.toHaveBeenCalled();
140-
});
26+
define([
27+
"../../src/navigation/NavigateAction"
28+
], function (
29+
NavigateAction
30+
) {
31+
32+
describe("The navigate action", function () {
33+
var mockNavigationService,
34+
mockDomainObject,
35+
action;
36+
37+
38+
function waitForCall() {
39+
var called = false;
40+
waitsFor(function () {
41+
return called;
14142
});
43+
return function () {
44+
called = true;
45+
};
46+
}
47+
48+
beforeEach(function () {
49+
mockNavigationService = jasmine.createSpyObj(
50+
"navigationService",
51+
[
52+
"shouldNavigate",
53+
"setNavigation"
54+
]
55+
);
56+
57+
mockDomainObject = {};
58+
59+
action = new NavigateAction(
60+
mockNavigationService,
61+
{ domainObject: mockDomainObject }
62+
);
63+
});
14264

143-
describe("in edit mode", function () {
144-
beforeEach(function () {
145-
mockNavigatedObject.hasCapability.andCallFake(function (capability) {
146-
return capability === "editor";
147-
});
148-
capabilities.editor.isEditContextRoot.andReturn(true);
149-
});
150-
151-
it("finishes editing if in edit mode", function () {
152-
action.perform();
153-
expect(capabilities.editor.finish)
154-
.toHaveBeenCalled();
155-
});
65+
it("sets navigation if it is allowed", function () {
66+
mockNavigationService.shouldNavigate.andReturn(true);
67+
action.perform()
68+
.then(waitForCall());
69+
runs(function () {
70+
expect(mockNavigationService.setNavigation)
71+
.toHaveBeenCalledWith(mockDomainObject, true);
15672
});
73+
});
15774

158-
it("is only applicable when a domain object is in context", function () {
159-
expect(NavigateAction.appliesTo({})).toBeFalsy();
160-
expect(NavigateAction.appliesTo({
161-
domainObject: mockDomainObject
162-
})).toBeTruthy();
75+
it("does not set navigation if it is not allowed", function () {
76+
mockNavigationService.shouldNavigate.andReturn(false);
77+
var onSuccess = jasmine.createSpy('onSuccess');
78+
action.perform()
79+
.then(onSuccess, waitForCall());
80+
runs(function () {
81+
expect(onSuccess).not.toHaveBeenCalled();
82+
expect(mockNavigationService.setNavigation)
83+
.not
84+
.toHaveBeenCalledWith(mockDomainObject);
16385
});
86+
});
16487

88+
it("is only applicable when a domain object is in context", function () {
89+
expect(NavigateAction.appliesTo({})).toBeFalsy();
90+
expect(NavigateAction.appliesTo({
91+
domainObject: mockDomainObject
92+
})).toBeTruthy();
16593
});
166-
}
167-
);
94+
95+
});
96+
});

platform/commonUI/browse/test/navigation/NavigationServiceSpec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ define(
2828
function (NavigationService) {
2929

3030
describe("The navigation service", function () {
31-
var navigationService;
31+
var $window,
32+
navigationService;
3233

3334
beforeEach(function () {
34-
navigationService = new NavigationService();
35+
$window = jasmine.createSpyObj('$window', ['confirm']);
36+
navigationService = new NavigationService($window);
3537
});
3638

3739
it("stores navigation state", function () {

platform/commonUI/edit/src/controllers/EditObjectController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ define(
7070
cancelEditing(domainObject);
7171
});
7272

73-
function setViewForDomainObject(domainObject) {
73+
function setViewForDomainObject() {
7474

7575
var locationViewKey = $location.search().view;
7676

@@ -87,7 +87,7 @@ define(
8787
}
8888
}
8989

90-
setViewForDomainObject($scope.domainObject);
90+
setViewForDomainObject();
9191

9292
$scope.doAction = function (action) {
9393
return $scope[action] && $scope[action]();

0 commit comments

Comments
 (0)