eb5146e33b422c4864783ca0c02621f87ab08b24
[portal.git] / ecomp-portal-FE-common / client / app / views / widget-onboarding / widget-details-dialog / widget-details.controller.spec.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 // 'use strict';
39 // describe('Controller: WidgetDetailsModalCtrl', ()=> {
40 //     /**
41 //      * INITIALIZATION
42 //      */
43 //     beforeEach(module('testUtils'));
44 //     beforeEach(module('ecompApp'));
45 //
46 //     let promisesTestUtils;
47 //     //destroy $http default cache before starting to prevent the error 'default cache already exists'
48 //     //_promisesTestUtils_ comes from testUtils for promises resolve/reject
49 //     beforeEach(inject((_CacheFactory_, _promisesTestUtils_)=> {
50 //         _CacheFactory_.destroyAll();
51 //         promisesTestUtils = _promisesTestUtils_;
52 //     }));
53 //
54 //     let widgetDetails, scope, $controller, $q, $rootScope, $log, widgetsService, errorMessageByCode, ECOMP_URL_REGEX;
55 //     let deferredAdminApps, deferredUserProfile;
56 //     let applicationsServiceMock, widgetsServiceMock, userProfileServiceMock;
57 //     beforeEach(inject((_$controller_, _$q_, _$rootScope_, _$log_)=> {
58 //         [$controller, $q, $rootScope, $log] = [_$controller_, _$q_, _$rootScope_, _$log_];
59 //
60 //         deferredAdminApps = $q.defer();
61 //         deferredUserProfile = $q.defer();
62 //         /*applicationsServiceMock = {
63 //             getAppsForSuperAdminAndAccountAdmin: () => {
64 //                 var promise = () => {return deferredAdminApps.promise};
65 //                 var cancel = jasmine.createSpy();
66 //                 return {
67 //                     promise: promise,
68 //                     cancel: cancel
69 //                 }
70 //             }
71 //         };*/
72 //
73 //         widgetsServiceMock = {
74 //             updateWidget: () => {
75 //                 var promise = () => {return deferredAdminApps.promise};
76 //                 var cancel = jasmine.createSpy();
77 //                 return {
78 //                     promise: promise,
79 //                     cancel: cancel
80 //                 }
81 //             },
82 //             createWidget: () => {
83 //                 var promise = () => {return deferredAdminApps.promise};
84 //                 var cancel = jasmine.createSpy();
85 //                 return {
86 //                     promise: promise,
87 //                     cancel: cancel
88 //                 }
89 //             }
90 //         };
91 //
92 //         userProfileServiceMock = jasmine.createSpyObj('userProfileServiceMock',['getUserProfile']);
93 //         userProfileServiceMock.getUserProfile.and.returnValue(deferredUserProfile.promise);
94 //
95 //         applicationsServiceMock = jasmine.createSpyObj('applicationsServiceMock',['getAppsForSuperAdminAndAccountAdmin']);
96 //         applicationsServiceMock.getAppsForSuperAdminAndAccountAdmin.and.returnValue(deferredAdminApps.promise);
97 //
98 //     }));
99 //
100 //     beforeEach(()=> {
101 //         errorMessageByCode = [];
102 //         ECOMP_URL_REGEX = "";
103 //         scope = $rootScope.$new();
104 //         createController(scope);
105 //     });
106 //
107 //     let createController = scopeObj => {
108 //         widgetDetails = $controller('WidgetDetailsModalCtrl', {
109 //             $scope: scope,
110 //             $log: $log,
111 //             applicationsService: applicationsServiceMock,
112 //             widgetsService: widgetsServiceMock,
113 //             errorMessageByCode: errorMessageByCode,
114 //             ECOMP_URL_REGEX: ECOMP_URL_REGEX,
115 //             userProfileService: userProfileServiceMock
116 //         });
117 //     };
118 //
119 //     /**
120 //      * MOCK DATA
121 //      */
122 //     let newWidgetModel = {
123 //         name: null,
124 //         appId: null,
125 //         appName: null,
126 //         width: 360,
127 //         height: 300,
128 //         url: null
129 //     };
130 //     let exsistingWidget = {
131 //         name: 'some widget',
132 //         appId: 1,
133 //         appName: 'APP NAME',
134 //         width: 360,
135 //         height: 300,
136 //         url: 'http://a.com'
137 //     };
138 //     let adminApps = [{id: 1, name: 'a'}, {id: 2, name: 'b'}];
139 //
140 //     /**
141 //      * TEST CASES
142 //      */
143 //     it('should initialize controller with new widget mode when opening the modal without selected widget', ()=> {
144 //         expect(widgetDetails.widget).toEqual(newWidgetModel);
145 //     });
146 //
147 //     it('should initialize controller with exsisting widget details when opening the modal with selected widget', ()=> {
148 //         scope.ngDialogData = {
149 //             widget: exsistingWidget
150 //         };
151 //         createController(scope);
152 //         expect(widgetDetails.widget).toEqual(exsistingWidget);
153 //     });
154 //
155 //     it('should populate widget selected app name and id when initializing controller with widget', () =>{
156 //         deferredAdminApps.resolve(adminApps);
157 //         scope.ngDialogData = {
158 //             widget: exsistingWidget
159 //         };
160 //         createController(scope);
161 //         scope.$apply();
162 //         expect(widgetDetails.widget.appId).toEqual(adminApps[0].id);
163 //         expect(widgetDetails.widget.appName).toEqual(adminApps[0].name);
164 //     });
165 //
166 //     //TODO:
167 //     //save changes fail - conflict handling
168 //     //save changes success
169 //
170 //
171 //
172 // });