2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
22 describe('Controller: TabsCtrl ',() => {
23 beforeEach(module('ecompApp'));
25 //destroy $http default cache before starting to prevent the error 'default cache already exists'
26 beforeEach(inject((_CacheFactory_)=>{
27 _CacheFactory_.destroyAll();
30 let TabsCtrl, $controller, $q, $rootScope, $log, $window, $cookies,$scope;
32 beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_)=>{
33 [$controller, $q, $rootScope, $log, $window, $cookies] = [_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_];
36 var deferredApps, deferredUserProfile;
38 deferredApps = $q.defer();
39 deferredUserProfile = $q.defer();
40 let applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
41 applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
43 let userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
44 userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
46 $scope = $rootScope.$new();
47 TabsCtrl = $controller('TabsCtrl', {
48 applicationsService: applicationsServiceMock,
51 userProfileService: userProfileServiceMock,
54 $rootScope: $rootScope
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'}]);
63 expect($scope.appsViewData.length).toBe(3);
66 it('should call $log error when getAllPortals fail', ()=>{
68 deferredUserProfile.reject('something happened!');
70 expect($log.error).toHaveBeenCalled();
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');