progress_popup_controller_test.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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('controllers/main/admin/highAvailability/progress_popup_controller');
  20. describe('App.HighAvailabilityProgressPopupController', function () {
  21. var controller;
  22. beforeEach(function () {
  23. controller = App.HighAvailabilityProgressPopupController.create();
  24. });
  25. after(function () {
  26. controller.destroy();
  27. });
  28. describe('#startTaskPolling', function () {
  29. beforeEach(function () {
  30. sinon.stub(App.updater, 'run', Em.K);
  31. sinon.stub(App.updater, 'immediateRun', Em.K);
  32. });
  33. afterEach(function () {
  34. App.updater.run.restore();
  35. App.updater.immediateRun.restore();
  36. });
  37. describe('should start task polling', function () {
  38. beforeEach(function () {
  39. controller.startTaskPolling(1, 2);
  40. });
  41. it('isTaskPolling = true', function () {
  42. expect(controller.get('isTaskPolling')).to.be.true;
  43. });
  44. it('taskInfo.id = 2', function () {
  45. expect(controller.get('taskInfo.id'), 2);
  46. });
  47. it('taskInfo.requestId = 1', function () {
  48. expect(controller.get('taskInfo.requestId'), 1);
  49. });
  50. it('App.updater.run is called once', function () {
  51. expect(App.updater.run.calledOnce).to.be.true;
  52. });
  53. it('App.updater.immediateRun is called once', function () {
  54. expect(App.updater.immediateRun.calledOnce).to.be.true;
  55. });
  56. });
  57. });
  58. describe('#stopTaskPolling', function () {
  59. it('should stop task polling', function () {
  60. controller.stopTaskPolling();
  61. expect(controller.get('isTaskPolling')).to.be.false;
  62. });
  63. });
  64. describe('#updateTask', function () {
  65. beforeEach(function () {
  66. sinon.stub(App.ajax, 'send', Em.K);
  67. });
  68. afterEach(function () {
  69. App.ajax.send.restore();
  70. });
  71. it('should send polling request', function () {
  72. controller.updateTask();
  73. expect(App.ajax.send.calledOnce).to.be.true;
  74. });
  75. });
  76. describe('#updateTaskSuccessCallback', function () {
  77. beforeEach(function () {
  78. controller.reopen({
  79. taskInfo: {}
  80. });
  81. });
  82. var cases = [
  83. {
  84. status: 'FAILED',
  85. isTaskPolling: false
  86. },
  87. {
  88. status: 'COMPLETED',
  89. isTaskPolling: false
  90. },
  91. {
  92. status: 'TIMEDOUT',
  93. isTaskPolling: false
  94. },
  95. {
  96. status: 'ABORTED',
  97. isTaskPolling: false
  98. },
  99. {
  100. status: 'QUEUED',
  101. isTaskPolling: true
  102. },
  103. {
  104. status: 'IN_PROGRESS',
  105. isTaskPolling: true
  106. }
  107. ],
  108. tasks = {
  109. stderr: 'error',
  110. stdout: 'output',
  111. output_log: 'output-log.txt',
  112. error_log: 'error-log.txt'
  113. },
  114. title = '{0}polling task if it\'s status is {1}';
  115. cases.forEach(function (item) {
  116. var message = title.format(item.isTaskPolling ? '' : 'not ', item.status);
  117. describe(message, function () {
  118. beforeEach(function () {
  119. controller.updateTaskSuccessCallback({
  120. Tasks: $.extend(tasks, {
  121. status: item.status
  122. })
  123. });
  124. });
  125. it('stderr is valid', function () {
  126. expect(controller.get('taskInfo.stderr')).to.equal('error');
  127. });
  128. it('stdout is valid', function () {
  129. expect(controller.get('taskInfo.stdout')).to.equal('output');
  130. });
  131. it('outputLog is valid', function () {
  132. expect(controller.get('taskInfo.outputLog')).to.equal('output-log.txt');
  133. });
  134. it('errorLog is valid', function () {
  135. expect(controller.get('taskInfo.errorLog')).to.equal('error-log.txt');
  136. });
  137. it('isTaskPolling is valid', function () {
  138. expect(controller.get('isTaskPolling')).to.equal(item.isTaskPolling);
  139. });
  140. });
  141. });
  142. });
  143. describe('#getHosts', function () {
  144. var cases = [
  145. {
  146. name: 'background_operations.get_by_request',
  147. title: 'default background operation polling'
  148. },
  149. {
  150. stageId: 0,
  151. name: 'common.request.polling',
  152. stageIdPassed: '0',
  153. title: 'polling by stage, stageId = 0'
  154. },
  155. {
  156. stageId: 1,
  157. name: 'common.request.polling',
  158. stageIdPassed: 1,
  159. title: 'polling by stage'
  160. }
  161. ];
  162. beforeEach(function () {
  163. sinon.stub(App.ajax, 'send', Em.K);
  164. });
  165. afterEach(function () {
  166. App.ajax.send.restore();
  167. });
  168. cases.forEach(function (item) {
  169. describe(item.title, function () {
  170. beforeEach(function () {
  171. controller.setProperties({
  172. requestIds: [1, 2],
  173. stageId: item.stageId
  174. });
  175. controller.getHosts();
  176. });
  177. it('two requests are sent', function () {
  178. expect(App.ajax.send.calledTwice).to.be.true;
  179. });
  180. it('1st call name is valid', function () {
  181. expect(App.ajax.send.firstCall.args[0].name).to.equal(item.name);
  182. });
  183. it('2nd call name is valid', function () {
  184. expect(App.ajax.send.secondCall.args[0].name).to.equal(item.name);
  185. });
  186. it('1st stageId is valid', function () {
  187. expect(App.ajax.send.firstCall.args[0].data.stageId).to.eql(item.stageIdPassed);
  188. });
  189. it('2nd stageId is valid', function () {
  190. expect(App.ajax.send.secondCall.args[0].data.stageId).to.eql(item.stageIdPassed);
  191. });
  192. });
  193. });
  194. });
  195. });