services_config_test.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('views/common/chart/pie');
  20. require('views/common/configs/services_config');
  21. describe('App.ServiceConfigView', function () {
  22. var controller = App.WizardStep7Controller.create({
  23. selectedServiceObserver: function(){},
  24. switchConfigGroupConfigs: function(){}
  25. });
  26. var view = App.ServiceConfigView.create({
  27. controller: controller
  28. });
  29. var testCases = [
  30. {
  31. title: 'selectedConfigGroup is null',
  32. result: {
  33. 'category1': false,
  34. 'category2': true,
  35. 'category3': false
  36. },
  37. selectedConfigGroup: null,
  38. selectedService: {
  39. serviceName: 'TEST',
  40. configCategories: [
  41. App.ServiceConfigCategory.create({ name: 'category1', canAddProperty: false}),
  42. App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: true}),
  43. App.ServiceConfigCategory.create({ name: 'category3', siteFileName: 'xml', canAddProperty: false})
  44. ]
  45. }
  46. },
  47. {
  48. title: 'selectedConfigGroup is default group',
  49. result: {
  50. 'category1': true,
  51. 'category2': true,
  52. 'category3': false
  53. },
  54. selectedConfigGroup: {isDefault: true},
  55. selectedService: {
  56. serviceName: 'TEST',
  57. configCategories: [
  58. App.ServiceConfigCategory.create({ name: 'category1', canAddProperty: true}),
  59. App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: true}),
  60. App.ServiceConfigCategory.create({ name: 'category3', siteFileName: 'xml', canAddProperty: false})
  61. ]
  62. }
  63. },
  64. {
  65. title: 'selectedConfigGroup is not default group',
  66. result: {
  67. 'category1': false,
  68. 'category2': false
  69. },
  70. selectedConfigGroup: {},
  71. selectedService: {
  72. serviceName: 'TEST',
  73. configCategories: [
  74. App.ServiceConfigCategory.create({ name: 'category1', siteFileName: 'xml', canAddProperty: true}),
  75. App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: false})
  76. ]
  77. }
  78. }
  79. ];
  80. describe('#checkCanEdit', function () {
  81. testCases.forEach(function (test) {
  82. it(test.title, function () {
  83. controller.set('selectedService', test.selectedService);
  84. controller.set('selectedConfigGroup', test.selectedConfigGroup);
  85. view.checkCanEdit();
  86. controller.get('selectedService.configCategories').forEach(function (category) {
  87. expect(category.get('canAddProperty')).to.equal(test.result[category.get('name')]);
  88. });
  89. });
  90. });
  91. });
  92. });
  93. describe('App.ServiceConfigsByCategoryView', function () {
  94. var view = App.ServiceConfigsByCategoryView.create({
  95. serviceConfigs: []
  96. });
  97. var result = [1, 2, 3, 4];
  98. var testData = [
  99. {
  100. title: 'four configs in correct order',
  101. configs: [
  102. Em.Object.create({index: 1, resultId: 1}),
  103. Em.Object.create({index: 2, resultId: 2}),
  104. Em.Object.create({index: 3, resultId: 3}),
  105. Em.Object.create({index: 4, resultId: 4})
  106. ]
  107. },
  108. {
  109. title: 'four configs in reverse order',
  110. configs: [
  111. Em.Object.create({index: 4, resultId: 4}),
  112. Em.Object.create({index: 3, resultId: 3}),
  113. Em.Object.create({index: 2, resultId: 2}),
  114. Em.Object.create({index: 1, resultId: 1})
  115. ]
  116. },
  117. {
  118. title: 'four configs in random order',
  119. configs: [
  120. Em.Object.create({index: 3, resultId: 3}),
  121. Em.Object.create({index: 4, resultId: 4}),
  122. Em.Object.create({index: 1, resultId: 1}),
  123. Em.Object.create({index: 2, resultId: 2})
  124. ]
  125. },
  126. {
  127. title: 'four configs with no index',
  128. configs: [
  129. Em.Object.create({resultId: 1}),
  130. Em.Object.create({resultId: 2}),
  131. Em.Object.create({resultId: 3}),
  132. Em.Object.create({resultId: 4})
  133. ]
  134. },
  135. {
  136. title: 'four configs but one with index',
  137. configs: [
  138. Em.Object.create({resultId: 2}),
  139. Em.Object.create({resultId: 3}),
  140. Em.Object.create({resultId: 4}),
  141. Em.Object.create({index: 1, resultId: 1})
  142. ]
  143. },
  144. {
  145. title: 'index is null or not number',
  146. configs: [
  147. Em.Object.create({index: null, resultId: 3}),
  148. Em.Object.create({index: 1, resultId: 1}),
  149. Em.Object.create({index: 2, resultId: 2}),
  150. Em.Object.create({index: 'a', resultId: 4})
  151. ]
  152. },
  153. {
  154. title: 'four configs when indexes skipped',
  155. configs: [
  156. Em.Object.create({index: 88, resultId: 3}),
  157. Em.Object.create({index: 67, resultId: 2}),
  158. Em.Object.create({index: 111, resultId: 4}),
  159. Em.Object.create({index: 3, resultId: 1})
  160. ]
  161. }
  162. ];
  163. describe('#sortByIndex', function () {
  164. testData.forEach(function(_test){
  165. it(_test.title, function () {
  166. expect(view.sortByIndex(_test.configs).mapProperty('resultId')).to.deep.equal(result);
  167. })
  168. })
  169. });
  170. describe('#updateReadOnlyFlags', function () {
  171. it('if canEdit is true then isEditable flag of configs shouldn\'t be changed', function () {
  172. view.set('canEdit', true);
  173. view.set('serviceConfigs', [
  174. Em.Object.create({
  175. name: 'config1',
  176. isEditable: true
  177. }),
  178. Em.Object.create({
  179. name: 'config2',
  180. isEditable: false
  181. })
  182. ]);
  183. view.updateReadOnlyFlags();
  184. expect(view.get('serviceConfigs').findProperty('name', 'config1').get('isEditable')).to.equal(true);
  185. expect(view.get('serviceConfigs').findProperty('name', 'config2').get('isEditable')).to.equal(false);
  186. });
  187. it('if canEdit is false then configs shouldn\'t be editable', function () {
  188. view.set('canEdit', false);
  189. view.set('serviceConfigs', [
  190. Em.Object.create({
  191. name: 'config1',
  192. isEditable: true
  193. }),
  194. Em.Object.create({
  195. name: 'config2',
  196. isEditable: false
  197. })
  198. ]);
  199. view.updateReadOnlyFlags();
  200. expect(view.get('serviceConfigs').findProperty('name', 'config1').get('isEditable')).to.equal(false);
  201. expect(view.get('serviceConfigs').findProperty('name', 'config2').get('isEditable')).to.equal(false);
  202. });
  203. it('if canEdit is false then config overrides shouldn\'t be editable', function () {
  204. view.set('canEdit', false);
  205. view.set('serviceConfigs', [
  206. Em.Object.create({
  207. name: 'config',
  208. isEditable: true,
  209. overrides: [
  210. Em.Object.create({
  211. name: 'override1',
  212. isEditable: true
  213. }),
  214. Em.Object.create({
  215. name: 'override2',
  216. isEditable: false
  217. })
  218. ]
  219. })
  220. ]);
  221. view.updateReadOnlyFlags();
  222. var overrides = view.get('serviceConfigs').findProperty('name', 'config').get('overrides');
  223. expect(overrides.findProperty('name', 'override1').get('isEditable')).to.equal(false);
  224. expect(overrides.findProperty('name', 'override2').get('isEditable')).to.equal(false);
  225. });
  226. it('if canEdit is true then isEditable flag of overrides shouldn\'t be changed', function () {
  227. view.set('canEdit', true);
  228. view.set('serviceConfigs', [
  229. Em.Object.create({
  230. name: 'config',
  231. isEditable: true,
  232. overrides: [
  233. Em.Object.create({
  234. name: 'override1',
  235. isEditable: true
  236. }),
  237. Em.Object.create({
  238. name: 'override2',
  239. isEditable: false
  240. })
  241. ]
  242. })
  243. ]);
  244. view.updateReadOnlyFlags();
  245. var overrides = view.get('serviceConfigs').findProperty('name', 'config').get('overrides');
  246. expect(overrides.findProperty('name', 'override1').get('isEditable')).to.equal(true);
  247. expect(overrides.findProperty('name', 'override2').get('isEditable')).to.equal(false);
  248. })
  249. })
  250. });