utils.js 3.1 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/labeledview/utils';
  9. import LabeledView from '../../src/labeledview/labeledview';
  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( 'LabeledView utils', () => {
  14. let locale;
  15. testUtils.createSinonSandbox();
  16. beforeEach( () => {
  17. locale = { t: val => val };
  18. } );
  19. describe( 'createLabeledInputText()', () => {
  20. let labeledView;
  21. beforeEach( () => {
  22. labeledView = new LabeledView( locale, createLabeledInputText );
  23. } );
  24. afterEach( () => {
  25. labeledView.destroy();
  26. } );
  27. it( 'should create an InputTextView instance', () => {
  28. expect( labeledView.view ).to.be.instanceOf( InputTextView );
  29. } );
  30. it( 'should pass the Locale to the input', () => {
  31. expect( labeledView.view.locale ).to.equal( locale );
  32. } );
  33. it( 'should set input #id and #ariaDescribedById', () => {
  34. labeledView.render();
  35. expect( labeledView.view.id ).to.equal( labeledView.labelView.for );
  36. expect( labeledView.view.ariaDescribedById ).to.equal( labeledView.statusView.element.id );
  37. } );
  38. it( 'should bind input\'s #isReadOnly to LabeledView#isEnabled', () => {
  39. labeledView.isEnabled = true;
  40. expect( labeledView.view.isReadOnly ).to.be.false;
  41. labeledView.isEnabled = false;
  42. expect( labeledView.view.isReadOnly ).to.be.true;
  43. } );
  44. it( 'should bind input\'s #hasError to LabeledView#errorText', () => {
  45. labeledView.errorText = 'some error';
  46. expect( labeledView.view.hasError ).to.be.true;
  47. labeledView.errorText = null;
  48. expect( labeledView.view.hasError ).to.be.false;
  49. } );
  50. it( 'should clean LabeledView#errorText upon input\'s DOM "update" event', () => {
  51. labeledView.errorText = 'some error';
  52. labeledView.view.fire( 'input' );
  53. expect( labeledView.errorText ).to.be.null;
  54. } );
  55. } );
  56. describe( 'createLabeledDropdown', () => {
  57. let labeledView;
  58. beforeEach( () => {
  59. labeledView = new LabeledView( locale, createLabeledDropdown );
  60. } );
  61. afterEach( () => {
  62. labeledView.destroy();
  63. } );
  64. it( 'should create a DropdownView', () => {
  65. expect( labeledView.view ).to.be.instanceOf( DropdownView );
  66. } );
  67. it( 'should pass the Locale to the dropdown', () => {
  68. expect( labeledView.view.locale ).to.equal( locale );
  69. } );
  70. it( 'should set dropdown\'s #id and #ariaDescribedById', () => {
  71. labeledView.render();
  72. expect( labeledView.view.id ).to.equal( labeledView.labelView.for );
  73. expect( labeledView.view.ariaDescribedById ).to.equal( labeledView.statusView.element.id );
  74. } );
  75. it( 'should bind dropdown\'s #isEnabled to the labeled view', () => {
  76. labeledView.isEnabled = true;
  77. expect( labeledView.view.isEnabled ).to.be.true;
  78. labeledView.isEnabled = false;
  79. expect( labeledView.view.isEnabled ).to.be.false;
  80. } );
  81. } );
  82. } );