configs_service_test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/host/configs_service');
  20. describe('App.MainHostServiceConfigsController', function () {
  21. var controller = App.MainHostServiceConfigsController.create({
  22. host: Em.Object.create()
  23. });
  24. describe('#filterServiceConfigs()', function () {
  25. var testCases = [
  26. {
  27. title: 'configCategories is empty',
  28. content: {
  29. configCategories: [],
  30. hostComponents: []
  31. },
  32. result: []
  33. },
  34. {
  35. title: 'Category hostComponentNames is null',
  36. content: {
  37. configCategories: [
  38. Em.Object.create({hostComponentNames: null})
  39. ],
  40. hostComponents: []
  41. },
  42. result: [
  43. Em.Object.create({hostComponentNames: null})
  44. ]
  45. },
  46. {
  47. title: 'Components of host are empty',
  48. content: {
  49. configCategories: [
  50. Em.Object.create({hostComponentNames: ['comp1']})
  51. ],
  52. hostComponents: []
  53. },
  54. result: []
  55. },
  56. {
  57. title: 'Host components do not match component of categories',
  58. content: {
  59. configCategories: [
  60. Em.Object.create({hostComponentNames: ['comp1']})
  61. ],
  62. hostComponents: [
  63. {
  64. componentName: 'comp2'
  65. }
  66. ]
  67. },
  68. result: []
  69. },
  70. {
  71. title: 'Host components match component of categories',
  72. content: {
  73. configCategories: [
  74. Em.Object.create({hostComponentNames: ['comp1']})
  75. ],
  76. hostComponents: [
  77. {
  78. componentName: 'comp1'
  79. }
  80. ]
  81. },
  82. result: [
  83. Em.Object.create({hostComponentNames: ['comp1']})
  84. ]
  85. }
  86. ];
  87. testCases.forEach(function (test) {
  88. it(test.title, function () {
  89. controller.set('host.hostComponents', test.content.hostComponents);
  90. expect(controller.filterServiceConfigs(test.content.configCategories)).to.eql(test.result);
  91. });
  92. });
  93. });
  94. describe("#loadStep()", function () {
  95. it("should set host", function () {
  96. controller.set('content', {
  97. host: 'host1'
  98. });
  99. controller.loadStep();
  100. expect(controller.get('host')).to.be.equal('host1');
  101. });
  102. });
  103. describe("#renderServiceConfigs()", function () {
  104. it("should call filterServiceConfigs", function () {
  105. var serviceConfigs = {
  106. configCategories: 'val'
  107. };
  108. sinon.stub(controller, 'filterServiceConfigs', function () {
  109. this._super = Em.K;
  110. });
  111. controller.renderServiceConfigs(serviceConfigs);
  112. expect(controller.filterServiceConfigs.calledWith('val')).to.be.true;
  113. controller.filterServiceConfigs.restore();
  114. });
  115. });
  116. describe("#switchHostGroup()", function () {
  117. beforeEach(function() {
  118. sinon.stub(controller, 'launchSwitchConfigGroupOfHostDialog', Em.K);
  119. sinon.stub(controller, 'onConfigGroupChange', Em.K);
  120. });
  121. afterEach(function () {
  122. controller.launchSwitchConfigGroupOfHostDialog.restore();
  123. controller.onConfigGroupChange.restore();
  124. });
  125. it("should call launchSwitchConfigGroupOfHostDialog", function () {
  126. controller.set('selectedConfigGroup', {});
  127. controller.set('configGroups', []);
  128. controller.set('host', {hostName: 'host1'});
  129. controller.switchHostGroup();
  130. expect(controller.launchSwitchConfigGroupOfHostDialog.calledWith({}, [], 'host1')).to.be.true;
  131. });
  132. });
  133. });