step6_view_test.js 5.7 KB

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