inputtextview.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import InputTextView from '../../src/inputtext/inputtextview';
  6. describe( 'InputTextView', () => {
  7. let view;
  8. beforeEach( () => {
  9. view = new InputTextView();
  10. view.init();
  11. } );
  12. describe( 'constructor()', () => {
  13. it( 'should creates element from template', () => {
  14. expect( view.element.tagName ).to.equal( 'INPUT' );
  15. expect( view.element.type ).to.equal( 'text' );
  16. expect( view.element.classList.contains( 'ck-input' ) ).to.be.true;
  17. expect( view.element.classList.contains( 'ck-input-text' ) ).to.be.true;
  18. } );
  19. } );
  20. describe( 'DOM bindings', () => {
  21. beforeEach( () => {
  22. view.value = 'foo';
  23. view.id = 'bar';
  24. } );
  25. describe( 'value', () => {
  26. it( 'should react on view#value', () => {
  27. expect( view.element.value ).to.equal( 'foo' );
  28. view.value = 'baz';
  29. expect( view.element.value ).to.equal( 'baz' );
  30. } );
  31. it( 'should set to empty string when using `falsy` values', () => {
  32. [ undefined, false, null ].forEach( value => {
  33. view.value = value;
  34. expect( view.element.value ).to.equal( '' );
  35. } );
  36. } );
  37. } );
  38. describe( 'id', () => {
  39. it( 'should react on view#id', () => {
  40. expect( view.element.id ).to.equal( 'bar' );
  41. view.id = 'baz';
  42. expect( view.element.id ).to.equal( 'baz' );
  43. } );
  44. } );
  45. describe( 'placeholder', () => {
  46. it( 'should react on view#placeholder', () => {
  47. expect( view.element.placeholder ).to.equal( '' );
  48. view.placeholder = 'baz';
  49. expect( view.element.placeholder ).to.equal( 'baz' );
  50. } );
  51. } );
  52. describe( 'isReadOnly', () => {
  53. it( 'should react on view#isReadOnly', () => {
  54. expect( view.element.readOnly ).to.false;
  55. view.isReadOnly = true;
  56. expect( view.element.readOnly ).to.true;
  57. } );
  58. } );
  59. } );
  60. describe( 'select()', () => {
  61. it( 'should select input value', () => {
  62. const selectSpy = sinon.spy( view.element, 'select' );
  63. view.select();
  64. expect( selectSpy.calledOnce ).to.true;
  65. selectSpy.restore();
  66. } );
  67. } );
  68. describe( 'focus()', () => {
  69. it( 'focuses the input in DOM', () => {
  70. const spy = sinon.spy( view.element, 'focus' );
  71. view.focus();
  72. sinon.assert.calledOnce( spy );
  73. } );
  74. } );
  75. } );