Replace ecomp references
[portal.git] / ecomp-portal-FE-common / client / app / directives / search-users / search-users.controller.spec.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 //'use strict';
40 //
41 //describe('Controller: NewAdminCtrl ', () => {
42 //    beforeEach(module('ecompApp'));
43 //
44 //    //destroy $http default cache before starting to prevent the error 'default cache already exists'
45 //    beforeEach(inject((_CacheFactory_)=> {
46 //        _CacheFactory_.destroyAll();
47 //    }));
48 //
49 //
50 //    let newCtrl, $controller, $q, $rootScope, $log;
51 //
52 //    beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {
53 //        [$controller, $q, $rootScope, $log] = [_$controller_, _$q_, _$rootScope_, _$log_];
54 //    }));
55 //
56 //    let deferredUsersList, deferredAdminAppsRoles, deferredUpdateRolesRes;
57 //    let usersServiceMock, adminsServiceMock;
58 //    beforeEach(()=> {
59 //        [deferredUsersList, deferredAdminAppsRoles, deferredUpdateRolesRes] = [$q.defer(), $q.defer(), $q.defer()];
60 //
61 //        //usersServiceMock = jasmine.createSpyObj('usersServiceMock', ['searchUsers']);
62 //        usersServiceMock = {
63 //            searchUsers: () => {
64 //                var promise = () => {return deferredUsersList.promise};
65 //                var cancel = jasmine.createSpy();
66 //                return {
67 //                    promise: promise,
68 //                    cancel: cancel
69 //                }
70 //            }
71 //        };
72 //
73 //        adminsServiceMock = jasmine.createSpyObj('adminsServiceMock', ['getAdminAppsRoles', 'updateAdminAppsRoles']);
74 //
75 //        //usersServiceMock.searchUsers.and.returnValue(deferredUsersList.promise);
76 //        adminsServiceMock.getAdminAppsRoles.and.returnValue(deferredAdminAppsRoles.promise);
77 //        adminsServiceMock.updateAdminAppsRoles.and.returnValue(deferredUpdateRolesRes.promise);
78 //
79 //        newCtrl = $controller('NewAdminModalCtrl', {
80 //            $log: $log,
81 //            usersService: usersServiceMock,
82 //            adminsService: adminsServiceMock,
83 //            $scope: $rootScope
84 //        });
85 //    });
86 //
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);
91 //    });
92 //
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();
100 //
101 //        //expect(usersServiceMock.searchUsers).toHaveBeenCalledWith(newCtrl.searchUserString);
102 //        expect(newCtrl.searchUsersResults).toEqual(usersListRes);
103 //        expect(newCtrl.searchUsersInProgress).toBe(false);
104 //    });
105 //
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();
112 //    });
113 //
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);
117 //
118 //        newCtrl.searchUsersInProgress = false;
119 //        newCtrl.selectedUser = {orgUserId: 'orgUserId'};
120 //
121 //        newCtrl.getAdminAppsRoles();
122 //        $rootScope.$apply();
123 //
124 //        expect(adminsServiceMock.getAdminAppsRoles).toHaveBeenCalledWith(newCtrl.selectedUser.orgUserId);
125 //        expect(newCtrl.adminAppsRoles).toEqual(userApps.appsRoles);
126 //        expect(newCtrl.dialogState).toBe(2);
127 //    });
128 //
129 //    it('should  log the error when adminsService.getAdminAppsRoles fails', ()=> {
130 //        spyOn($log, 'error');
131 //        deferredAdminAppsRoles.reject('some error');
132 //
133 //        newCtrl.searchUsersInProgress = false;
134 //        newCtrl.selectedUser = {orgUserId: 'orgUserId'};
135 //
136 //        newCtrl.getAdminAppsRoles();
137 //        $rootScope.$apply();
138 //
139 //        expect($log.error).toHaveBeenCalled();
140 //    });
141 //    it('should  log the error when trying to getAdminAppsRoles without selecting user ', ()=> {
142 //        spyOn($log, 'error');
143 //
144 //        newCtrl.searchUsersInProgress = false;
145 //        newCtrl.selectedUser = null;
146 //
147 //        newCtrl.getAdminAppsRoles();
148 //        $rootScope.$apply();
149 //
150 //        expect($log.error).toHaveBeenCalled();
151 //    });
152 //    //it('should setSelectedUser when choosing user', ()=> {
153 //    //
154 //    //});
155 //    //it('should set isAdmin as false when removing app from the administrated apps list', ()=> {
156 //    //});
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}');
162 //
163 //        expect(newCtrl.adminAppsRoles[0].isAdmin).toBe(true);
164 //        expect(newCtrl.selectedNewApp).toBe(null);
165 //    });
166 //
167 //    it('should close the modal when updating apps roles succeeded', ()=> {
168 //        $rootScope.closeThisDialog = () => {};
169 //        spyOn($rootScope,'closeThisDialog');
170 //
171 //        newCtrl.selectedUser = {orgUserId: 'orgUserId'};
172 //        newCtrl.adminAppsRoles = [{id: 1}];
173 //
174 //        deferredUpdateRolesRes.resolve();
175 //        newCtrl.updateAdminAppsRoles();
176 //        $rootScope.$apply();
177 //
178 //        expect(adminsServiceMock.updateAdminAppsRoles).toHaveBeenCalledWith({orgUserId: newCtrl.selectedUser.orgUserId, appsRoles: newCtrl.adminAppsRoles});
179 //        expect($rootScope.closeThisDialog).toHaveBeenCalled();
180 //    });
181 //    it('should log the error when updating apps roles fails', ()=> {
182 //        newCtrl.selectedUser = {orgUserId: 'orgUserId'};
183 //        newCtrl.adminAppsRoles = [{id: 1}];
184 //
185 //        spyOn($log,'error');
186 //        deferredUpdateRolesRes.reject();
187 //        newCtrl.updateAdminAppsRoles();
188 //        $rootScope.$apply();
189 //        expect($log.error).toHaveBeenCalled();
190 //    });
191 //    //it('should display the add admin dropdown when clicking the add button', ()=> {
192 //    //});
193 //
194 //});