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