labeledinputview.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @license Copyright (c) 2003-2017, 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.init();
  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 label view', () => {
  31. expect( view.template.children.get( 0 ) ).to.equal( view.labelView );
  32. } );
  33. it( 'should have input view', () => {
  34. expect( view.template.children.get( 1 ) ).to.equal( view.inputView );
  35. } );
  36. } );
  37. describe( 'binding', () => {
  38. it( 'should bind view#text to view.labelView#label', () => {
  39. view.label = 'Foo bar';
  40. expect( view.labelView.text ).to.equal( 'Foo bar' );
  41. } );
  42. it( 'should bind view#value to view.inputView#value', () => {
  43. view.value = 'Lorem ipsum';
  44. expect( view.inputView.value ).to.equal( 'Lorem ipsum' );
  45. } );
  46. it( 'should bind view#isreadOnly to view.inputView#isReadOnly', () => {
  47. view.isReadOnly = false;
  48. expect( view.inputView.isReadOnly ).to.false;
  49. view.isReadOnly = true;
  50. expect( view.inputView.isReadOnly ).to.true;
  51. } );
  52. } );
  53. describe( 'select()', () => {
  54. it( 'should select input value', () => {
  55. const spy = sinon.spy( view.inputView, 'select' );
  56. view.select();
  57. sinon.assert.calledOnce( spy );
  58. } );
  59. } );
  60. describe( 'focus()', () => {
  61. it( 'focuses the input in DOM', () => {
  62. const spy = sinon.spy( view.inputView, 'focus' );
  63. view.focus();
  64. sinon.assert.calledOnce( spy );
  65. } );
  66. } );
  67. } );