step6_view_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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('utils/helper');
  20. require('utils/string_utils');
  21. require('views/wizard/step6_view');
  22. var view;
  23. function getView() {
  24. return App.WizardStep6View.create({
  25. controller: App.WizardStep6Controller.create()
  26. });
  27. }
  28. describe('App.WizardStep6View', function() {
  29. beforeEach(function() {
  30. view = getView();
  31. });
  32. App.TestAliases.testAsComputedAlias(getView(), 'filteredContent', 'content', 'array');
  33. describe('#content', function() {
  34. it('should be same to controller.hosts', function() {
  35. view.set('content', []);
  36. var d = [{}, {}];
  37. view.set('controller.hosts', d);
  38. expect(view.get('content')).to.eql(d);
  39. });
  40. });
  41. describe('#didInsertElement', function() {
  42. beforeEach(function() {
  43. sinon.stub(view.get('controller'), 'loadStep', Em.K);
  44. sinon.stub(App, 'tooltip', Em.K);
  45. sinon.stub(view, 'setLabel', Em.K);
  46. });
  47. afterEach(function() {
  48. view.get('controller').loadStep.restore();
  49. App.tooltip.restore();
  50. view.setLabel.restore();
  51. });
  52. it('should call loadStep', function() {
  53. view.didInsertElement();
  54. expect(view.get('controller').loadStep.calledOnce).to.equal(true);
  55. });
  56. it('should call setLabel if not controller.isMasters', function() {
  57. view.set('controller.isMasters', false);
  58. view.didInsertElement();
  59. expect(view.setLabel.calledOnce).to.equal(true);
  60. });
  61. });
  62. describe('#setLabel', function() {
  63. var tests = Em.A([
  64. {
  65. clients: [{display_name: 'c1'}],
  66. m: 'One client',
  67. e: 'c1'
  68. },
  69. {
  70. clients: [{display_name: 'c1'}, {display_name: 'c2'}],
  71. m: 'Two clients',
  72. e: 'c1 and c2.'
  73. },
  74. {
  75. clients: [{display_name: 'c1'}, {display_name: 'c2'}, {display_name: 'c3'}],
  76. m: 'Three clients',
  77. e: 'c1, c2 and c3.'
  78. },
  79. {
  80. clients: [{display_name: 'c1'}, {display_name: 'c2'}, {display_name: 'c3'}, {display_name: 'c4'}],
  81. m: 'Four clients',
  82. e: 'c1, c2, c3 and c4.'
  83. },
  84. {
  85. clients: [{display_name: 'c1'}, {display_name: 'c2'}, {display_name: 'c3'}, {display_name: 'c4'}, {display_name: 'c5'}],
  86. m: 'Five clients',
  87. e: 'c1, c2, c3, c4 and c5.'
  88. }
  89. ]);
  90. tests.forEach(function(test) {
  91. it(test.m, function() {
  92. view.set('controller.content', {clients: test.clients});
  93. view.setLabel();
  94. expect(view.get('label').endsWith(test.e)).to.equal(true);
  95. });
  96. });
  97. });
  98. describe("#checkboxClick()", function() {
  99. var e;
  100. beforeEach(function() {
  101. sinon.stub(view.get('controller'), 'checkCallback', Em.K);
  102. sinon.stub(view.get('controller'), 'callValidation', Em.K);
  103. e = {
  104. context: {
  105. checked: true,
  106. component: 'c1'
  107. }
  108. };
  109. view.checkboxClick(e);
  110. });
  111. afterEach(function() {
  112. view.get('controller').checkCallback.restore();
  113. view.get('controller').callValidation.restore();
  114. });
  115. it("checked is false", function() {
  116. expect(e.context.checked).to.be.false;
  117. });
  118. it("checkCallback is called with correct data", function() {
  119. expect(view.get('controller').checkCallback.calledWith('c1')).to.be.true;
  120. });
  121. it("callValidation is called once", function() {
  122. expect(view.get('controller').callValidation.calledOnce).to.be.true;
  123. });
  124. });
  125. describe("#columnCount", function() {
  126. it("hosts present", function() {
  127. view.set('controller.hosts', [
  128. Em.Object.create({checkboxes: [{}, {}, {}]})
  129. ]);
  130. view.propertyDidChange('columnCount');
  131. expect(view.get('columnCount')).to.equal(4);
  132. });
  133. it("hosts absent", function() {
  134. view.set('controller.hosts', []);
  135. view.propertyDidChange('columnCount');
  136. expect(view.get('columnCount')).to.equal(1);
  137. });
  138. });
  139. });
  140. describe('App.WizardStep6HostView', function() {
  141. beforeEach(function() {
  142. view = App.WizardStep6HostView.create({
  143. controller: App.WizardStep6Controller.create()
  144. });
  145. });
  146. describe('#didInsertElement', function() {
  147. var data = [];
  148. beforeEach(function() {
  149. sinon.stub(App, 'popover', Em.K);
  150. sinon.stub(view.get('controller'), 'getMasterComponentsForHost', function() {return data;});
  151. });
  152. afterEach(function() {
  153. App.popover.restore();
  154. view.get('controller').getMasterComponentsForHost.restore();
  155. });
  156. it('should create popover if not controller.isMasters', function() {
  157. data = [{}, {}];
  158. view.set('controller.isMasters', false);
  159. view.didInsertElement();
  160. expect(App.popover.calledOnce).to.equal(true);
  161. });
  162. it('should create popover even if controller.getMasterComponentsForHost is an empty array', function() {
  163. data = [{}];
  164. view.set('controller.isMasters', true);
  165. view.didInsertElement();
  166. expect(App.popover.calledOnce).to.equal(true);
  167. });
  168. });
  169. });