boxededitoruiview.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 BoxedEditorUIView from '../../../src/editorui/boxed/boxededitoruiview';
  6. import Locale from '@ckeditor/ckeditor5-utils/src/locale';
  7. import ViewCollection from '../../../src/viewcollection';
  8. describe( 'BoxedEditorUIView', () => {
  9. let view, element;
  10. beforeEach( () => {
  11. view = new BoxedEditorUIView( new Locale() );
  12. view.render();
  13. element = view.element;
  14. } );
  15. afterEach( () => {
  16. view.destroy();
  17. } );
  18. describe( 'constructor()', () => {
  19. it( 'adds view collections', () => {
  20. expect( view.top ).to.be.instanceof( ViewCollection );
  21. expect( view.main ).to.be.instanceof( ViewCollection );
  22. } );
  23. it( 'bootstraps the view element from template', () => {
  24. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  25. expect( view.element.classList.contains( 'ck-editor' ) ).to.be.true;
  26. expect( view.element.classList.contains( 'ck-reset' ) ).to.be.true;
  27. expect( view.element.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
  28. expect( view.element.getAttribute( 'dir' ) ).to.equal( 'ltr' );
  29. expect( element.attributes[ 'aria-labelledby' ].value )
  30. .to.equal( view.element.firstChild.id )
  31. .to.match( /^ck-editor__label_\w+$/ );
  32. } );
  33. it( 'bootstraps the voice label from template', () => {
  34. const voiceLabel = view.element.firstChild;
  35. expect( voiceLabel.classList.contains( 'ck-voice-label' ) ).to.be.true;
  36. expect( voiceLabel.textContent ).to.equal( 'Rich Text Editor' );
  37. } );
  38. it( 'setups accessibility of the view element', () => {
  39. expect( element.attributes.getNamedItem( 'aria-labelledby' ).value ).to.equal(
  40. view.element.firstChild.id );
  41. expect( element.attributes.getNamedItem( 'role' ).value ).to.equal( 'application' );
  42. expect( element.attributes.getNamedItem( 'lang' ).value ).to.equal( 'en' );
  43. } );
  44. it( 'bootstraps the view region elements from template', () => {
  45. expect( element.childNodes[ 1 ].classList.contains( 'ck-editor__top' ) ).to.be.true;
  46. expect( element.childNodes[ 2 ].classList.contains( 'ck-editor__main' ) ).to.be.true;
  47. } );
  48. it( 'setups accessibility of the view region elements', () => {
  49. expect( element.childNodes[ 1 ].attributes.getNamedItem( 'role' ).value ).to.equal( 'presentation' );
  50. expect( element.childNodes[ 2 ].attributes.getNamedItem( 'role' ).value ).to.equal( 'presentation' );
  51. } );
  52. it( 'sets the proper "dir" attribute value when using RTL language', () => {
  53. const view = new BoxedEditorUIView( new Locale( { uiLanguage: 'ar' } ) );
  54. view.render();
  55. expect( view.element.getAttribute( 'dir' ) ).to.equal( 'rtl' );
  56. view.destroy();
  57. } );
  58. } );
  59. } );