editoruiview.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import EditorUIView from '../../src/editorui/editoruiview';
  8. import ViewCollection from '../../src/viewcollection';
  9. import Locale from '@ckeditor/ckeditor5-utils/src/locale';
  10. describe( 'EditorUIView', () => {
  11. let view, locale;
  12. testUtils.createSinonSandbox();
  13. beforeEach( () => {
  14. locale = new Locale();
  15. view = new EditorUIView( locale );
  16. view.render();
  17. } );
  18. afterEach( () => {
  19. view.destroy();
  20. } );
  21. describe( 'constructor()', () => {
  22. it( 'accepts locale', () => {
  23. expect( view.locale ).to.equal( locale );
  24. } );
  25. it( 'sets all the properties', () => {
  26. expect( view.body ).to.be.instanceof( ViewCollection );
  27. } );
  28. } );
  29. describe( 'render()', () => {
  30. it( 'sets the right class set to the body region', () => {
  31. const el = view._bodyCollectionContainer;
  32. expect( el.parentNode ).to.equal( document.body );
  33. expect( el.classList.contains( 'ck' ) ).to.be.true;
  34. expect( el.classList.contains( 'ck-body' ) ).to.be.true;
  35. expect( el.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
  36. expect( el.classList.contains( 'ck-reset_all' ) ).to.be.true;
  37. } );
  38. it( 'sets the right dir attribute to the body region (LTR)', () => {
  39. const el = view._bodyCollectionContainer;
  40. expect( el.getAttribute( 'dir' ) ).to.equal( 'ltr' );
  41. } );
  42. it( 'sets the right dir attribute to the body region (RTL)', () => {
  43. const locale = new Locale( { uiLanguage: 'ar' } );
  44. const view = new EditorUIView( locale );
  45. view.render();
  46. const el = view._bodyCollectionContainer;
  47. expect( el.getAttribute( 'dir' ) ).to.equal( 'rtl' );
  48. view.destroy();
  49. } );
  50. } );
  51. describe( 'destroy()', () => {
  52. it( 'removes the body region container', () => {
  53. const el = view._bodyCollectionContainer;
  54. view.destroy();
  55. expect( el.parentNode ).to.be.null;
  56. } );
  57. it( 'can be called multiple times', () => {
  58. expect( () => {
  59. view.destroy();
  60. view.destroy();
  61. } ).to.not.throw();
  62. } );
  63. } );
  64. } );