-
Notifications
You must be signed in to change notification settings - Fork 0
/
activeSprintsControlerTest.js
149 lines (125 loc) · 4.49 KB
/
activeSprintsControlerTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
describe("controller: ActiveSprintsController", function () {
var $q, $scope, WsApi, controller, MockedUser, WsApi;
var initializeVariables = function () {
inject(function (_$q_, _WsApi_) {
$q = _$q_;
MockedUser = new mockUser($q);
WsApi = _WsApi_;
});
};
var initializeController = function (settings) {
inject(function (_$controller_, _$sce_, _$rootScope_, _ActiveSprintsService_, _StatusRepo_) {
$scope = _$rootScope_.$new();
sessionStorage.role = settings && settings.role ? settings.role : "ROLE_ADMIN";
sessionStorage.token = settings && settings.token ? settings.token : "faketoken";
controller = _$controller_("ActiveSprintsController", {
$scope: $scope,
$sce: _$sce_,
ActiveSprintsService: _ActiveSprintsService_,
StatusRepo: _StatusRepo_
});
// ensure that the isReady() is called.
if (!$scope.$$phase) {
$scope.$digest();
}
});
};
beforeEach(function () {
module("core");
module("app");
module("templates");
module("mock.activeSprintsService");
module("mock.statusRepo");
module("mock.user", function ($provide) {
var User = function () {
return MockedUser;
};
$provide.value("User", User);
});
module("mock.userService");
installPromiseMatchers();
initializeVariables();
initializeController();
});
describe("Is the controller", function () {
var roles = [ "ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER", "ROLE_ANONYMOUS" ];
var controllerExists = function (setting) {
return function() {
initializeController(setting);
expect(controller).toBeDefined();
};
};
for (var i in roles) {
it("defined for " + roles[i], controllerExists({ role: roles[i] }));
}
});
describe("Is the scope method", function () {
var methods = [
"select",
"kanbanHeader",
"getSprintEstimateTotal",
"getStatusEstimateTotal",
"getAvatarUrl",
"getHtmlContent",
"getPanelClass",
"getSelectedSprint"
];
var scopeMethodExists = function (method) {
return function() {
expect($scope[method]).toBeDefined();
expect(typeof $scope[method]).toEqual("function");
};
};
for (var i in methods) {
it(methods[i] + " defined", scopeMethodExists(methods[i]));
}
});
describe("Does the scope method", function () {
it("select set session storage to selected index", function () {
$scope.select(0);
expect(Number(sessionStorage.selected)).toEqual(0);
});
it("getSprintEstimateTotal get sprint total estimate", function () {
var total = $scope.getSprintEstimateTotal($scope.activeSprints[0]);
expect(total).toEqual(8.5);
});
it("getStatusEstimateTotal get status total estimate", function () {
$scope.select(0);
var total = $scope.getStatusEstimateTotal({
"id": 4,
"identifier": "Accepted",
"mapping": ["Accepted"]
});
expect(total).toEqual(8);
});
it("getAvatarUrl get the member avatar url", function () {
var avatarUrl = $scope.getAvatarUrl({
"id": "6616",
"name": "Ryan Laddusaw",
"avatar": "no_avatar.png"
});
// Tests are not loading the base href.
// An error message like "$location in HTML5 mode requires a <base> tag to be present" appears despite the index.html having a base path of '<base href="/products/">'.
// Remove the /products/ from the URL until such time the test process can be fixed.
// Adding the module("templates"); to load the templates above to load the HTML templates does not help any.
expect(avatarUrl).toEqual("http://localhost:9000/images/no_avatar.png");
});
it("getHtmlContent get trusted content", function () {
var html = "<span>Hello, World!</span>";
$scope.getHtmlContent(html);
});
it('getPanelClass return correct value', function () {
var featureClass = $scope.getPanelClass('Feature');
var defectClass = $scope.getPanelClass('Defect');
var otherClass = $scope.getPanelClass('anything else');
expect(featureClass).toEqual('panel-primary');
expect(defectClass).toEqual('panel-danger');
expect(otherClass).toEqual('panel-default');
});
it("getSelectedSprint get selected sprint", function () {
$scope.select(0);
var selectedSprint = $scope.getSelectedSprint();
expect(selectedSprint).toEqual($scope.activeSprints[0]);
});
});
});