labeledinputview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import LabeledInputView from '../../src/labeledinput/labeledinputview';
  6. import InputView from '../../src/inputtext/inputtextview';
  7. import LabelView from '../../src/label/labelview';
  8. describe( 'LabeledInputView', () => {
  9. const locale = {};
  10. let view;
  11. beforeEach( () => {
  12. view = new LabeledInputView( locale, InputView );
  13. view.render();
  14. } );
  15. describe( 'constructor()', () => {
  16. it( 'should set view#locale', () => {
  17. expect( view.locale ).to.deep.equal( locale );
  18. } );
  19. it( 'should create view#inputView', () => {
  20. expect( view.inputView ).to.instanceOf( InputView );
  21. } );
  22. it( 'should create view#labelView', () => {
  23. expect( view.labelView ).to.instanceOf( LabelView );
  24. } );
  25. it( 'should pair inputView and labelView by unique id', () => {
  26. expect( view.labelView.for ).to.equal( view.inputView.id ).to.ok;
  27. } );
  28. } );
  29. describe( 'template', () => {
  30. it( 'should have the CSS class', () => {
  31. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  32. expect( view.element.classList.contains( 'ck-labeled-input' ) ).to.be.true;
  33. } );
  34. it( 'should have label view', () => {
  35. expect( view.template.children[ 0 ] ).to.equal( view.labelView );
  36. } );
  37. it( 'should have input view', () => {
  38. expect( view.template.children[ 1 ] ).to.equal( view.inputView );
  39. } );
  40. describe( 'DOM bindings', () => {
  41. describe( 'class', () => {
  42. it( 'should react on view#isReadOnly', () => {
  43. view.isReadOnly = false;
  44. expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.false;
  45. view.isReadOnly = true;
  46. expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.true;
  47. } );
  48. } );
  49. } );
  50. } );
  51. describe( 'binding', () => {
  52. it( 'should bind view#text to view.labelView#label', () => {
  53. view.label = 'Foo bar';
  54. expect( view.labelView.text ).to.equal( 'Foo bar' );
  55. } );
  56. it( 'should bind view#value to view.inputView#value', () => {
  57. view.value = 'Lorem ipsum';
  58. expect( view.inputView.value ).to.equal( 'Lorem ipsum' );
  59. } );
  60. it( 'should bind view#isreadOnly to view.inputView#isReadOnly', () => {
  61. view.isReadOnly = false;
  62. expect( view.inputView.isReadOnly ).to.false;
  63. view.isReadOnly = true;
  64. expect( view.inputView.isReadOnly ).to.true;
  65. } );
  66. } );
  67. describe( 'select()', () => {
  68. it( 'should select input value', () => {
  69. const spy = sinon.spy( view.inputView, 'select' );
  70. view.select();
  71. sinon.assert.calledOnce( spy );
  72. } );
  73. } );
  74. describe( 'focus()', () => {
  75. it( 'focuses the input in DOM', () => {
  76. const spy = sinon.spy( view.inputView, 'focus' );
  77. view.focus();
  78. sinon.assert.calledOnce( spy );
  79. } );
  80. } );
  81. } );