hostWarningPopupBody_view_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 lazyloading = require('utils/lazy_loading');
  20. require('views/wizard/step3/hostWarningPopupBody_view');
  21. var view;
  22. describe('App.WizardStep3HostWarningPopupBody', function() {
  23. beforeEach(function() {
  24. view = App.WizardStep3HostWarningPopupBody.create({
  25. didInsertElement: Em.K,
  26. $: function() {
  27. return Em.Object.create({
  28. toggle: Em.K
  29. })
  30. }
  31. });
  32. });
  33. describe('#onToggleBlock', function() {
  34. it('should toggle', function() {
  35. var context = Em.Object.create({isCollapsed: false});
  36. view.onToggleBlock({context: context});
  37. expect(context.get('isCollapsed')).to.equal(true);
  38. view.onToggleBlock({context: context});
  39. expect(context.get('isCollapsed')).to.equal(false);
  40. });
  41. });
  42. describe('#showHostsPopup', function() {
  43. it('should call App.ModalPopup.show', function() {
  44. sinon.stub(App.ModalPopup, 'show', Em.K);
  45. view.showHostsPopup({context: []});
  46. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  47. App.ModalPopup.show.restore();
  48. });
  49. });
  50. describe('#categoryWarnings', function() {
  51. it('should return empty array', function() {
  52. var warningsByHost = null;
  53. view.reopen({warningsByHost: warningsByHost});
  54. expect(view.get('categoryWarnings')).to.eql([]);
  55. });
  56. it('should return filtered warnings', function() {
  57. var warningsByHost = [
  58. {name: 'c', warnings: [{}, {}, {}]},
  59. {name: 'd', warnings: [{}]}
  60. ];
  61. view.reopen({warningsByHost: warningsByHost, category: 'c'});
  62. expect(view.get('categoryWarnings.length')).to.equal(3);
  63. });
  64. });
  65. describe('#warningHostsNamesCount', function() {
  66. it('should parse warnings', function() {
  67. view.set('bodyController', Em.Object.create({
  68. repoCategoryWarnings: [
  69. {hostsNames: ['h1', 'h4']}
  70. ],
  71. thpCategoryWarnings: [
  72. {hostsNames: ['h2', 'h3']}
  73. ],
  74. jdkCategoryWarnings: [
  75. {hostsNames: ['h3', 'h5']}
  76. ],
  77. hostCheckWarnings: [
  78. {hostsNames: ['h1', 'h2']}
  79. ],
  80. diskCategoryWarnings: [
  81. {hostsNames: ['h2', 'h5']}
  82. ],
  83. warningsByHost: [
  84. {},
  85. { name: 'h1', warnings: [{}, {}, {}] },
  86. { name: 'h2', warnings: [{}, {}, {}] },
  87. { name: 'h3', warnings: [] }
  88. ]
  89. }));
  90. expect(view.warningHostsNamesCount()).to.equal(5);
  91. });
  92. });
  93. describe('#hostSelectView', function() {
  94. var v;
  95. beforeEach(function() {
  96. v = view.get('hostSelectView').create();
  97. });
  98. describe('#click', function() {
  99. Em.A([
  100. {
  101. isLoaded: false,
  102. isLazyLoading: true,
  103. e: true
  104. },
  105. {
  106. isLoaded: true,
  107. isLazyLoading: true,
  108. e: false
  109. },
  110. {
  111. isLoaded: false,
  112. isLazyLoading: false,
  113. e: false
  114. },
  115. {
  116. isLoaded: true,
  117. isLazyLoading: false,
  118. e: false
  119. }
  120. ]).forEach(function (test) {
  121. it('isLoaded: ' + test.isLoaded.toString() + ', isLazyLoading: ' + test.isLazyLoading.toString(), function () {
  122. v.reopen({
  123. isLoaded: test.isLoaded,
  124. isLazyLoading: test.isLazyLoading
  125. });
  126. sinon.spy(lazyloading, 'run');
  127. v.click();
  128. if (test.e) {
  129. expect(lazyloading.run.calledOnce).to.equal(true);
  130. }
  131. else {
  132. expect(lazyloading.run.called).to.equal(false);
  133. }
  134. lazyloading.run.restore();
  135. });
  136. });
  137. });
  138. });
  139. describe('#contentInDetails', function() {
  140. var content = [
  141. {category: 'firewall', warnings: [{name: 'n1'}, {name: 'n2'}, {name: 'n3'}]},
  142. {category: 'fileFolders', warnings: [{name: 'n4'}, {name: 'n5'}, {name: 'n6'}]},
  143. {category: 'reverseLookup', warnings: [{name: 'n19', hosts: ["h1"], hostsLong: ["h1"]}]},
  144. {
  145. category: 'process',
  146. warnings: [
  147. {name: 'n7', hosts:['h1', 'h2'], hostsLong:['h1', 'h2'], user: 'u1', pid: 'pid1'},
  148. {name: 'n8', hosts:['h2'], hostsLong:['h2'], user: 'u2', pid: 'pid2'},
  149. {name: 'n9', hosts:['h3'], hostsLong:['h3'], user: 'u1', pid: 'pid3'}
  150. ]
  151. },
  152. {category: 'package', warnings: [{name: 'n10'}, {name: 'n11'}, {name: 'n12'}]},
  153. {category: 'service', warnings: [{name: 'n13'}, {name: 'n14'}, {name: 'n15'}]},
  154. {category: 'user', warnings: [{name: 'n16'}, {name: 'n17'}, {name: 'n18'}]},
  155. {category: 'jdk', warnings: []},
  156. {category: 'disk', warnings: []},
  157. {category: 'repositories', warnings: []},
  158. {category: 'hostNameResolution', warnings: []},
  159. {category: 'thp', warnings: []}
  160. ];
  161. beforeEach(function() {
  162. view.reopen({content: content, warningsByHost: [], hostNamesWithWarnings: ['c', 'd']});
  163. });
  164. it('should map hosts', function() {
  165. var newContent = view.get('contentInDetails');
  166. expect(newContent.contains('c d')).to.equal(true);
  167. });
  168. it('should map firewall warnings', function() {
  169. var newContent = view.get('contentInDetails');
  170. expect(newContent.contains('n1<br>n2<br>n3')).to.equal(true);
  171. });
  172. it('should map fileFolders warnings', function() {
  173. var newContent = view.get('contentInDetails');
  174. expect(newContent.contains('n4 n5 n6')).to.equal(true);
  175. });
  176. it('should map process warnings', function() {
  177. var newContent = view.get('contentInDetails');
  178. expect(newContent.contains('(h1,u1,pid1)')).to.equal(true);
  179. expect(newContent.contains('(h2,u1,pid1)')).to.equal(true);
  180. expect(newContent.contains('(h2,u2,pid2)')).to.equal(true);
  181. expect(newContent.contains('(h3,u1,pid3)')).to.equal(true);
  182. });
  183. it('should map package warnings', function() {
  184. var newContent = view.get('contentInDetails');
  185. expect(newContent.contains('n10 n11 n12')).to.equal(true);
  186. });
  187. it('should map service warnings', function() {
  188. var newContent = view.get('contentInDetails');
  189. expect(newContent.contains('n13 n14 n15')).to.equal(true);
  190. });
  191. it('should map user warnings', function() {
  192. var newContent = view.get('contentInDetails');
  193. expect(newContent.contains('n16 n17 n18')).to.equal(true);
  194. });
  195. it('should map reverse lookup warnings', function() {
  196. var newContent = view.get('contentInDetails');
  197. expect(newContent.contains('h1')).to.equal(true);
  198. });
  199. });
  200. describe('#content', function () {
  201. it('should return array with warning objects', function () {
  202. view.set('bodyController', Em.Object.create({
  203. hostCheckWarnings: [
  204. {
  205. hosts: ['h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h5', 'h7', 'h8', 'h9', 'h10']
  206. }
  207. ],
  208. repoCategoryWarnings: [
  209. {
  210. hosts: ['h11', 'h12']
  211. }
  212. ],
  213. diskCategoryWarnings: [
  214. {
  215. hosts: ['h13']
  216. }
  217. ],
  218. jdkCategoryWarnings: [
  219. {
  220. hosts: ['h14']
  221. }
  222. ],
  223. thpCategoryWarnings: [
  224. {
  225. hosts: ['h15']
  226. }
  227. ]
  228. }));
  229. view.reopen({
  230. categoryWarnings: [
  231. {
  232. category: 'firewall',
  233. hosts: ['h16']
  234. },
  235. {
  236. category: 'firewall',
  237. hosts: ['h17']
  238. },
  239. {
  240. category: 'processes',
  241. hosts: ['h18']
  242. },
  243. {
  244. category: 'packages',
  245. hosts: ['h19']
  246. },
  247. {
  248. category: 'fileFolders',
  249. hosts: ['h20']
  250. },
  251. {
  252. category: 'services',
  253. hosts: ['h21']
  254. },
  255. {
  256. category: 'users',
  257. hosts: ['h22']
  258. },
  259. {
  260. category: 'misc',
  261. hosts: ['h23']
  262. },
  263. {
  264. category: 'alternatives',
  265. hosts: ['h24']
  266. },
  267. {
  268. category: 'reverseLookup',
  269. hosts: ['h25']
  270. },
  271. {
  272. category: 'reverseLookup',
  273. hosts: ['h26']
  274. },
  275. {
  276. category: 'reverseLookup',
  277. hosts: ['h27']
  278. },
  279. {
  280. category: 'reverseLookup',
  281. hosts: ['h28']
  282. },
  283. {
  284. category: 'reverseLookup',
  285. hosts: ['h29']
  286. },
  287. {
  288. category: 'reverseLookup',
  289. hosts: ['h30']
  290. },
  291. {
  292. category: 'reverseLookup',
  293. hosts: ['h31']
  294. },
  295. {
  296. category: 'reverseLookup',
  297. hosts: ['h32']
  298. },
  299. {
  300. category: 'reverseLookup',
  301. hosts: ['h33']
  302. },
  303. {
  304. category: 'reverseLookup',
  305. hosts: ['h34']
  306. },
  307. {
  308. category: 'reverseLookup',
  309. hosts: ['h35', 'h36']
  310. }
  311. ]
  312. });
  313. var content = view.get('content');
  314. expect(content.mapProperty('isCollapsed').uniq()).to.eql([true]);
  315. expect(content.findProperty('category', 'hostNameResolution').get('warnings')[0].hostsList).
  316. to.equal('h0<br>h1<br>h2<br>h3<br>h4<br>h5<br>h5<br>h7<br>h8<br>h9<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(1));
  317. expect(content.findProperty('category', 'repositories').get('warnings')[0].hostsList).to.equal('h11<br>h12');
  318. expect(content.findProperty('category', 'disk').get('warnings')[0].hostsList).to.equal('h13');
  319. expect(content.findProperty('category', 'jdk').get('warnings')[0].hostsList).to.equal('h14');
  320. expect(content.findProperty('category', 'thp').get('warnings')[0].hostsList).to.equal('h15');
  321. expect(content.findProperty('category', 'firewall').get('warnings').mapProperty('hostsList')).to.eql(['h16', 'h17']);
  322. expect(content.findProperty('category', 'process').get('warnings')[0].hostsList).to.equal('h18');
  323. expect(content.findProperty('category', 'package').get('warnings')[0].hostsList).to.equal('h19');
  324. expect(content.findProperty('category', 'fileFolders').get('warnings')[0].hostsList).to.equal('h20');
  325. expect(content.findProperty('category', 'service').get('warnings')[0].hostsList).to.equal('h21');
  326. expect(content.findProperty('category', 'user').get('warnings')[0].hostsList).to.equal('h22');
  327. expect(content.findProperty('category', 'misc').get('warnings')[0].hostsList).to.equal('h23');
  328. expect(content.findProperty('category', 'alternatives').get('warnings')[0].hostsList).to.equal('h24');
  329. expect(content.findProperty('category', 'reverseLookup').get('warnings').mapProperty('hostsList')).to.eql([
  330. 'h25', 'h26', 'h27', 'h28', 'h29', 'h30', 'h31', 'h32', 'h33', 'h34', 'h35<br>h36'
  331. ]);
  332. });
  333. });
  334. });