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