cleanup.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /* globals document */
  6. import Locale from '@ckeditor/ckeditor5-utils/src/locale';
  7. import EditorUIView from '@ckeditor/ckeditor5-ui/src/editorui/editoruiview';
  8. import { removeEditorBodyOrphans } from '../_utils/cleanup';
  9. describe( 'cleanup util', () => {
  10. describe( 'removeEditorBodyOrphans()', () => {
  11. it( 'removes the body collection wrapper', () => {
  12. const locale = new Locale();
  13. const uiViews = [ new EditorUIView( locale ), new EditorUIView( locale ) ];
  14. for ( const view of uiViews ) {
  15. view.render();
  16. }
  17. // Body collection reuses its wrapper, hence 1.
  18. expect( document.querySelectorAll( '.ck-body-wrapper' ) ).to.have.length( 1 );
  19. removeEditorBodyOrphans();
  20. expect( document.querySelectorAll( '.ck-body-wrapper' ) ).to.have.length( 0 );
  21. expect( document.querySelectorAll( '.ck-body' ) ).to.have.length( 0 );
  22. } );
  23. // Right now, body collection should reuse its wrapper, but it doesn't cost us much to
  24. // ensure that we remove all.
  25. it( 'removes all body collection wrappers', () => {
  26. const wrapper = document.createElement( 'div' );
  27. wrapper.classList.add( 'ck-body-wrapper' );
  28. document.body.appendChild( wrapper );
  29. document.body.appendChild( wrapper.cloneNode() );
  30. removeEditorBodyOrphans();
  31. expect( document.querySelectorAll( '.ck-body-wrapper' ) ).to.have.length( 0 );
  32. } );
  33. } );
  34. } );