cluster_check_popup_test.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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/modal_popups/cluster_check_popup');
  20. describe('App.showClusterCheckPopup', function () {
  21. var isCallbackExecuted,
  22. callback = function () {
  23. isCallbackExecuted = true;
  24. },
  25. cases = [
  26. {
  27. inputData: {
  28. data: {
  29. items: [
  30. {
  31. UpgradeChecks: {
  32. id: 'p0',
  33. status: 'PASS'
  34. }
  35. },
  36. {
  37. UpgradeChecks: {
  38. id: 'p1',
  39. status: 'PASS'
  40. }
  41. }
  42. ]
  43. }
  44. },
  45. result: {
  46. primary: Em.I18n.t('common.proceedAnyway'),
  47. secondary: Em.I18n.t('common.cancel'),
  48. header: ' '
  49. },
  50. bodyResult: {
  51. failTitle: undefined,
  52. failAlert: undefined,
  53. warningTitle: undefined,
  54. warningAlert: undefined,
  55. fails: [],
  56. warnings: [],
  57. hasConfigsMergeConflicts: false,
  58. isAllPassed: true
  59. },
  60. isCallbackExecuted: false,
  61. title: 'no fails, no warnings, no popup customization'
  62. },
  63. {
  64. inputData: {
  65. data: {
  66. items: [
  67. {
  68. UpgradeChecks: {
  69. id: 'w0',
  70. status: 'WARNING'
  71. }
  72. },
  73. {
  74. UpgradeChecks: {
  75. id: 'w1',
  76. status: 'WARNING'
  77. }
  78. }
  79. ]
  80. },
  81. popup: {
  82. header: 'checks',
  83. failTitle: 'fail',
  84. failAlert: 'something has failed',
  85. warningTitle: 'warning',
  86. warningAlert: 'something is not good',
  87. callback: callback
  88. }
  89. },
  90. result: {
  91. primary: Em.I18n.t('common.proceedAnyway'),
  92. secondary: Em.I18n.t('common.cancel'),
  93. header: 'checks'
  94. },
  95. bodyResult: {
  96. failTitle: 'fail',
  97. failAlert: 'something has failed',
  98. warningTitle: 'warning',
  99. warningAlert: 'something is not good',
  100. fails: [],
  101. warnings: [
  102. {
  103. UpgradeChecks: {
  104. id: 'w0',
  105. status: 'WARNING'
  106. }
  107. },
  108. {
  109. UpgradeChecks: {
  110. id: 'w1',
  111. status: 'WARNING'
  112. }
  113. }
  114. ],
  115. hasConfigsMergeConflicts: false,
  116. isAllPassed: false
  117. },
  118. isCallbackExecuted: true,
  119. title: 'no fails, default buttons, callback executed'
  120. },
  121. {
  122. inputData: {
  123. data: {
  124. items: [
  125. {
  126. UpgradeChecks: {
  127. id: 'f0',
  128. status: 'FAIL'
  129. }
  130. },
  131. {
  132. UpgradeChecks: {
  133. id: 'f1',
  134. status: 'FAIL'
  135. }
  136. }
  137. ]
  138. },
  139. popup: {
  140. callback: callback,
  141. noCallbackCondition: true
  142. }
  143. },
  144. result: {
  145. primary: Em.I18n.t('common.dismiss'),
  146. secondary: false,
  147. header: ' '
  148. },
  149. bodyResult: {
  150. failTitle: undefined,
  151. failAlert: undefined,
  152. warningTitle: undefined,
  153. warningAlert: undefined,
  154. fails: [
  155. {
  156. UpgradeChecks: {
  157. id: 'f0',
  158. status: 'FAIL'
  159. }
  160. },
  161. {
  162. UpgradeChecks: {
  163. id: 'f1',
  164. status: 'FAIL'
  165. }
  166. }
  167. ],
  168. warnings: [],
  169. hasConfigsMergeConflicts: false,
  170. isAllPassed: false
  171. },
  172. isCallbackExecuted: false,
  173. title: 'fails detected, default buttons, callback not executed'
  174. },
  175. {
  176. inputData: {
  177. data: {
  178. items: [
  179. {
  180. UpgradeChecks: {
  181. id: 'p0',
  182. status: 'PASS'
  183. }
  184. },
  185. {
  186. UpgradeChecks: {
  187. id: 'p1',
  188. status: 'PASS'
  189. }
  190. }
  191. ]
  192. },
  193. popup: {
  194. primary: 'ok',
  195. secondary: 'cancel'
  196. },
  197. configs: [
  198. {
  199. name: 'c0'
  200. },
  201. {
  202. name: 'c1'
  203. }
  204. ],
  205. upgradeVersion: 'HDP-2.3.0.0'
  206. },
  207. result: {
  208. primary: 'ok',
  209. secondary: 'cancel',
  210. header: ' '
  211. },
  212. bodyResult: {
  213. failTitle: undefined,
  214. failAlert: undefined,
  215. warningTitle: undefined,
  216. warningAlert: undefined,
  217. fails: [],
  218. warnings: [],
  219. hasConfigsMergeConflicts: true,
  220. isAllPassed: false
  221. },
  222. configsResult: [
  223. {
  224. name: 'c0'
  225. },
  226. {
  227. name: 'c1'
  228. }
  229. ],
  230. isCallbackExecuted: false,
  231. title: 'configs merge conflicts detected, custom buttons'
  232. }
  233. ];
  234. beforeEach(function () {
  235. isCallbackExecuted = false;
  236. sinon.stub(App, 'tooltip', Em.K);
  237. });
  238. afterEach(function () {
  239. App.tooltip.restore();
  240. });
  241. cases.forEach(function (item) {
  242. it(item.title, function () {
  243. var popup = App.showClusterCheckPopup(item.inputData.data, item.inputData.popup, item.inputData.configs, item.inputData.upgradeVersion),
  244. popupBody = popup.bodyClass.create();
  245. popup.onPrimary();
  246. Em.keys(item.result).forEach(function (key) {
  247. expect(popup[key]).to.equal(item.result[key]);
  248. });
  249. Em.keys(item.bodyResult).forEach(function (key) {
  250. expect(popupBody[key]).to.eql(item.bodyResult[key]);
  251. });
  252. expect(isCallbackExecuted).to.equal(item.isCallbackExecuted);
  253. if (item.bodyResult.hasConfigsMergeConflicts) {
  254. var configsMergeTable = popupBody.configsMergeTable.create();
  255. configsMergeTable.didInsertElement();
  256. expect(configsMergeTable.configs).to.eql(item.configsResult);
  257. expect(App.tooltip.calledOnce).to.be.true;
  258. expect(App.tooltip.firstCall.args[1].title).to.equal(item.inputData.upgradeVersion);
  259. } else {
  260. expect(App.tooltip.calledOnce).to.be.false;
  261. }
  262. });
  263. });
  264. });