step0_view_test.js 3.0 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('views/wizard/step0_view');
  20. var view, controller = Em.Object.create({
  21. clusterNameError: '',
  22. loadStep: Em.K
  23. });
  24. describe('App.WizardStep0View', function () {
  25. beforeEach(function () {
  26. view = App.WizardStep0View.create({'controller': controller});
  27. });
  28. describe('#onError', function () {
  29. it('should be true if clusterNameError appears', function () {
  30. controller.set('clusterNameError', 'ERROR');
  31. expect(view.get('onError')).to.equal(true);
  32. });
  33. it('should be false if clusterNameError doesn\'t appears', function () {
  34. controller.set('clusterNameError', '');
  35. expect(view.get('onError')).to.equal(false);
  36. });
  37. });
  38. describe('#didInsertElement', function () {
  39. beforeEach(function () {
  40. sinon.stub(App, 'popover', Em.K);
  41. sinon.spy(view.get('controller'), 'loadStep');
  42. });
  43. afterEach(function () {
  44. App.popover.restore();
  45. view.get('controller').loadStep.restore();
  46. });
  47. it('should call loadStep', function () {
  48. view.didInsertElement();
  49. expect(view.get('controller').loadStep.calledOnce).to.equal(true);
  50. });
  51. it('should create popover', function () {
  52. view.didInsertElement();
  53. expect(App.popover.calledOnce).to.equal(true);
  54. });
  55. });
  56. });
  57. describe('App.WizardStep0ViewClusterNameInput', function () {
  58. beforeEach(function() {
  59. view = App.WizardStep0ViewClusterNameInput.create({
  60. parentView: Em.Object.create({
  61. controller: Em.Object.create({
  62. submit: Em.K
  63. })
  64. })
  65. });
  66. });
  67. describe('#keyPress', function() {
  68. beforeEach(function () {
  69. sinon.spy(view.get('parentView.controller'), 'submit');
  70. });
  71. afterEach(function () {
  72. view.get('parentView.controller').submit.restore();
  73. });
  74. it('should return true if pressed not Enter', function() {
  75. expect(view.keyPress({keyCode: 1})).to.equal(true);
  76. expect(view.get('parentView.controller').submit.called).to.equal(false);
  77. });
  78. it('should submit form if Enter pressed', function() {
  79. expect(view.keyPress({keyCode: 13})).to.equal(false);
  80. expect(view.get('parentView.controller').submit.calledOnce).to.equal(true);
  81. });
  82. });
  83. });