nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / home / applications-home / applications-home.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 describe('Controller: ApplicationsHomeCtrl ', function() {
22     beforeEach(module('ecompApp'));
23
24     let ApplicationsHomeCtrl, $controller, $q, rootScope, $log, $window, $cookies, scope;
25     let deferredApps, deferredUserProfile, applicationsServiceMock, userProfileServiceMock;
26
27
28     beforeEach(inject( (_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_, _CacheFactory_)=>{
29         rootScope = _$rootScope_;
30         scope = rootScope.$new();
31         $q = _$q_;
32         $controller = _$controller_;
33         $log = _$log_;
34         $window = _$window_;
35         $cookies = _$cookies_;
36
37         _CacheFactory_.destroyAll();
38
39         deferredApps = $q.defer();
40         deferredUserProfile = $q.defer();
41         applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
42         applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
43
44         userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
45         userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
46
47         ApplicationsHomeCtrl = $controller('ApplicationsHomeCtrl', {
48             applicationsService: applicationsServiceMock,
49             $log: $log,
50             $window: $window,
51             userProfileService: userProfileServiceMock,
52             $scope: scope,
53             $cookies: $cookies
54         });
55         scope.$digest();
56     }));
57
58     it('should populate this.apps with data from portals service getUserApps', inject(function ( _$q_) {
59         $q = _$q_;
60
61         let profile = {roles: 'superAdmin', userId: 'userid'};
62
63         deferredUserProfile.resolve(profile)
64         deferredApps.resolve([{name: 'portal1'},{name: 'portal2'},{name: 'portal3'}]);
65         scope.$digest();
66         expect(scope.appsViewData.length).toBe(3);
67     }));
68
69     it('should call $log error when getAllPortals fail', inject(function ( _$q_) {
70         $q = _$q_;
71         spyOn($log, 'error');
72         deferredUserProfile.reject('something happened!');
73         scope.$digest();
74         expect($log.error).toHaveBeenCalled();
75     }));
76
77 });