step2_controller_test.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/service/reassign/step2_controller');
  20. require('models/host_component');
  21. describe('App.ReassignMasterWizardStep2Controller', function () {
  22. var controller = App.ReassignMasterWizardStep2Controller.create({
  23. content: Em.Object.create({
  24. reassign: Em.Object.create({}),
  25. services: []
  26. }),
  27. renderComponents: Em.K,
  28. multipleComponents: []
  29. });
  30. describe('#customClientSideValidation', function () {
  31. var hostComponents = [];
  32. var isSubmitDisabled = false;
  33. beforeEach(function () {
  34. sinon.stub(App.HostComponent, 'find', function () {
  35. return hostComponents;
  36. });
  37. });
  38. afterEach(function () {
  39. App.HostComponent.find.restore();
  40. });
  41. it('No host-components, reassigned equal 0', function () {
  42. expect(controller.customClientSideValidation()).to.be.false;
  43. });
  44. it('Reassign component match existed components, reassigned equal 0', function () {
  45. controller.set('content.reassign.component_name', 'COMP1');
  46. hostComponents = [Em.Object.create({
  47. componentName: 'COMP1',
  48. hostName: 'host1'
  49. })];
  50. controller.set('servicesMasters', [{
  51. component_name: 'COMP1',
  52. selectedHost: 'host1'
  53. }]);
  54. expect(controller.customClientSideValidation()).to.be.false;
  55. });
  56. it('Reassign component do not match existed components, reassigned equal 1', function () {
  57. controller.set('content.reassign.component_name', 'COMP1');
  58. hostComponents = [Em.Object.create({
  59. componentName: 'COMP1',
  60. hostName: 'host1'
  61. })];
  62. controller.set('servicesMasters', []);
  63. expect(controller.customClientSideValidation()).to.be.true;
  64. });
  65. it('Reassign component do not match existed components, reassigned equal 2', function () {
  66. controller.set('content.reassign.component_name', 'COMP1');
  67. hostComponents = [
  68. Em.Object.create({
  69. componentName: 'COMP1',
  70. hostName: 'host1'
  71. }),
  72. Em.Object.create({
  73. componentName: 'COMP1',
  74. hostName: 'host2'
  75. })
  76. ];
  77. controller.set('servicesMasters', []);
  78. expect(controller.customClientSideValidation()).to.be.false;
  79. });
  80. it('submitDisabled is already true', function () {
  81. isSubmitDisabled = true;
  82. expect(controller.customClientSideValidation()).to.be.false;
  83. });
  84. });
  85. describe("#mastersToShow", function() {
  86. it("", function() {
  87. controller.set('content.reassign.component_name', 'C1');
  88. controller.propertyDidChange('mastersToShow');
  89. expect(controller.get('mastersToShow')).to.eql(['C1']);
  90. });
  91. });
  92. describe("#mastersToMove", function() {
  93. it("", function() {
  94. controller.set('content.reassign.component_name', 'C1');
  95. controller.propertyDidChange('mastersToMove');
  96. expect(controller.get('mastersToMove')).to.eql(['C1']);
  97. });
  98. });
  99. describe("#additionalHostsList", function () {
  100. beforeEach(function () {
  101. sinon.stub(App.HostComponent, 'find').returns([Em.Object.create({
  102. componentName: 'C1',
  103. hostName: 'host1'
  104. })]);
  105. });
  106. afterEach(function () {
  107. App.HostComponent.find.restore();
  108. });
  109. it("servicesMastersToShow empty", function () {
  110. controller.reopen({
  111. servicesMastersToShow: []
  112. });
  113. controller.set('content.reassign.component_name', 'C1');
  114. controller.propertyDidChange('additionalHostsList');
  115. expect(controller.get('additionalHostsList')).to.be.empty;
  116. });
  117. it("servicesMastersToShow has one master", function () {
  118. controller.reopen({
  119. servicesMastersToShow: [{}]
  120. });
  121. controller.set('content.reassign.component_name', 'C1');
  122. controller.propertyDidChange('additionalHostsList');
  123. expect(controller.get('additionalHostsList')).to.eql([{
  124. label: Em.I18n.t('services.reassign.step2.currentHost'),
  125. host: 'host1'
  126. }]);
  127. });
  128. });
  129. });