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: DashboardCtrl ', function() {
23 beforeEach(module('ecompApp'));
25 let DashboardCtrl, $controller, $q, rootScope, $log, $window, $cookies, scope;
26 let deferredApps, deferredUserProfile, applicationsServiceMock, userProfileServiceMock;
29 beforeEach(inject( (_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_, _CacheFactory_)=>{
30 rootScope = _$rootScope_;
31 scope = rootScope.$new();
33 $controller = _$controller_;
36 $cookies = _$cookies_;
38 _CacheFactory_.destroyAll();
40 deferredApps = $q.defer();
41 deferredUserProfile = $q.defer();
42 applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
43 applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
45 userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
46 userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
48 DashboardCtrl = $controller('DashboardCtrl', {
49 applicationsService: applicationsServiceMock,
52 userProfileService: userProfileServiceMock,
59 it('should populate this.apps with data from portals service getUserApps', inject(function ( _$q_) {
62 let profile = {roles: 'superAdmin', orgUserId: 'userid'};
64 deferredUserProfile.resolve(profile)
65 deferredApps.resolve([{name: 'portal1'},{name: 'portal2'},{name: 'portal3'}]);
67 expect(scope.appsViewData.length).toBe(3);
70 it('should call $log error when getAllPortals fail', inject(function ( _$q_) {
73 deferredUserProfile.reject('something happened!');
75 expect($log.error).toHaveBeenCalled();