rename.js 1.1 KB

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