8
0

labeledinputview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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-labeled-input' ) ).to.be.true;
  32. } );
  33. it( 'should have label view', () => {
  34. expect( view.template.children[ 0 ] ).to.equal( view.labelView );
  35. } );
  36. it( 'should have input view', () => {
  37. expect( view.template.children[ 1 ] ).to.equal( view.inputView );
  38. } );
  39. describe( 'DOM bindings', () => {
  40. describe( 'class', () => {
  41. it( 'should react on view#isReadOnly', () => {
  42. view.isReadOnly = false;
  43. expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.false;
  44. view.isReadOnly = true;
  45. expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.true;
  46. } );
  47. } );
  48. } );
  49. } );
  50. describe( 'binding', () => {
  51. it( 'should bind view#text to view.labelView#label', () => {
  52. view.label = 'Foo bar';
  53. expect( view.labelView.text ).to.equal( 'Foo bar' );
  54. } );
  55. it( 'should bind view#value to view.inputView#value', () => {
  56. view.value = 'Lorem ipsum';
  57. expect( view.inputView.value ).to.equal( 'Lorem ipsum' );
  58. } );
  59. it( 'should bind view#isreadOnly to view.inputView#isReadOnly', () => {
  60. view.isReadOnly = false;
  61. expect( view.inputView.isReadOnly ).to.false;
  62. view.isReadOnly = true;
  63. expect( view.inputView.isReadOnly ).to.true;
  64. } );
  65. } );
  66. describe( 'select()', () => {
  67. it( 'should select input value', () => {
  68. const spy = sinon.spy( view.inputView, 'select' );
  69. view.select();
  70. sinon.assert.calledOnce( spy );
  71. } );
  72. } );
  73. describe( 'focus()', () => {
  74. it( 'focuses the input in DOM', () => {
  75. const spy = sinon.spy( view.inputView, 'focus' );
  76. view.focus();
  77. sinon.assert.calledOnce( spy );
  78. } );
  79. } );
  80. } );