step3_controller_test.js 6.7 KB

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