927836ae48ca45efb2d77009986eca6416196178
[portal.git] / ecomp-portal-FE-common / client / app / views / widget-onboarding / widget-details-dialog / widget-details.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 // describe('Controller: WidgetDetailsModalCtrl', ()=> {
22 //     /**
23 //      * INITIALIZATION
24 //      */
25 //     beforeEach(module('testUtils'));
26 //     beforeEach(module('ecompApp'));
27 //
28 //     let promisesTestUtils;
29 //     //destroy $http default cache before starting to prevent the error 'default cache already exists'
30 //     //_promisesTestUtils_ comes from testUtils for promises resolve/reject
31 //     beforeEach(inject((_CacheFactory_, _promisesTestUtils_)=> {
32 //         _CacheFactory_.destroyAll();
33 //         promisesTestUtils = _promisesTestUtils_;
34 //     }));
35 //
36 //     let widgetDetails, scope, $controller, $q, $rootScope, $log, widgetsService, errorMessageByCode, ECOMP_URL_REGEX;
37 //     let deferredAdminApps, deferredUserProfile;
38 //     let applicationsServiceMock, widgetsServiceMock, userProfileServiceMock;
39 //     beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {
40 //         [$controller, $q, $rootScope, $log] = [_$controller_, _$q_, _$rootScope_, _$log_];
41 //
42 //         deferredAdminApps = $q.defer();
43 //         deferredUserProfile = $q.defer();
44 //         /*applicationsServiceMock = {
45 //             getAppsForSuperAdminAndAccountAdmin: () => {
46 //                 var promise = () => {return deferredAdminApps.promise};
47 //                 var cancel = jasmine.createSpy();
48 //                 return {
49 //                     promise: promise,
50 //                     cancel: cancel
51 //                 }
52 //             }
53 //         };*/
54 //
55 //         widgetsServiceMock = {
56 //             updateWidget: () => {
57 //                 var promise = () => {return deferredAdminApps.promise};
58 //                 var cancel = jasmine.createSpy();
59 //                 return {
60 //                     promise: promise,
61 //                     cancel: cancel
62 //                 }
63 //             },
64 //             createWidget: () => {
65 //                 var promise = () => {return deferredAdminApps.promise};
66 //                 var cancel = jasmine.createSpy();
67 //                 return {
68 //                     promise: promise,
69 //                     cancel: cancel
70 //                 }
71 //             }
72 //         };
73 //
74 //         userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
75 //         userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
76 //
77 //         applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock',['getAppsForSuperAdminAndAccountAdmin']);
78 //         applicationsServiceMock.getAppsForSuperAdminAndAccountAdmin.and.returnValue(deferredAdminApps.promise);
79 //
80 //     }));
81 //
82 //     beforeEach(()=> {
83 //         errorMessageByCode = [];
84 //         ECOMP_URL_REGEX = "";
85 //         scope = $rootScope.$new();
86 //         createController(scope);
87 //     });
88 //
89 //     let createController = scopeObj => {
90 //         widgetDetails = $controller('WidgetDetailsModalCtrl', {
91 //             $scope: scope,
92 //             $log: $log,
93 //             applicationsService: applicationsServiceMock,
94 //             widgetsService: widgetsServiceMock,
95 //             errorMessageByCode: errorMessageByCode,
96 //             ECOMP_URL_REGEX: ECOMP_URL_REGEX,
97 //             userProfileService: userProfileServiceMock
98 //         });
99 //     };
100 //
101 //     /**
102 //      * MOCK DATA
103 //      */
104 //     let newWidgetModel = {
105 //         name: null,
106 //         appId: null,
107 //         appName: null,
108 //         width: 360,
109 //         height: 300,
110 //         url: null
111 //     };
112 //     let exsistingWidget = {
113 //         name: 'some widget',
114 //         appId: 1,
115 //         appName: 'APP NAME',
116 //         width: 360,
117 //         height: 300,
118 //         url: 'http://a.com'
119 //     };
120 //     let adminApps = [{id: 1, name: 'a'}, {id: 2, name: 'b'}];
121 //
122 //     /**
123 //      * TEST CASES
124 //      */
125 //     it('should initialize controller with new widget mode when opening the modal without selected widget', ()=> {
126 //         expect(widgetDetails.widget).toEqual(newWidgetModel);
127 //     });
128 //
129 //     it('should initialize controller with exsisting widget details when opening the modal with selected widget', ()=> {
130 //         scope.ngDialogData = {
131 //             widget: exsistingWidget
132 //         };
133 //         createController(scope);
134 //         expect(widgetDetails.widget).toEqual(exsistingWidget);
135 //     });
136 //
137 //     it('should populate widget selected app name and id when initializing controller with widget', () =>{
138 //         deferredAdminApps.resolve(adminApps);
139 //         scope.ngDialogData = {
140 //             widget: exsistingWidget
141 //         };
142 //         createController(scope);
143 //         scope.$apply();
144 //         expect(widgetDetails.widget.appId).toEqual(adminApps[0].id);
145 //         expect(widgetDetails.widget.appName).toEqual(adminApps[0].name);
146 //     });
147 //
148 //     //TODO:
149 //     //save changes fail - conflict handling
150 //     //save changes success
151 //
152 //
153 //
154 // });