config_widget_view_test.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. var view;
  20. describe('App.ConfigWidgetView', function () {
  21. beforeEach(function () {
  22. view = App.ConfigWidgetView.create({
  23. initPopover: Em.K,
  24. config: Em.Object.create({
  25. isOriginalSCP: false,
  26. isPropertyOverridable: false,
  27. cantBeUndone: false,
  28. isNotDefaultValue: false
  29. })
  30. });
  31. });
  32. describe('#undoAllowed', function () {
  33. Em.A([
  34. {
  35. cfg: {
  36. cantBeUndone: false,
  37. isNotDefaultValue: false
  38. },
  39. view: {
  40. disabled: false,
  41. isOriginalSCP: false
  42. },
  43. e: false
  44. },
  45. {
  46. cfg: {
  47. cantBeUndone: true,
  48. isNotDefaultValue: false
  49. },
  50. view: {
  51. disabled: false,
  52. isOriginalSCP: false
  53. },
  54. e: false
  55. },
  56. {
  57. cfg: {
  58. cantBeUndone: false,
  59. isNotDefaultValue: true
  60. },
  61. view: {
  62. disabled: false,
  63. isOriginalSCP: true
  64. },
  65. e: true
  66. },
  67. {
  68. cfg: {
  69. cantBeUndone: true,
  70. isNotDefaultValue: true
  71. },
  72. view: {
  73. disabled: true,
  74. isOriginalSCP: false
  75. },
  76. e: false
  77. }
  78. ]).forEach(function (test, index) {
  79. it('test #' + index, function () {
  80. view.get('config').setProperties(test.cfg);
  81. view.setProperties(test.view);
  82. expect(view.get('undoAllowed')).to.equal(test.e);
  83. });
  84. });
  85. });
  86. describe('#overrideAllowed', function () {
  87. Em.A([
  88. {
  89. cfg: {
  90. isOriginalSCP: false,
  91. isPropertyOverridable: false,
  92. isComparison: false
  93. },
  94. e: false
  95. },
  96. {
  97. cfg: {
  98. isOriginalSCP: true,
  99. isPropertyOverridable: false,
  100. isComparison: false
  101. },
  102. e: false
  103. },
  104. {
  105. cfg: {
  106. isOriginalSCP: false,
  107. isPropertyOverridable: true,
  108. isComparison: false
  109. },
  110. e: false
  111. },
  112. {
  113. cfg: {
  114. isOriginalSCP: true,
  115. isPropertyOverridable: true,
  116. isComparison: false
  117. },
  118. e: true
  119. },
  120. {
  121. cfg: {
  122. isOriginalSCP: false,
  123. isPropertyOverridable: false,
  124. isComparison: true
  125. },
  126. e: false
  127. },
  128. {
  129. cfg: {
  130. isOriginalSCP: true,
  131. isPropertyOverridable: false,
  132. isComparison: true
  133. },
  134. e: false
  135. },
  136. {
  137. cfg: {
  138. isOriginalSCP: false,
  139. isPropertyOverridable: true,
  140. isComparison: true
  141. },
  142. e: false
  143. },
  144. {
  145. cfg: {
  146. isOriginalSCP: true,
  147. isPropertyOverridable: true,
  148. isComparison: true
  149. },
  150. e: false
  151. }
  152. ]).forEach(function (test, index) {
  153. it('test #' + index, function () {
  154. view.get('config').setProperties(test.cfg);
  155. expect(view.get('overrideAllowed')).to.equal(test.e);
  156. });
  157. });
  158. });
  159. describe('#restoreDependentConfigs', function() {
  160. beforeEach(function() {
  161. view = App.ConfigWidgetView.create({
  162. controller: Em.Object.create({
  163. updateDependentConfigs: function() {}
  164. }),
  165. config: Em.Object.create({ name: 'config1'})
  166. });
  167. });
  168. var tests = [
  169. {
  170. dependentConfigs: [
  171. {name: 'dependent1', parentConfigs: ['config1']},
  172. {name: 'dependent2', parentConfigs: ['config2']},
  173. {name: 'dependent3', parentConfigs: ['config1']}
  174. ],
  175. e: ['dependent2'],
  176. m: 'when dependent configs has one parent they should be removed'
  177. },
  178. {
  179. dependentConfigs: [
  180. {name: 'dependent1', parentConfigs: ['config1', 'config2']},
  181. {name: 'dependent2', parentConfigs: ['config2']},
  182. {name: 'dependent3', parentConfigs: ['config1']}
  183. ],
  184. e: ['dependent1', 'dependent2'],
  185. m: 'when dependent configs has multiple parents they should not be removed'
  186. }
  187. ];
  188. tests.forEach(function(test) {
  189. it(test.m, function() {
  190. view.set('controller._dependentConfigValues', test.dependentConfigs);
  191. view.restoreDependentConfigs(view.get('config'));
  192. expect(view.get('controller._dependentConfigValues').mapProperty('name')).to.be.eql(test.e);
  193. });
  194. });
  195. it('when dependent configs has multiple parents appropriate parent config should be removed', function() {
  196. view.set('controller._dependentConfigValues', [
  197. {name: 'dependent1', parentConfigs: ['config1', 'config2']},
  198. {name: 'dependent2', parentConfigs: ['config2', 'config1']},
  199. {name: 'dependent3', parentConfigs: ['config1']}
  200. ]);
  201. view.restoreDependentConfigs(view.get('config'));
  202. expect(view.get('controller._dependentConfigValues').findProperty('name', 'dependent1').parentConfigs.toArray()).to.be.eql(["config2"]);
  203. expect(view.get('controller._dependentConfigValues').findProperty('name', 'dependent2').parentConfigs.toArray()).to.be.eql(["config2"]);
  204. expect(view.get('controller._dependentConfigValues.length')).to.be.eql(2);
  205. });
  206. });
  207. describe('#isValueCompatibleWithWidget()', function() {
  208. it('pass validation', function() {
  209. view.set('config.isValid', true);
  210. expect(view.isValueCompatibleWithWidget()).to.be.true;
  211. });
  212. it('fail validation', function() {
  213. view.set('config.isValid', false);
  214. expect(view.isValueCompatibleWithWidget()).to.be.false;
  215. });
  216. });
  217. });