| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treemodel, delta */
- 'use strict';
- /* jshint unused: false */
- import deltas from '/ckeditor5/core/treemodel/delta/basic-deltas.js';
- import Document from '/ckeditor5/core/treemodel/document.js';
- import Batch from '/ckeditor5/core/treemodel/batch.js';
- import { register } from '/ckeditor5/core/treemodel/batch.js';
- import Delta from '/ckeditor5/core/treemodel/delta/delta.js';
- import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
- class TestDelta extends Delta {
- constructor( batch ) {
- super( batch, [] );
- }
- }
- describe( 'Batch', () => {
- it( 'should have registered basic methods', () => {
- const batch = new Batch( new Document() );
- expect( batch.setAttr ).to.be.a( 'function' );
- expect( batch.removeAttr ).to.be.a( 'function' );
- } );
- describe( 'register', () => {
- afterEach( () => {
- delete Batch.prototype.foo;
- } );
- it( 'should register function to the batch prototype', () => {
- const spy = sinon.spy();
- register( 'foo', spy );
- const batch = new Batch( new Document() );
- batch.foo();
- expect( spy.calledOnce ).to.be.true;
- } );
- it( 'should throw if one try to register the same batch twice', () => {
- register( 'foo', () => {} );
- expect( () => {
- register( 'foo', () => {} );
- } ).to.throw( CKEditorError, /^batch-register-taken/ );
- } );
- } );
- describe( 'addDelta', () => {
- it( 'should add delta to the batch', () => {
- const batch = new Batch( new Document() );
- const deltaA = new Delta();
- const deltaB = new Delta();
- batch.addDelta( deltaA );
- batch.addDelta( deltaB );
- expect( batch.deltas.length ).to.equal( 2 );
- expect( batch.deltas[ 0 ] ).to.equal( deltaA );
- expect( batch.deltas[ 1 ] ).to.equal( deltaB );
- } );
- it( 'should fire batch event on it\'s document when first delta is added to the batch', () => {
- const doc = new Document();
- const batch = new Batch( doc );
- const spy = sinon.spy();
- doc.on( 'batch', spy );
- batch.addDelta( new Delta() );
- expect( spy.calledOnce ).to.be.true;
- batch.addDelta( new Delta() );
- expect( spy.calledOnce ).to.be.true;
- } );
- } );
- } );
|