hostWarningPopupBody_view_test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. diskCategoryWarnings: [
  72. {hostsNames: ['h2', 'h5']}
  73. ],
  74. warningsByHost: [
  75. {},
  76. { name: 'h1', warnings: [{}, {}, {}] },
  77. { name: 'h2', warnings: [{}, {}, {}] },
  78. { name: 'h3', warnings: [] }
  79. ]
  80. }));
  81. expect(view.warningHostsNamesCount()).to.equal(4);
  82. });
  83. });
  84. describe('#hostSelectView', function() {
  85. var v;
  86. beforeEach(function() {
  87. v = view.get('hostSelectView').create();
  88. });
  89. describe('#click', function() {
  90. Em.A([
  91. {
  92. isLoaded: false,
  93. isLazyLoading: true,
  94. e: true
  95. },
  96. {
  97. isLoaded: true,
  98. isLazyLoading: true,
  99. e: false
  100. },
  101. {
  102. isLoaded: false,
  103. isLazyLoading: false,
  104. e: false
  105. },
  106. {
  107. isLoaded: true,
  108. isLazyLoading: false,
  109. e: false
  110. }
  111. ]).forEach(function (test) {
  112. it('isLoaded: ' + test.isLoaded.toString() + ', isLazyLoading: ' + test.isLazyLoading.toString(), function () {
  113. v.reopen({
  114. isLoaded: test.isLoaded,
  115. isLazyLoading: test.isLazyLoading
  116. });
  117. sinon.spy(lazyloading, 'run');
  118. v.click();
  119. if (test.e) {
  120. expect(lazyloading.run.calledOnce).to.equal(true);
  121. }
  122. else {
  123. expect(lazyloading.run.called).to.equal(false);
  124. }
  125. lazyloading.run.restore();
  126. });
  127. });
  128. });
  129. });
  130. describe('#contentInDetails', function() {
  131. var content = [
  132. {category: 'firewall', warnings: [{name: 'n1'}, {name: 'n2'}, {name: 'n3'}]},
  133. {category: 'fileFolders', warnings: [{name: 'n4'}, {name: 'n5'}, {name: 'n6'}]},
  134. {
  135. category: 'process',
  136. warnings: [
  137. {name: 'n7', hosts:['h1', 'h2'], user: 'u1', pid: 'pid1'},
  138. {name: 'n8', hosts:['h2'], user: 'u2', pid: 'pid2'},
  139. {name: 'n9', hosts:['h3'], user: 'u1', pid: 'pid3'}
  140. ]
  141. },
  142. {category: 'package', warnings: [{name: 'n10'}, {name: 'n11'}, {name: 'n12'}]},
  143. {category: 'service', warnings: [{name: 'n13'}, {name: 'n14'}, {name: 'n15'}]},
  144. {category: 'user', warnings: [{name: 'n16'}, {name: 'n17'}, {name: 'n18'}]}
  145. ], warningsByHost = [
  146. {},
  147. {name: 'c', warnings: [{}, {}, {}]},
  148. {name: 'd', warnings: [{}]}
  149. ];
  150. beforeEach(function() {
  151. view.reopen({content: content, warningsByHost: warningsByHost});
  152. });
  153. it('should map hosts', function() {
  154. var newContent = view.get('contentInDetails');
  155. expect(newContent.contains('c d')).to.equal(true);
  156. });
  157. it('should map firewall warnings', function() {
  158. var newContent = view.get('contentInDetails');
  159. expect(newContent.contains('n1<br>n2<br>n3')).to.equal(true);
  160. });
  161. it('should map fileFolders warnings', function() {
  162. var newContent = view.get('contentInDetails');
  163. expect(newContent.contains('n4 n5 n6')).to.equal(true);
  164. });
  165. it('should map process warnings', function() {
  166. var newContent = view.get('contentInDetails');
  167. expect(newContent.contains('(h1,u1,pid1)')).to.equal(true);
  168. expect(newContent.contains('(h2,u1,pid1)')).to.equal(true);
  169. expect(newContent.contains('(h2,u2,pid2)')).to.equal(true);
  170. expect(newContent.contains('(h3,u1,pid3)')).to.equal(true);
  171. });
  172. it('should map package warnings', function() {
  173. var newContent = view.get('contentInDetails');
  174. expect(newContent.contains('n10 n11 n12')).to.equal(true);
  175. });
  176. it('should map service warnings', function() {
  177. var newContent = view.get('contentInDetails');
  178. expect(newContent.contains('n13 n14 n15')).to.equal(true);
  179. });
  180. it('should map user warnings', function() {
  181. var newContent = view.get('contentInDetails');
  182. expect(newContent.contains('n16 n17 n18')).to.equal(true);
  183. });
  184. });
  185. });