inputtextview.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import InputTextView from 'ckeditor5-ui/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. } );
  46. describe( 'select()', () => {
  47. it( 'should select input value', () => {
  48. const selectSpy = sinon.spy( view.element, 'select' );
  49. view.select();
  50. expect( selectSpy.calledOnce ).to.true;
  51. selectSpy.restore();
  52. } );
  53. } );
  54. describe( 'focus()', () => {
  55. it( 'focuses the input in DOM', () => {
  56. const spy = sinon.spy( view.element, 'focus' );
  57. view.focus();
  58. sinon.assert.calledOnce( spy );
  59. } );
  60. } );
  61. } );