config_history_controller_test.js 5.3 KB

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