step2_controller_test.js 4.7 KB

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