labeledinputview.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: ui, input */
  6. import LabeledInputView from 'ckeditor5-ui/src/labeledinput/labeledinputview';
  7. import InputView from 'ckeditor5-ui/src/inputtext/inputtextview';
  8. import LabelView from 'ckeditor5-ui/src/label/labelview';
  9. describe( 'LabeledInputView', () => {
  10. const locale = {};
  11. let view;
  12. beforeEach( () => {
  13. view = new LabeledInputView( locale, InputView );
  14. view.init();
  15. } );
  16. describe( 'constructor()', () => {
  17. it( 'should set view#locale', () => {
  18. expect( view.locale ).to.deep.equal( locale );
  19. } );
  20. it( 'should create view#inputView', () => {
  21. expect( view.inputView ).to.instanceOf( InputView );
  22. } );
  23. it( 'should create view#labelView', () => {
  24. expect( view.labelView ).to.instanceOf( LabelView );
  25. } );
  26. it( 'should pair inputView and labelView by unique id', () => {
  27. expect( view.labelView.for ).to.equal( view.inputView.id ).to.ok;
  28. } );
  29. } );
  30. describe( 'template', () => {
  31. it( 'should have label view', () => {
  32. expect( view.template.children.get( 0 ) ).to.equal( view.labelView );
  33. } );
  34. it( 'should have input view', () => {
  35. expect( view.template.children.get( 1 ) ).to.equal( view.inputView );
  36. } );
  37. } );
  38. describe( 'binding', () => {
  39. it( 'should bind view#text to view.labelView#label', () => {
  40. view.label = 'Foo bar';
  41. expect( view.labelView.text ).to.equal( 'Foo bar' );
  42. } );
  43. it( 'should bind view#value to view.inputView#value', () => {
  44. view.value = 'Lorem ipsum';
  45. expect( view.inputView.value ).to.equal( 'Lorem ipsum' );
  46. } );
  47. } );
  48. describe( 'select', () => {
  49. it( 'should select input value', () => {
  50. const spy = sinon.spy( view.inputView, 'select' );
  51. view.select();
  52. sinon.assert.calledOnce( spy );
  53. } );
  54. } );
  55. } );