8
0

labeledinputview.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. } );
  47. describe( 'select()', () => {
  48. it( 'should select input value', () => {
  49. const spy = sinon.spy( view.inputView, 'select' );
  50. view.select();
  51. sinon.assert.calledOnce( spy );
  52. } );
  53. } );
  54. describe( 'focus()', () => {
  55. it( 'focuses the input in DOM', () => {
  56. const spy = sinon.spy( view.inputView, 'focus' );
  57. view.focus();
  58. sinon.assert.calledOnce( spy );
  59. } );
  60. } );
  61. } );