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 beforeEach(inject((_CacheFactory_)=>{
26 _CacheFactory_.destroyAll();
29 let TabsCtrl, $controller, $q, $rootScope, $log, $window, $cookies,$scope;
31 beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_)=>{
32 [$controller, $q, $rootScope, $log, $window, $cookies] = [_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_];
35 var deferredApps, deferredUserProfile;
37 deferredApps = $q.defer();
38 deferredUserProfile = $q.defer();
39 let applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
40 applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
42 let userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
43 userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
45 $scope = $rootScope.$new();
46 TabsCtrl = $controller('TabsCtrl', {
47 applicationsService: applicationsServiceMock,
50 userProfileService: userProfileServiceMock,
53 $rootScope: $rootScope
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'}]);
62 expect($scope.appsViewData.length).toBe(3);
65 it('should call $log error when getAllPortals fail', ()=>{
67 deferredUserProfile.reject('something happened!');
69 expect($log.error).toHaveBeenCalled();
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');