step0_test.js 3.3 KB

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