progress_popup_controller_test.js 6.0 KB

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