background_operations_test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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('config');
  20. require('utils/updater');
  21. require('utils/ajax');
  22. require('controllers/global/background_operations_controller');
  23. require('views/common/modal_popup');
  24. require('utils/host_progress_popup');
  25. /*window.console.log = function(text){
  26. console.log(text);
  27. }*/
  28. describe('App.BackgroundOperationsController', function () {
  29. /**
  30. * Predefined data
  31. *
  32. */
  33. App.set('clusterName', 'testName');
  34. App.set('testMode', 'true');
  35. App.bgOperationsUpdateInterval = 100;
  36. /**
  37. * Test object
  38. */
  39. var controller = App.BackgroundOperationsController.create();
  40. describe('when set isWorking to true ', function () {
  41. it('startPolling executes App.updater.run ', function(done){
  42. sinon.stub(App.updater, 'run', function(){
  43. controller.set('isWorking', false);
  44. App.updater.run.restore();
  45. done();
  46. });
  47. controller.set('isWorking', true);
  48. });
  49. it('requestMostRecent should be called ', function(done){
  50. this.timeout(App.bgOperationsUpdateInterval + 500);
  51. sinon.stub(controller, 'requestMostRecent', function(){
  52. controller.set('isWorking', false);
  53. controller.requestMostRecent.restore();
  54. done();
  55. });
  56. controller.set('isWorking', true);
  57. });
  58. it('callBackForMostRecent should be called ', function(done){
  59. this.timeout(App.bgOperationsUpdateInterval + 1500);
  60. sinon.stub(controller, 'callBackForMostRecent', function(){
  61. controller.set('isWorking', false);
  62. controller.callBackForMostRecent.restore();
  63. done();
  64. });
  65. controller.set('isWorking', true);
  66. });
  67. });
  68. });