step3_controller_test.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. App = require('app');
  19. require('controllers/main/service/widgets/create/step3_controller');
  20. describe('App.WidgetWizardStep3Controller', function () {
  21. var controller = App.WidgetWizardStep3Controller.create({
  22. content: Em.Object.create()
  23. });
  24. describe("#isEditController", function () {
  25. it("empty name", function () {
  26. controller.set('content.controllerName', '');
  27. controller.propertyDidChange('isEditController');
  28. expect(controller.get('isEditController')).to.be.false;
  29. });
  30. it("widgetEditController name", function () {
  31. controller.set('content.controllerName', 'widgetEditController');
  32. controller.propertyDidChange('isEditController');
  33. expect(controller.get('isEditController')).to.be.true;
  34. });
  35. });
  36. describe("#widgetScope", function () {
  37. it("isSharedChecked - false", function () {
  38. controller.set('isSharedChecked', false);
  39. controller.propertyDidChange('widgetScope');
  40. expect(controller.get('widgetScope')).to.equal('User');
  41. });
  42. it("isSharedChecked - true", function () {
  43. controller.set('isSharedChecked', true);
  44. controller.propertyDidChange('widgetScope');
  45. expect(controller.get('widgetScope')).to.equal('Cluster');
  46. });
  47. });
  48. describe("#isSubmitDisabled", function () {
  49. it("widgetName - null", function () {
  50. controller.set('widgetName', null);
  51. controller.propertyDidChange('isSubmitDisabled');
  52. expect(controller.get('isSubmitDisabled')).to.be.true;
  53. });
  54. it("widgetName empty ", function () {
  55. controller.set('widgetName', '');
  56. controller.propertyDidChange('isSubmitDisabled');
  57. expect(controller.get('isSubmitDisabled')).to.be.true;
  58. });
  59. it("widgetName contains only whitespace", function () {
  60. controller.set('widgetName', ' ');
  61. controller.propertyDidChange('isSubmitDisabled');
  62. expect(controller.get('isSubmitDisabled')).to.be.true;
  63. });
  64. it("widgetName correct", function () {
  65. controller.set('widgetName', 'w1');
  66. controller.propertyDidChange('isSubmitDisabled');
  67. expect(controller.get('isSubmitDisabled')).to.be.false;
  68. });
  69. });
  70. describe("#initPreviewData()", function () {
  71. beforeEach(function () {
  72. sinon.stub(controller, 'addObserver');
  73. });
  74. afterEach(function () {
  75. controller.addObserver.restore();
  76. });
  77. it("", function () {
  78. controller.set('content', Em.Object.create({
  79. widgetProperties: 'widgetProperties',
  80. widgetValues: 'widgetValues',
  81. widgetMetrics: 'widgetMetrics',
  82. widgetAuthor: 'widgetAuthor',
  83. widgetName: 'widgetName',
  84. widgetDescription: 'widgetDescription',
  85. widgetScope: 'CLUSTER',
  86. controllerName: 'widgetEditController'
  87. }));
  88. controller.initPreviewData();
  89. controller.get('isSharedCheckboxDisabled') ? expect(controller.addObserver.calledWith('isSharedChecked')).to.be.false:
  90. expect(controller.addObserver.calledWith('isSharedChecked')).to.be.true;
  91. expect(controller.get('widgetProperties')).to.equal('widgetProperties');
  92. expect(controller.get('widgetValues')).to.equal('widgetValues');
  93. expect(controller.get('widgetMetrics')).to.equal('widgetMetrics');
  94. expect(controller.get('widgetAuthor')).to.equal('widgetAuthor');
  95. expect(controller.get('widgetName')).to.equal('widgetName');
  96. expect(controller.get('widgetDescription')).to.equal('widgetDescription');
  97. expect(controller.get('isSharedChecked')).to.be.true;
  98. expect(controller.get('isSharedCheckboxDisabled')).to.be.true;
  99. });
  100. });
  101. describe("#showConfirmationOnSharing()", function () {
  102. beforeEach(function () {
  103. sinon.spy(App, 'showConfirmationFeedBackPopup');
  104. });
  105. afterEach(function () {
  106. App.showConfirmationFeedBackPopup.restore();
  107. });
  108. it("isSharedChecked - false", function () {
  109. controller.set('isSharedChecked', false);
  110. controller.showConfirmationOnSharing();
  111. expect(App.showConfirmationFeedBackPopup.called).to.be.false;
  112. });
  113. it("isSharedChecked - true", function () {
  114. controller.set('isSharedChecked', true);
  115. var popup = controller.showConfirmationOnSharing();
  116. expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
  117. popup.onSecondary();
  118. expect(controller.get('isSharedChecked')).to.be.false;
  119. popup.onPrimary();
  120. expect(controller.get('isSharedChecked')).to.be.true;
  121. });
  122. });
  123. describe("#collectWidgetData()", function () {
  124. it("", function () {
  125. controller.setProperties({
  126. widgetName: 'widgetName',
  127. content: Em.Object.create({widgetType: 'T1'}),
  128. widgetDescription: 'widgetDescription',
  129. widgetScope: 'Cluster',
  130. widgetAuthor: 'widgetAuthor',
  131. widgetMetrics: [{data: 'data', name: 'm1'}],
  132. widgetValues: [{computedValue: 'cv', value: 'v'}],
  133. widgetProperties: 'widgetProperties'
  134. });
  135. expect(controller.collectWidgetData()).to.eql({
  136. "WidgetInfo": {
  137. "widget_name": "widgetName",
  138. "widget_type": "T1",
  139. "description": "widgetDescription",
  140. "scope": "CLUSTER",
  141. "author": "widgetAuthor",
  142. "metrics": [
  143. {
  144. "name": "m1"
  145. }
  146. ],
  147. "values": [
  148. {
  149. "value": "v"
  150. }
  151. ],
  152. "properties": "widgetProperties"
  153. }
  154. });
  155. });
  156. });
  157. describe("#cancel()", function () {
  158. var mock = {
  159. cancel: Em.K
  160. };
  161. beforeEach(function () {
  162. sinon.spy(mock, 'cancel');
  163. sinon.stub(App.router, 'get').returns(mock);
  164. });
  165. afterEach(function () {
  166. App.router.get.restore();
  167. mock.cancel.restore();
  168. });
  169. it("", function () {
  170. controller.cancel();
  171. expect(mock.cancel.calledOnce).to.be.true;
  172. });
  173. });
  174. describe("#complete()", function () {
  175. var mock = {
  176. finishWizard: Em.K
  177. };
  178. beforeEach(function () {
  179. sinon.spy(mock, 'finishWizard');
  180. sinon.stub(controller, 'collectWidgetData');
  181. sinon.stub(App.router, 'get').returns(mock);
  182. sinon.stub(App.router, 'send');
  183. });
  184. afterEach(function () {
  185. App.router.get.restore();
  186. App.router.send.restore();
  187. controller.collectWidgetData.restore();
  188. mock.finishWizard.restore();
  189. });
  190. it("", function () {
  191. controller.complete();
  192. expect(controller.collectWidgetData.calledOnce).to.be.true;
  193. expect(App.router.send.calledWith('complete')).to.be.true;
  194. expect(mock.finishWizard.calledOnce).to.be.true;
  195. });
  196. });
  197. });