hostWarningPopupBody_view_test.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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"]}]},
  144. {
  145. category: 'process',
  146. warnings: [
  147. {name: 'n7', hosts:['h1', 'h2'], user: 'u1', pid: 'pid1'},
  148. {name: 'n8', hosts:['h2'], user: 'u2', pid: 'pid2'},
  149. {name: 'n9', hosts:['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. });