background_operations_test.js 2.4 KB

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