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 * ================================================================================
21 describe('Controller: ApplicationsHomeCtrl ', function() {
22 beforeEach(module('ecompApp'));
24 let ApplicationsHomeCtrl, $controller, $q, rootScope, $log, $window, $cookies, scope;
25 let deferredApps, deferredUserProfile, applicationsServiceMock, userProfileServiceMock;
28 beforeEach(inject( (_$controller_, _$q_, _$rootScope_, _$log_, _$window_, _$cookies_, _CacheFactory_)=>{
29 rootScope = _$rootScope_;
30 scope = rootScope.$new();
32 $controller = _$controller_;
35 $cookies = _$cookies_;
37 _CacheFactory_.destroyAll();
39 deferredApps = $q.defer();
40 deferredUserProfile = $q.defer();
41 applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock', ['getUserApps']);
42 applicationsServiceMock.getUserApps.and.returnValue(deferredApps.promise);
44 userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
45 userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
47 ApplicationsHomeCtrl = $controller('ApplicationsHomeCtrl', {
48 applicationsService: applicationsServiceMock,
51 userProfileService: userProfileServiceMock,
58 it('should populate this.apps with data from portals service getUserApps', inject(function ( _$q_) {
61 let profile = {roles: 'superAdmin', userId: 'userid'};
63 deferredUserProfile.resolve(profile)
64 deferredApps.resolve([{name: 'portal1'},{name: 'portal2'},{name: 'portal3'}]);
66 expect(scope.appsViewData.length).toBe(3);
69 it('should call $log error when getAllPortals fail', inject(function ( _$q_) {
72 deferredUserProfile.reject('something happened!');
74 expect($log.error).toHaveBeenCalled();