renamedelta.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Document from '../../../src/model/document';
  6. import Element from '../../../src/model/element';
  7. import Text from '../../../src/model/text';
  8. import RenameDelta from '../../../src/model/delta/renamedelta';
  9. describe( 'RenameDelta', () => {
  10. let renameDelta, doc, root;
  11. beforeEach( () => {
  12. doc = new Document();
  13. root = doc.createRoot();
  14. renameDelta = new RenameDelta();
  15. } );
  16. describe( 'constructor()', () => {
  17. it( 'should create rename delta with no operations added', () => {
  18. expect( renameDelta.operations.length ).to.equal( 0 );
  19. } );
  20. } );
  21. describe( 'type', () => {
  22. it( 'should be equal to rename', () => {
  23. expect( renameDelta.type ).to.equal( 'rename' );
  24. } );
  25. } );
  26. describe( 'getReversed', () => {
  27. it( 'should return instance of RenameDelta', () => {
  28. const reversed = renameDelta.getReversed();
  29. expect( reversed ).to.be.instanceof( RenameDelta );
  30. } );
  31. it( 'should return correct RenameDelta', () => {
  32. root.appendChildren( new Element( 'p', null, new Text( 'abc' ) ) );
  33. const batch = doc.batch();
  34. batch.rename( root.getChild( 0 ), 'h' );
  35. const reversed = batch.deltas[ 0 ].getReversed();
  36. reversed.operations.forEach( operation => {
  37. doc.applyOperation( operation );
  38. } );
  39. expect( root.maxOffset ).to.equal( 1 );
  40. expect( root.getChild( 0 ) ).to.have.property( 'name', 'p' );
  41. } );
  42. } );
  43. it( 'should provide proper className', () => {
  44. expect( RenameDelta.className ).to.equal( 'engine.model.delta.RenameDelta' );
  45. } );
  46. } );