[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / users / new-user-dialogs / new-user.controller.spec.js
index 8d5ac74..bdc2958 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-/**\r
- * Created by nnaffar on 12/20/15.\r
- */\r
-'use strict';\r
-\r
-describe('Controller: NewUserModalCtrl ', () => {\r
-    beforeEach(module('testUtils'));\r
-    beforeEach(module('ecompApp'));\r
-\r
-        let promisesTestUtils;\r
-        //destroy $http default cache before starting to prevent the error 'default cache already exists'\r
-        //_promisesTestUtils_ comes from testUtils for promises resolve/reject\r
-        beforeEach(inject((_CacheFactory_, _promisesTestUtils_)=> {\r
-            _CacheFactory_.destroyAll();\r
-            promisesTestUtils = _promisesTestUtils_;\r
-        }));\r
-\r
-        let newUser, $controller, $q, $rootScope, $log, $scope;\r
-\r
-        let applicationsServiceMock, usersServiceMock, confirmBoxServiceMock;\r
-        let deferredAdminApps, deferredUsersAccounts, deferredUsersAppRoles, deferredUsersAppRoleUpdate;\r
-\r
-        beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {\r
-            $rootScope = _$rootScope_;\r
-            $q = _$q_;\r
-            $controller = _$controller_;\r
-            $log = _$log_;\r
-        }));\r
-\r
-    beforeEach(()=> {\r
-            [deferredAdminApps, deferredUsersAccounts, deferredUsersAppRoles, deferredUsersAppRoleUpdate] = [$q.defer(),$q.defer(), $q.defer(), $q.defer()];\r
-\r
-            /*applicationsServiceMock = {\r
-                getAdminApps: () => {\r
-                    var promise = () => {return deferredAdminApps.promise};\r
-                    var cancel = jasmine.createSpy();\r
-                    return {\r
-                        promise: promise,\r
-                        cancel: cancel\r
-                    }\r
-                }\r
-            };*/\r
-\r
-            confirmBoxServiceMock = {\r
-                deleteItem: () => {\r
-                    var promise = () => {return deferredAdminApps.promise};\r
-                    var cancel = jasmine.createSpy();\r
-                    return {\r
-                        promise: promise,\r
-                        cancel: cancel\r
-                    }\r
-                }\r
-            };\r
-\r
-            applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getAdminAppsSimpler']);\r
-            applicationsServiceMock.getAdminAppsSimpler.and.returnValue(deferredAdminApps.promise);\r
-\r
-            usersServiceMock = jasmine.createSpyObj('usersServiceMock', ['getAccountUsers','getUserAppRoles','updateUserAppsRoles']);\r
-\r
-            //applicationsServiceMock.getAdminApps().promise().and.returnValue(deferredAdminApps.promise);\r
-            usersServiceMock.getAccountUsers.and.returnValue(deferredUsersAccounts.promise);\r
-            usersServiceMock.getUserAppRoles.and.returnValue(deferredUsersAppRoles.promise);\r
-            usersServiceMock.updateUserAppsRoles.and.returnValue(deferredUsersAppRoleUpdate.promise);\r
-\r
-            $scope = $rootScope.$new();\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-            //$scope.users = users;\r
-        });\r
-\r
-        /*beforeEach(()=> {\r
-            scope = $rootScope.$new();\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: scope,\r
-                $log: $log,\r
-                usersService: usersService,\r
-                applicationsService: applicationsService,\r
-                confirmBoxService: confirmBoxService\r
-            });\r
-        });*/\r
-\r
-\r
-        it('should open modal window without user when no user is selected', ()=> {\r
-            expect(newUser.selectedUser).toBe(null);\r
-        });\r
-\r
-        it('should open modal window with selectedUser apps roles when user is selected', ()=> {\r
-            let roles = {apps: [{id: 1, appRoles: [{id: 3, isApplied: true}]}]};\r
-            let someUser = {orgUserId: 'asdfjl'};\r
-\r
-           deferredUsersAppRoles.resolve(roles);\r
-           deferredAdminApps.resolve(roles.apps);\r
-\r
-            $scope.ngDialogData = {\r
-                selectedUser: someUser,\r
-                dialogState: 2\r
-            };\r
-\r
-            //inject ngDialogData to the scope controller\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-\r
-            newUser.getUserAppsRoles();\r
-            $scope.$apply();\r
-\r
-            expect(newUser.selectedUser).toBe(someUser);\r
-            expect(newUser.adminApps).toEqual(roles.apps);\r
-        });\r
-\r
-        it('should push to apps order list only apps that has applied roles when initializing', () => {\r
-            let roles = {apps: [{appId: 13, appRoles: [{id: 3, isApplied: true}]},{appId: 20, appRoles: [{id: 3, isApplied: false}]}]};\r
-            let someUser = {orgUserId: 'asdfjl'};\r
-\r
-            deferredUsersAppRoles.resolve(roles);\r
-            //deferredAdminApps.resolve(roles.apps);\r
-\r
-            $scope.ngDialogData = {\r
-                selectedUser: someUser,\r
-                dialogState: 2\r
-            };\r
-\r
-            //inject ngDialogData to the scope controller\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-\r
-            $scope.$apply();\r
-\r
-           // expect(newUser.appsOrder).toEqual([13]);\r
-        });\r
-\r
-        it('should push app to apps order list when applying at least one role to user from app', () => {\r
-            let roles = {apps: [{appId: 13, appRoles: [{id: 3, isApplied: true}]},{appId: 20, appRoles: [{id: 3, isApplied: false}]}]};\r
-            let someUser = {orgUserId: 'asdfjl'};\r
-\r
-            // promisesTestUtils.resolvePromise(usersService, 'getUserAppsRoles', roles);\r
-            deferredUsersAppRoles.resolve(roles);\r
-\r
-            $scope.ngDialogData = {\r
-                selectedUser: someUser,\r
-                dialogState: 2\r
-            };\r
-\r
-            //inject ngDialogData to the scope controller\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-\r
-            //$scope.$apply();\r
-            //newUser.updateAppsOrder({appId: 39, appRoles: [{id: 13, isApplied: true}]});\r
-            $scope.$apply();\r
-\r
-          //  expect(newUser.appsOrder).toEqual([13, 39]);\r
-        });\r
-\r
-\r
-        it('should remove app from list when removing all user roles in it', () => {\r
-            let roles = {apps: [{appName: 'aaa', appId: 13, appRoles: [{id: 3, isApplied: true}]},{appName: 'vvv', appId: 20, appRoles: [{id: 3, isApplied: true}]}]};\r
-            let someUser = {orgUserId: 'asdfjl'};\r
-\r
-           // promisesTestUtils.resolvePromise(usersService, 'getUserAppsRoles', roles);\r
-            promisesTestUtils.resolvePromise(confirmBoxServiceMock, 'deleteItem', true);\r
-\r
-            deferredUsersAppRoles.resolve(roles);\r
-\r
-            $scope.ngDialogData = {\r
-                selectedUser: someUser,\r
-                dialogState: 2\r
-            };\r
-\r
-            //inject ngDialogData to the scope controller\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-\r
-            $scope.$apply();\r
-            newUser.deleteApp(roles.apps[0]);\r
-            $scope.$apply();\r
-\r
-           // expect(newUser.appsOrder).toEqual([20]);\r
-        });\r
-\r
-        it('should close the modal when update changes succeeded', () => {\r
-            let roles = {apps: [{appName: 'aaa', appId: 13, appRoles: [{id: 3, isApplied: true}]},{appName: 'vvv', appId: 20, appRoles: [{id: 3, isApplied: true}]}]};\r
-            let someUser = {orgUserId: 'asdfjl'};\r
-            //promisesTestUtils.resolvePromise(usersServiceMock, 'getUserAppsRoles', roles);\r
-            //promisesTestUtils.resolvePromise(usersServiceMock, 'updateUserAppsRoles');\r
-            deferredUsersAppRoles.resolve(roles);\r
-            deferredUsersAppRoleUpdate.resolve();\r
-            deferredAdminApps.resolve(roles.apps);\r
-\r
-            $scope.ngDialogData = {\r
-                selectedUser: someUser,\r
-                dialogState: 2\r
-            };\r
-\r
-            //inject ngDialogData to the scope controller\r
-            newUser = $controller('NewUserModalCtrl', {\r
-                $scope: $scope,\r
-                $log: $log,\r
-                usersService: usersServiceMock,\r
-                applicationsService: applicationsServiceMock,\r
-                confirmBoxService: confirmBoxServiceMock\r
-            });\r
-            $scope.closeThisDialog = function(){};\r
-            spyOn($scope, 'closeThisDialog');\r
-\r
-            newUser.getUserAppsRoles();\r
-            $scope.$apply();\r
-            newUser.updateUserAppsRoles();\r
-            $scope.$apply();\r
-            expect($scope.closeThisDialog).toHaveBeenCalledWith(true);\r
-        });\r
-    });\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+/**
+ * Created by nnaffar on 12/20/15.
+ */
+'use strict';
+
+describe('Controller: NewUserModalCtrl ', () => {
+    beforeEach(module('testUtils'));
+    beforeEach(module('ecompApp'));
+
+        let promisesTestUtils;
+        //destroy $http default cache before starting to prevent the error 'default cache already exists'
+        //_promisesTestUtils_ comes from testUtils for promises resolve/reject
+        beforeEach(inject((_CacheFactory_, _promisesTestUtils_)=> {
+            _CacheFactory_.destroyAll();
+            promisesTestUtils = _promisesTestUtils_;
+        }));
+
+        let newUser, $controller, $q, $rootScope, $log, $scope;
+
+        let applicationsServiceMock, usersServiceMock, confirmBoxServiceMock;
+        let deferredAdminApps, deferredUsersAccounts, deferredUsersAppRoles, deferredUsersAppRoleUpdate;
+
+        beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {
+            $rootScope = _$rootScope_;
+            $q = _$q_;
+            $controller = _$controller_;
+            $log = _$log_;
+        }));
+
+    beforeEach(()=> {
+            [deferredAdminApps, deferredUsersAccounts, deferredUsersAppRoles, deferredUsersAppRoleUpdate] = [$q.defer(),$q.defer(), $q.defer(), $q.defer()];
+
+            /*applicationsServiceMock = {
+                getAdminApps: () => {
+                    var promise = () => {return deferredAdminApps.promise};
+                    var cancel = jasmine.createSpy();
+                    return {
+                        promise: promise,
+                        cancel: cancel
+                    }
+                }
+            };*/
+
+            confirmBoxServiceMock = {
+                deleteItem: () => {
+                    var promise = () => {return deferredAdminApps.promise};
+                    var cancel = jasmine.createSpy();
+                    return {
+                        promise: promise,
+                        cancel: cancel
+                    }
+                }
+            };
+
+            applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getAdminAppsSimpler']);
+            applicationsServiceMock.getAdminAppsSimpler.and.returnValue(deferredAdminApps.promise);
+
+            usersServiceMock = jasmine.createSpyObj('usersServiceMock', ['getAccountUsers','getUserAppRoles','updateUserAppsRoles']);
+
+            //applicationsServiceMock.getAdminApps().promise().and.returnValue(deferredAdminApps.promise);
+            usersServiceMock.getAccountUsers.and.returnValue(deferredUsersAccounts.promise);
+            usersServiceMock.getUserAppRoles.and.returnValue(deferredUsersAppRoles.promise);
+            usersServiceMock.updateUserAppsRoles.and.returnValue(deferredUsersAppRoleUpdate.promise);
+
+            $scope = $rootScope.$new();
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+            //$scope.users = users;
+        });
+
+        /*beforeEach(()=> {
+            scope = $rootScope.$new();
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: scope,
+                $log: $log,
+                usersService: usersService,
+                applicationsService: applicationsService,
+                confirmBoxService: confirmBoxService
+            });
+        });*/
+
+
+        it('should open modal window without user when no user is selected', ()=> {
+            expect(newUser.selectedUser).toBe(null);
+        });
+
+        it('should open modal window with selectedUser apps roles when user is selected', ()=> {
+            let roles = {apps: [{id: 1, appRoles: [{id: 3, isApplied: true}]}]};
+            let someUser = {orgUserId: 'asdfjl'};
+
+           deferredUsersAppRoles.resolve(roles);
+           deferredAdminApps.resolve(roles.apps);
+
+            $scope.ngDialogData = {
+                selectedUser: someUser,
+                dialogState: 2
+            };
+
+            //inject ngDialogData to the scope controller
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+
+            newUser.getUserAppsRoles();
+            $scope.$apply();
+
+            expect(newUser.selectedUser).toBe(someUser);
+            expect(newUser.adminApps).toEqual(roles.apps);
+        });
+
+        it('should push to apps order list only apps that has applied roles when initializing', () => {
+            let roles = {apps: [{appId: 13, appRoles: [{id: 3, isApplied: true}]},{appId: 20, appRoles: [{id: 3, isApplied: false}]}]};
+            let someUser = {orgUserId: 'asdfjl'};
+
+            deferredUsersAppRoles.resolve(roles);
+            //deferredAdminApps.resolve(roles.apps);
+
+            $scope.ngDialogData = {
+                selectedUser: someUser,
+                dialogState: 2
+            };
+
+            //inject ngDialogData to the scope controller
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+
+            $scope.$apply();
+
+           // expect(newUser.appsOrder).toEqual([13]);
+        });
+
+        it('should push app to apps order list when applying at least one role to user from app', () => {
+            let roles = {apps: [{appId: 13, appRoles: [{id: 3, isApplied: true}]},{appId: 20, appRoles: [{id: 3, isApplied: false}]}]};
+            let someUser = {orgUserId: 'asdfjl'};
+
+            // promisesTestUtils.resolvePromise(usersService, 'getUserAppsRoles', roles);
+            deferredUsersAppRoles.resolve(roles);
+
+            $scope.ngDialogData = {
+                selectedUser: someUser,
+                dialogState: 2
+            };
+
+            //inject ngDialogData to the scope controller
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+
+            //$scope.$apply();
+            //newUser.updateAppsOrder({appId: 39, appRoles: [{id: 13, isApplied: true}]});
+            $scope.$apply();
+
+          //  expect(newUser.appsOrder).toEqual([13, 39]);
+        });
+
+
+        it('should remove app from list when removing all user roles in it', () => {
+            let roles = {apps: [{appName: 'aaa', appId: 13, appRoles: [{id: 3, isApplied: true}]},{appName: 'vvv', appId: 20, appRoles: [{id: 3, isApplied: true}]}]};
+            let someUser = {orgUserId: 'asdfjl'};
+
+           // promisesTestUtils.resolvePromise(usersService, 'getUserAppsRoles', roles);
+            promisesTestUtils.resolvePromise(confirmBoxServiceMock, 'deleteItem', true);
+
+            deferredUsersAppRoles.resolve(roles);
+
+            $scope.ngDialogData = {
+                selectedUser: someUser,
+                dialogState: 2
+            };
+
+            //inject ngDialogData to the scope controller
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+
+            $scope.$apply();
+            newUser.deleteApp(roles.apps[0]);
+            $scope.$apply();
+
+           // expect(newUser.appsOrder).toEqual([20]);
+        });
+
+        it('should close the modal when update changes succeeded', () => {
+            let roles = {apps: [{appName: 'aaa', appId: 13, appRoles: [{id: 3, isApplied: true}]},{appName: 'vvv', appId: 20, appRoles: [{id: 3, isApplied: true}]}]};
+            let someUser = {orgUserId: 'asdfjl'};
+            //promisesTestUtils.resolvePromise(usersServiceMock, 'getUserAppsRoles', roles);
+            //promisesTestUtils.resolvePromise(usersServiceMock, 'updateUserAppsRoles');
+            deferredUsersAppRoles.resolve(roles);
+            deferredUsersAppRoleUpdate.resolve();
+            deferredAdminApps.resolve(roles.apps);
+
+            $scope.ngDialogData = {
+                selectedUser: someUser,
+                dialogState: 2
+            };
+
+            //inject ngDialogData to the scope controller
+            newUser = $controller('NewUserModalCtrl', {
+                $scope: $scope,
+                $log: $log,
+                usersService: usersServiceMock,
+                applicationsService: applicationsServiceMock,
+                confirmBoxService: confirmBoxServiceMock
+            });
+            $scope.closeThisDialog = function(){};
+            spyOn($scope, 'closeThisDialog');
+
+            newUser.getUserAppsRoles();
+            $scope.$apply();
+            newUser.updateUserAppsRoles();
+            $scope.$apply();
+            expect($scope.closeThisDialog).toHaveBeenCalledWith(true);
+        });
+    });