document.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document */
  6. 'use strict';
  7. var modules = bender.amd.require( 'document/document', 'document/element' );
  8. describe( 'constructor', function() {
  9. it( 'should create Document with no data', function() {
  10. var Document = modules[ 'document/document' ];
  11. var Element = modules[ 'document/element' ];
  12. var document = new Document();
  13. expect( document ).to.have.property( 'root' ).that.is.instanceof( Element );
  14. expect( document.root ).to.have.property( 'name' ).that.equal( 'root' );
  15. } );
  16. } );
  17. describe( 'applyOperation', function() {
  18. it( 'should increase document version, execute operation and fire operationApplied', function() {
  19. var Document = modules[ 'document/document' ];
  20. var document = new Document();
  21. var operationApplied = sinon.spy();
  22. var operation = {
  23. baseVersion: 0,
  24. _execute: sinon.spy()
  25. };
  26. document.on( 'operationApplied', operationApplied );
  27. document.applyOperation( operation );
  28. expect( document.version ).to.be.equal( 1 );
  29. sinon.assert.calledOnce( operationApplied );
  30. sinon.assert.calledOnce( operation._execute );
  31. } );
  32. it( 'should throw an error on the operation base version and the document version is different', function() {
  33. var Document = modules[ 'document/document' ];
  34. var document = new Document();
  35. var operationApplied = sinon.spy();
  36. var operation = {
  37. baseVersion: 1
  38. };
  39. document.on( 'operationApplied', operationApplied );
  40. expect( function() {
  41. document.applyOperation( operation );
  42. } ).to.throw();
  43. } );
  44. } );