step0_test.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if (!App.router) {
  23. App.router = Em.Object.create({});
  24. }
  25. App.router.set('send', Em.K);
  26. describe('App.WizardStep0Controller', function () {
  27. beforeEach(function() {
  28. wizardStep0Controller = App.WizardStep0Controller.create({content: {cluster: {}}});
  29. sinon.stub(App.clusterStatus, 'set', Em.K);
  30. sinon.spy(App.router, 'send');
  31. });
  32. afterEach(function() {
  33. App.clusterStatus.set.restore();
  34. App.router.send.restore();
  35. });
  36. describe('#invalidClusterName', function () {
  37. it('should return true if no cluster name is present', function () {
  38. wizardStep0Controller.set('hasSubmitted', true);
  39. wizardStep0Controller.set('content', {'cluster':{'name':''}});
  40. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  41. });
  42. it('should return true if cluster name contains white spaces', function () {
  43. wizardStep0Controller.set('hasSubmitted', true);
  44. wizardStep0Controller.set('content', {'cluster':{'name':'the cluster'}});
  45. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  46. });
  47. it('should return true if cluster name contains special chars', function () {
  48. wizardStep0Controller.set('hasSubmitted', true);
  49. wizardStep0Controller.set('content', {'cluster':{'name':'$cluster'}});
  50. expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
  51. })
  52. });
  53. describe('#loadStep', function() {
  54. it('should clear step data', function() {
  55. wizardStep0Controller.loadStep();
  56. expect(wizardStep0Controller.get('hasSubmitted')).to.equal(false);
  57. expect(wizardStep0Controller.get('clusterNameError')).to.equal('');
  58. });
  59. });
  60. describe('#submit', function() {
  61. it('if cluster name is valid should proceed', function() {
  62. wizardStep0Controller.set('content.cluster.name', 'tdk');
  63. wizardStep0Controller.submit();
  64. expect(wizardStep0Controller.get('content.cluster.status')).to.equal('PENDING');
  65. expect(wizardStep0Controller.get('content.cluster.isCompleted')).to.equal(false);
  66. expect(App.router.send.calledWith('next')).to.equal(true);
  67. expect(App.clusterStatus.set.calledWith('clusterName', 'tdk')).to.equal(true);
  68. });
  69. it('if cluster name isn\'t valid shouldn\'t proceed', function() {
  70. wizardStep0Controller.set('content.cluster.name', '@@@@');
  71. wizardStep0Controller.submit();
  72. expect(App.router.send.called).to.equal(false);
  73. expect(App.clusterStatus.set.called).to.equal(false);
  74. });
  75. });
  76. });