utils.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import {
  6. createLabeledInputText,
  7. createLabeledDropdown
  8. } from '../../src/labeledfield/utils';
  9. import LabeledFieldView from '../../src/labeledfield/labeledfieldview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. import InputTextView from '../../src/inputtext/inputtextview';
  12. import DropdownView from '../../src/dropdown/dropdownview';
  13. describe( 'LabeledFieldView utils', () => {
  14. let locale;
  15. testUtils.createSinonSandbox();
  16. beforeEach( () => {
  17. locale = { t: val => val };
  18. } );
  19. describe( 'createLabeledInputText()', () => {
  20. let labeledInput;
  21. beforeEach( () => {
  22. labeledInput = new LabeledFieldView( locale, createLabeledInputText );
  23. } );
  24. afterEach( () => {
  25. labeledInput.destroy();
  26. } );
  27. it( 'should create an InputTextView instance', () => {
  28. expect( labeledInput.fieldView ).to.be.instanceOf( InputTextView );
  29. } );
  30. it( 'should pass the Locale to the input', () => {
  31. expect( labeledInput.fieldView.locale ).to.equal( locale );
  32. } );
  33. it( 'should set input #id and #ariaDescribedById', () => {
  34. labeledInput.render();
  35. expect( labeledInput.fieldView.id ).to.equal( labeledInput.labelView.for );
  36. expect( labeledInput.fieldView.ariaDescribedById ).to.equal( labeledInput.statusView.element.id );
  37. } );
  38. it( 'should bind input\'s #isReadOnly to labeledInput#isEnabled', () => {
  39. labeledInput.isEnabled = true;
  40. expect( labeledInput.fieldView.isReadOnly ).to.be.false;
  41. labeledInput.isEnabled = false;
  42. expect( labeledInput.fieldView.isReadOnly ).to.be.true;
  43. } );
  44. it( 'should bind input\'s #hasError to labeledInput#errorText', () => {
  45. labeledInput.errorText = 'some error';
  46. expect( labeledInput.fieldView.hasError ).to.be.true;
  47. labeledInput.errorText = null;
  48. expect( labeledInput.fieldView.hasError ).to.be.false;
  49. } );
  50. it( 'should clean labeledInput#errorText upon input\'s DOM "update" event', () => {
  51. labeledInput.errorText = 'some error';
  52. labeledInput.fieldView.fire( 'input' );
  53. expect( labeledInput.errorText ).to.be.null;
  54. } );
  55. } );
  56. describe( 'createLabeledDropdown', () => {
  57. let labeledDropdown;
  58. beforeEach( () => {
  59. labeledDropdown = new LabeledFieldView( locale, createLabeledDropdown );
  60. } );
  61. afterEach( () => {
  62. labeledDropdown.destroy();
  63. } );
  64. it( 'should create a DropdownView', () => {
  65. expect( labeledDropdown.fieldView ).to.be.instanceOf( DropdownView );
  66. } );
  67. it( 'should pass the Locale to the dropdown', () => {
  68. expect( labeledDropdown.fieldView.locale ).to.equal( locale );
  69. } );
  70. it( 'should set dropdown\'s #id and #ariaDescribedById', () => {
  71. labeledDropdown.render();
  72. expect( labeledDropdown.fieldView.id ).to.equal( labeledDropdown.labelView.for );
  73. expect( labeledDropdown.fieldView.ariaDescribedById ).to.equal( labeledDropdown.statusView.element.id );
  74. } );
  75. it( 'should bind dropdown\'s #isEnabled to the labeled view', () => {
  76. labeledDropdown.isEnabled = true;
  77. expect( labeledDropdown.fieldView.isEnabled ).to.be.true;
  78. labeledDropdown.isEnabled = false;
  79. expect( labeledDropdown.fieldView.isEnabled ).to.be.false;
  80. } );
  81. } );
  82. } );