rename.js 1.0 KB

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