step0_test.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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('models/cluster_states');
  20. require('controllers/wizard/step0_controller');
  21. var wizardStep0Controller;
  22. describe('App.WizardStep0Controller', function () {
  23. beforeEach(function() {
  24. wizardStep0Controller = App.WizardStep0Controller.create({content: {cluster: {}}});
  25. sinon.stub(App.clusterStatus, 'set', Em.K);
  26. sinon.stub(App.router, 'send', Em.K);
  27. App.router.nextBtnClickInProgress = false;
  28. });
  29. afterEach(function() {
  30. App.clusterStatus.set.restore();
  31. App.router.send.restore();
  32. App.router.nextBtnClickInProgress = false;
  33. });
  34. describe('#invalidClusterName', function () {
  35. it('should return true if no cluster name is present', function () {
  36. wizardStep0Controller.set('hasSubmitted', true);
  37. wizardStep0Controller.set('content', {'cluster':{'name':''}});
  38. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  39. });
  40. it('should return true if cluster name contains white spaces', function () {
  41. wizardStep0Controller.set('hasSubmitted', true);
  42. wizardStep0Controller.set('content', {'cluster':{'name':'the cluster'}});
  43. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  44. });
  45. it('should return true if cluster name contains special chars', function () {
  46. wizardStep0Controller.set('hasSubmitted', true);
  47. wizardStep0Controller.set('content', {'cluster':{'name':'$cluster'}});
  48. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  49. })
  50. });
  51. describe('#loadStep', function() {
  52. it('should clear step data', function() {
  53. wizardStep0Controller.loadStep();
  54. expect(wizardStep0Controller.get('hasSubmitted')).to.equal(false);
  55. expect(wizardStep0Controller.get('clusterNameError')).to.equal('');
  56. });
  57. });
  58. describe('#submit', function() {
  59. it('if cluster name is valid should proceed', function() {
  60. wizardStep0Controller.set('content.cluster.name', 'tdk');
  61. wizardStep0Controller.submit();
  62. expect(wizardStep0Controller.get('content.cluster.status')).to.equal('PENDING');
  63. expect(wizardStep0Controller.get('content.cluster.isCompleted')).to.equal(false);
  64. expect(App.router.send.calledWith('next')).to.equal(true);
  65. expect(App.clusterStatus.set.calledWith('clusterName', 'tdk')).to.equal(true);
  66. });
  67. it('if cluster name isn\'t valid shouldn\'t proceed', function() {
  68. wizardStep0Controller.set('content.cluster.name', '@@@@');
  69. wizardStep0Controller.submit();
  70. expect(App.router.send.called).to.equal(false);
  71. expect(App.clusterStatus.set.called).to.equal(false);
  72. });
  73. it('if Next button is clicked multiple times before the next step renders, it must not be processed', function() {
  74. wizardStep0Controller.set('content.cluster.name', 'tdk');
  75. wizardStep0Controller.submit();
  76. expect(App.router.send.calledWith('next')).to.equal(true);
  77. App.router.send.reset();
  78. wizardStep0Controller.submit();
  79. expect(App.router.send.called).to.equal(false);
  80. });
  81. });
  82. });