[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / dashboard / dashboard.controller.spec.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21
22 describe('Controller: DashboardCtrl ', function() {
23     beforeEach(module('ecompApp'));
24
25     let DashboardCtrl, $controller, $q, rootScope, $log, $window, $cookies, scope;
26     let deferredApps, deferredUserProfile, applicationsServiceMock, userProfileServiceMock;
27
28
29     beforeEach(inject( (_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_, _CacheFactory_)=>{
30         rootScope = _$rootScope_;
31         scope = rootScope.$new();
32         $q = _$q_;
33         $controller = _$controller_;
34         $log = _$log_;
35         $window = _$window_;
36         $cookies = _$cookies_;
37
38         _CacheFactory_.destroyAll();
39
40         deferredApps = $q.defer();
41         deferredUserProfile = $q.defer();
42         applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
43         applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
44
45         userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
46         userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
47
48         DashboardCtrl = $controller('DashboardCtrl', {
49             applicationsService: applicationsServiceMock,
50             $log: $log,
51             $window: $window,
52             userProfileService: userProfileServiceMock,
53             $scope: scope,
54             $cookies: $cookies
55         });
56         scope.$digest();
57     }));
58
59     it('should populate this.apps with data from portals service getUserApps', inject(function ( _$q_) {
60         $q = _$q_;
61
62         let profile = {roles: 'superAdmin', orgUserId: 'userid'};
63
64         deferredUserProfile.resolve(profile)
65         deferredApps.resolve([{name: 'portal1'},{name: 'portal2'},{name: 'portal3'}]);
66         scope.$digest();
67         expect(scope.appsViewData.length).toBe(3);
68     }));
69
70     it('should call $log error when getAllPortals fail', inject(function ( _$q_) {
71         $q = _$q_;
72         spyOn($log, 'error');
73         deferredUserProfile.reject('something happened!');
74         scope.$digest();
75         expect($log.error).toHaveBeenCalled();
76     }));
77
78 });