rename.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 DowncastWriter from '../../../src/view/downcastwriter';
  6. import { parse } from '../../../src/dev-utils/view';
  7. import Document from '../../../src/view/document';
  8. import { StylesProcessor } from '../../../src/view/stylesmap';
  9. describe( 'DowncastWriter', () => {
  10. describe( 'rename()', () => {
  11. let root, foo, writer;
  12. before( () => {
  13. writer = new DowncastWriter( new Document( new StylesProcessor() ) );
  14. } );
  15. beforeEach( () => {
  16. root = parse( '<container:div><container:foo foo="1">xxx</container:foo></container:div>' );
  17. foo = root.getChild( 0 );
  18. } );
  19. it( 'should rename given element by inserting a new element in the place of the old one', () => {
  20. const text = foo.getChild( 0 );
  21. writer.rename( 'bar', foo );
  22. const bar = root.getChild( 0 );
  23. expect( bar ).not.to.equal( foo );
  24. expect( bar.name ).to.equal( 'bar' );
  25. expect( bar.getAttribute( 'foo' ) ).to.equal( '1' );
  26. expect( bar.getChild( 0 ) ).to.equal( text );
  27. } );
  28. it( 'should return a reference to the inserted element', () => {
  29. const bar = writer.rename( 'bar', foo );
  30. expect( bar ).to.equal( root.getChild( 0 ) );
  31. } );
  32. } );
  33. } );