2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 //describe('Controller: NewAdminCtrl ', () => {
42 // beforeEach(module('ecompApp'));
44 // //destroy $http default cache before starting to prevent the error 'default cache already exists'
45 // beforeEach(inject((_CacheFactory_)=> {
46 // _CacheFactory_.destroyAll();
50 // let newCtrl, $controller, $q, $rootScope, $log;
52 // beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {
53 // [$controller, $q, $rootScope, $log] = [_$controller_, _$q_, _$rootScope_, _$log_];
56 // let deferredUsersList, deferredAdminAppsRoles, deferredUpdateRolesRes;
57 // let usersServiceMock, adminsServiceMock;
59 // [deferredUsersList, deferredAdminAppsRoles, deferredUpdateRolesRes] = [$q.defer(), $q.defer(), $q.defer()];
61 // //usersServiceMock = jasmine.createSpyObj('usersServiceMock', ['searchUsers']);
62 // usersServiceMock = {
63 // searchUsers: () => {
64 // var promise = () => {return deferredUsersList.promise};
65 // var cancel = jasmine.createSpy();
73 // adminsServiceMock = jasmine.createSpyObj('adminsServiceMock', ['getAdminAppsRoles', 'updateAdminAppsRoles']);
75 // //usersServiceMock.searchUsers.and.returnValue(deferredUsersList.promise);
76 // adminsServiceMock.getAdminAppsRoles.and.returnValue(deferredAdminAppsRoles.promise);
77 // adminsServiceMock.updateAdminAppsRoles.and.returnValue(deferredUpdateRolesRes.promise);
79 // newCtrl = $controller('NewAdminModalCtrl', {
81 // usersService: usersServiceMock,
82 // adminsService: adminsServiceMock,
87 // it('should init default values when loading the controller', ()=> {
88 // //expect(newCtrl.searchUsersInProgress).toBe(false);
89 // expect(newCtrl.dialogState).toBe(1);
90 // expect(newCtrl.selectedUser).toBe(null);
93 // it('should populate retrieved users when search users service returns a list ', ()=> {
94 // //spyOn(usersServiceMock, 'searchUsers');
95 // let usersListRes = [{user: 1}, {user: 2}];
96 // newCtrl.searchUserString = 'some org user name';
97 // deferredUsersList.resolve(usersListRes);
98 // newCtrl.searchUsers();
99 // $rootScope.$apply();
101 // //expect(usersServiceMock.searchUsers).toHaveBeenCalledWith(newCtrl.searchUserString);
102 // expect(newCtrl.searchUsersResults).toEqual(usersListRes);
103 // expect(newCtrl.searchUsersInProgress).toBe(false);
106 // it('should log the error when search users fails', ()=> {
107 // spyOn($log, 'error');
108 // deferredUsersList.reject('oh snap!');
109 // newCtrl.searchUsers();
110 // $rootScope.$apply();
111 // expect($log.error).toHaveBeenCalled();
114 // it('should populate admin apps roles and move to the next screen when adminsService.getAdminAppsRoles succeeded', ()=> {
115 // let userApps = {appsRoles: [{id: 1, isAdmin: false}, {id: 2, isAdmin: true}]};
116 // deferredAdminAppsRoles.resolve(userApps);
118 // newCtrl.searchUsersInProgress = false;
119 // newCtrl.selectedUser = {orgUserId: 'orgUserId'};
121 // newCtrl.getAdminAppsRoles();
122 // $rootScope.$apply();
124 // expect(adminsServiceMock.getAdminAppsRoles).toHaveBeenCalledWith(newCtrl.selectedUser.orgUserId);
125 // expect(newCtrl.adminAppsRoles).toEqual(userApps.appsRoles);
126 // expect(newCtrl.dialogState).toBe(2);
129 // it('should log the error when adminsService.getAdminAppsRoles fails', ()=> {
130 // spyOn($log, 'error');
131 // deferredAdminAppsRoles.reject('some error');
133 // newCtrl.searchUsersInProgress = false;
134 // newCtrl.selectedUser = {orgUserId: 'orgUserId'};
136 // newCtrl.getAdminAppsRoles();
137 // $rootScope.$apply();
139 // expect($log.error).toHaveBeenCalled();
141 // it('should log the error when trying to getAdminAppsRoles without selecting user ', ()=> {
142 // spyOn($log, 'error');
144 // newCtrl.searchUsersInProgress = false;
145 // newCtrl.selectedUser = null;
147 // newCtrl.getAdminAppsRoles();
148 // $rootScope.$apply();
150 // expect($log.error).toHaveBeenCalled();
152 // //it('should setSelectedUser when choosing user', ()=> {
155 // //it('should set isAdmin as false when removing app from the administrated apps list', ()=> {
157 // it('should set isAdmin as true when adding app via the dropdown menu', ()=> {
158 // newCtrl.adminAppsRoles = [{id: 1, isAdmin: false},{id: 2, isAdmin: true}];
159 // //simulate UI change
160 // $rootScope.$apply('newAdmin.selectedNewApp = null');
161 // $rootScope.$apply('newAdmin.selectedNewApp = {id: 1, isAdmin: true}');
163 // expect(newCtrl.adminAppsRoles[0].isAdmin).toBe(true);
164 // expect(newCtrl.selectedNewApp).toBe(null);
167 // it('should close the modal when updating apps roles succeeded', ()=> {
168 // $rootScope.closeThisDialog = () => {};
169 // spyOn($rootScope,'closeThisDialog');
171 // newCtrl.selectedUser = {orgUserId: 'orgUserId'};
172 // newCtrl.adminAppsRoles = [{id: 1}];
174 // deferredUpdateRolesRes.resolve();
175 // newCtrl.updateAdminAppsRoles();
176 // $rootScope.$apply();
178 // expect(adminsServiceMock.updateAdminAppsRoles).toHaveBeenCalledWith({orgUserId: newCtrl.selectedUser.orgUserId, appsRoles: newCtrl.adminAppsRoles});
179 // expect($rootScope.closeThisDialog).toHaveBeenCalled();
181 // it('should log the error when updating apps roles fails', ()=> {
182 // newCtrl.selectedUser = {orgUserId: 'orgUserId'};
183 // newCtrl.adminAppsRoles = [{id: 1}];
185 // spyOn($log,'error');
186 // deferredUpdateRolesRes.reject();
187 // newCtrl.updateAdminAppsRoles();
188 // $rootScope.$apply();
189 // expect($log.error).toHaveBeenCalled();
191 // //it('should display the add admin dropdown when clicking the add button', ()=> {