config_history_controller_test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/dashboard/config_history_controller');
  20. describe('MainConfigHistoryController', function () {
  21. var controller = App.MainConfigHistoryController.create();
  22. describe('#realUrl', function () {
  23. it('cluster name is empty', function () {
  24. App.set('clusterName', '');
  25. expect(controller.get('realUrl')).to.equal('/api/v1/clusters//configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note&minimal_response=true');
  26. });
  27. it('cluster name is "mycluster"', function () {
  28. App.set('clusterName', 'mycluster');
  29. expect(controller.get('realUrl')).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note&minimal_response=true');
  30. });
  31. });
  32. describe('#load()', function () {
  33. it('', function () {
  34. sinon.stub(controller, 'updateTotalCounter', Em.K);
  35. sinon.stub(controller, 'loadConfigVersionsToModel').returns({done: Em.K});
  36. controller.load();
  37. expect(controller.updateTotalCounter.calledOnce).to.be.true;
  38. controller.updateTotalCounter.restore();
  39. controller.loadConfigVersionsToModel.restore();
  40. });
  41. });
  42. describe('#loadConfigVersionsToModel()', function () {
  43. it('', function () {
  44. sinon.stub(App.HttpClient, 'get', Em.K);
  45. sinon.stub(controller, 'getUrl', Em.K);
  46. sinon.stub(controller, 'getQueryParameters', function(){
  47. return [1];
  48. });
  49. controller.loadConfigVersionsToModel();
  50. expect(App.HttpClient.get.calledOnce).to.be.true;
  51. expect(controller.getQueryParameters.calledOnce).to.be.true;
  52. expect(controller.getUrl.calledWith([1])).to.be.true;
  53. controller.getUrl.restore();
  54. controller.getQueryParameters.restore();
  55. App.HttpClient.get.restore();
  56. });
  57. });
  58. describe('#updateTotalCounter()', function () {
  59. it('', function () {
  60. sinon.stub(App.ajax, 'send', Em.K);
  61. controller.updateTotalCounter();
  62. expect(App.ajax.send.calledOnce).to.be.true;
  63. App.ajax.send.restore();
  64. });
  65. });
  66. describe('#updateTotalCounterSuccess()', function () {
  67. it('', function () {
  68. controller.updateTotalCounterSuccess({itemTotal: 1});
  69. expect(controller.get('totalCount')).to.equal(1);
  70. });
  71. });
  72. describe('#getUrl()', function () {
  73. beforeEach(function () {
  74. sinon.stub(App.router, 'get', function () {
  75. return {
  76. computeParameters: function () {
  77. return 'params'
  78. }
  79. }
  80. });
  81. });
  82. afterEach(function () {
  83. App.router.get.restore();
  84. App.get.restore();
  85. });
  86. it('testMode is true', function () {
  87. sinon.stub(App, 'get', function(k) {
  88. if ('testMode' === k) return true;
  89. return Em.get(App, k);
  90. });
  91. expect(controller.getUrl()).to.equal('/data/configurations/service_versions.json');
  92. });
  93. it('query params is empty', function () {
  94. sinon.stub(App, 'get', function(k) {
  95. if ('testMode' === k) return false;
  96. return Em.get(App, k);
  97. });
  98. expect(controller.getUrl()).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note&minimal_response=true');
  99. });
  100. it('query params is correct', function () {
  101. sinon.stub(App, 'get', function(k) {
  102. if ('testMode' === k) return false;
  103. return Em.get(App, k);
  104. });
  105. expect(controller.getUrl({})).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?paramsfields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note&minimal_response=true');
  106. });
  107. });
  108. describe('#doPolling()', function () {
  109. beforeEach(function () {
  110. sinon.stub(controller, 'load', function(){
  111. return {done: Em.K};
  112. });
  113. this.clock = sinon.useFakeTimers();
  114. });
  115. afterEach(function () {
  116. this.clock.restore();
  117. controller.load.restore();
  118. });
  119. it('isPolling false', function () {
  120. controller.set('isPolling', false);
  121. controller.doPolling();
  122. this.clock.tick(App.componentsUpdateInterval);
  123. expect(controller.load.called).to.be.false;
  124. });
  125. it('isPolling true', function () {
  126. controller.set('isPolling', true);
  127. controller.doPolling();
  128. this.clock.tick(App.componentsUpdateInterval);
  129. expect(controller.load.calledOnce).to.be.true;
  130. });
  131. });
  132. });