rename.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Writer from '../../../src/view/writer';
  6. import { parse } from '../../../src/dev-utils/view';
  7. import Document from '../../../src/view/document';
  8. describe( 'Writer', () => {
  9. describe( 'rename()', () => {
  10. let root, foo, writer;
  11. before( () => {
  12. writer = new Writer( new Document() );
  13. } );
  14. beforeEach( () => {
  15. root = parse( '<container:div><container:foo foo="1">xxx</container:foo></container:div>' );
  16. foo = root.getChild( 0 );
  17. } );
  18. it( 'should rename given element by inserting a new element in the place of the old one', () => {
  19. const text = foo.getChild( 0 );
  20. writer.rename( foo, 'bar' );
  21. const bar = root.getChild( 0 );
  22. expect( bar ).not.to.equal( foo );
  23. expect( bar.name ).to.equal( 'bar' );
  24. expect( bar.getAttribute( 'foo' ) ).to.equal( '1' );
  25. expect( bar.getChild( 0 ) ).to.equal( text );
  26. } );
  27. it( 'should return a reference to the inserted element', () => {
  28. const bar = writer.rename( foo, 'bar' );
  29. expect( bar ).to.equal( root.getChild( 0 ) );
  30. } );
  31. } );
  32. } );