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