updater_test.js 2.5 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. describe('utils/updater', function() {
  20. describe('#App.updater', function() {
  21. beforeEach(function() {
  22. this.clock = sinon.useFakeTimers();
  23. });
  24. var tests = {
  25. t1: {
  26. obj: Em.Object.create({
  27. method: sinon.spy(),
  28. isWorking: true
  29. }),
  30. m: 'method called once with default interval in 15 000 ms'
  31. },
  32. t2: {
  33. obj: Em.Object.create({
  34. method: function() {}
  35. }),
  36. m: 'should return false if key name is invalid or absent'
  37. },
  38. t3: {
  39. obj: Em.Object.create({
  40. method2: sinon.spy(),
  41. isWorking: true
  42. }),
  43. m: 'method should be called immediately'
  44. },
  45. t4: {
  46. obj: Em.Object.create({
  47. method3: sinon.spy(),
  48. isWorking: true
  49. }),
  50. m: 'method call should be ignored if `isWorking` set to false'
  51. }
  52. };
  53. it(tests.t1.m, function() {
  54. App.updater.run(tests.t1.obj, 'method', 'isWorking');
  55. this.clock.tick(15000);
  56. expect(tests.t1.obj.method.called).to.be.ok;
  57. });
  58. it(tests.t2.m, function() {
  59. var methodCall = App.updater.run(tests.t2.obj, 'method', 'isWorking');
  60. expect(methodCall).to.be.false;
  61. });
  62. it(tests.t3.m, function() {
  63. App.updater.run(tests.t3.obj, 'method2', 'isWorking');
  64. App.updater.immediateRun('method2');
  65. expect(tests.t3.obj.method2.called).to.be.ok;
  66. });
  67. it(tests.t4.m, function() {
  68. App.updater.run(tests.t4.obj, 'method3', 'isWorking');
  69. this.clock.tick(10000);
  70. tests.t4.obj.set('isWorking', false);
  71. this.clock.tick(5000);
  72. expect(tests.t4.obj.method3.called).to.be.false;
  73. });
  74. afterEach(function() {
  75. this.clock.restore();
  76. });
  77. });
  78. });