rename.js 1.1 KB

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