8
0

utils.js 3.1 KB

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