8
0

batch.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treemodel, delta */
  6. 'use strict';
  7. import Batch from '/ckeditor5/core/treemodel/batch.js';
  8. import Delta from '/ckeditor5/core/treemodel/delta/delta.js';
  9. import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
  10. describe( 'Batch', () => {
  11. it( 'should have registered basic methods', () => {
  12. const batch = new Batch();
  13. expect( batch.setAttr ).to.be.a( 'function' );
  14. expect( batch.removeAttr ).to.be.a( 'function' );
  15. } );
  16. describe( 'Batch.register', () => {
  17. let TestDelta;
  18. before( () => {
  19. TestDelta = class extends Delta {
  20. constructor( batch ) {
  21. super( batch, [] );
  22. }
  23. };
  24. } );
  25. afterEach( () => {
  26. delete Batch.prototype.foo;
  27. } );
  28. it( 'should register function which return an delta', () => {
  29. Batch.register( 'foo', function() {
  30. this.addDelta( new TestDelta() );
  31. } );
  32. const batch = new Batch();
  33. batch.foo();
  34. expect( batch.deltas.length ).to.equal( 1 );
  35. expect( batch.deltas[ 0 ] ).to.be.instanceof( TestDelta );
  36. } );
  37. it( 'should register function which return an multiple deltas', () => {
  38. Batch.register( 'foo', function() {
  39. this.addDelta( new TestDelta() );
  40. this.addDelta( new TestDelta() );
  41. } );
  42. const batch = new Batch();
  43. batch.foo();
  44. expect( batch.deltas.length ).to.equal( 2 );
  45. expect( batch.deltas[ 0 ] ).to.be.instanceof( TestDelta );
  46. expect( batch.deltas[ 1 ] ).to.be.instanceof( TestDelta );
  47. } );
  48. it( 'should throw if one try to register the same batch twice', () => {
  49. Batch.register( 'foo', () => {} );
  50. expect( () => {
  51. Batch.register( 'foo', () => {} );
  52. } ).to.throw( CKEditorError, /^batch-register-taken/ );
  53. } );
  54. } );
  55. } );