step2_controller_test.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. });