8
0

nooperation.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const modules = bender.amd.require(
  8. 'document/document',
  9. 'document/position',
  10. 'document/range',
  11. 'document/attribute',
  12. 'document/operation/nooperation',
  13. 'document/operation/insertoperation',
  14. 'document/operation/changeoperation',
  15. 'document/operation/moveoperation'
  16. );
  17. describe( 'NoOperation', () => {
  18. let Document, Position, Range, Attribute, NoOperation, InsertOperation, ChangeOperation, MoveOperation;
  19. before( function() {
  20. Document = modules[ 'document/document' ];
  21. Position = modules[ 'document/position' ];
  22. Range = modules[ 'document/range' ];
  23. Attribute = modules[ 'document/attribute' ];
  24. NoOperation = modules[ 'document/operation/nooperation' ];
  25. InsertOperation = modules[ 'document/operation/insertoperation' ];
  26. ChangeOperation = modules[ 'document/operation/changeoperation' ];
  27. MoveOperation = modules[ 'document/operation/moveoperation' ];
  28. } );
  29. let noop, doc, root;
  30. beforeEach( () => {
  31. noop = new NoOperation( 0 );
  32. doc = new Document();
  33. root = doc.createRoot( 'root' );
  34. } );
  35. function expectNoTransformation( noop, transformBy ) {
  36. const transOp = noop.getTransformedBy( transformBy );
  37. expect( transOp ).to.be.instanceof( NoOperation );
  38. expect( transOp.baseVersion ).to.equal( 0 );
  39. }
  40. it( 'should not throw an error when applied', () => {
  41. expect( () => doc.applyOperation( noop ) ).to.not.throw( Error );
  42. } );
  43. it( 'should create a do-nothing operation as a reverse', () => {
  44. const reverse = noop.getReversed();
  45. expect( reverse ).to.be.an.instanceof( NoOperation );
  46. expect( reverse.baseVersion ).to.equal( 1 );
  47. } );
  48. it( 'should create a do-nothing operation having same parameters when cloned', () => {
  49. const clone = noop.clone();
  50. expect( clone ).to.be.an.instanceof( NoOperation );
  51. expect( clone.baseVersion ).to.equal( 0 );
  52. } );
  53. it( 'should not change when transformed by InsertOperation', () => {
  54. const transformBy = new InsertOperation( new Position( [ 0 ], root ), 'abc', 0 );
  55. expectNoTransformation( noop, transformBy );
  56. } );
  57. it( 'should not change when transformed by ChangeOperation', () => {
  58. const transformBy = new ChangeOperation(
  59. new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
  60. null,
  61. new Attribute( 'foo', 'bar' ),
  62. 0
  63. );
  64. expectNoTransformation( noop, transformBy );
  65. } );
  66. it( 'should not change when transformed by MoveOperation', () => {
  67. const transformBy = new MoveOperation(
  68. new Position( [ 0 ], root ),
  69. new Position( [ 1 ], root ),
  70. 4,
  71. 0
  72. );
  73. expectNoTransformation( noop, transformBy );
  74. } );
  75. it( 'should not change when transformed by NoOperation', () => {
  76. const transformBy = new NoOperation( 0 );
  77. expectNoTransformation( noop, transformBy );
  78. } );
  79. } );