DiffCodecTests.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const sinon = require('sinon')
  14. const chai = require('chai')
  15. const should = chai.should()
  16. const { expect } = chai
  17. const modulePath = '../../../../app/js/DiffCodec.js'
  18. const SandboxedModule = require('sandboxed-module')
  19. describe('DiffCodec', function () {
  20. beforeEach(function () {
  21. this.callback = sinon.stub()
  22. return (this.DiffCodec = SandboxedModule.require(modulePath))
  23. })
  24. return describe('diffAsShareJsOps', function () {
  25. it('should insert new text correctly', function (done) {
  26. this.before = ['hello world']
  27. this.after = ['hello beautiful world']
  28. return this.DiffCodec.diffAsShareJsOp(
  29. this.before,
  30. this.after,
  31. (error, ops) => {
  32. expect(ops).to.deep.equal([
  33. {
  34. i: 'beautiful ',
  35. p: 6
  36. }
  37. ])
  38. return done()
  39. }
  40. )
  41. })
  42. it('should shift later inserts by previous inserts', function (done) {
  43. this.before = ['the boy played with the ball']
  44. this.after = ['the tall boy played with the red ball']
  45. return this.DiffCodec.diffAsShareJsOp(
  46. this.before,
  47. this.after,
  48. (error, ops) => {
  49. expect(ops).to.deep.equal([
  50. { i: 'tall ', p: 4 },
  51. { i: 'red ', p: 29 }
  52. ])
  53. return done()
  54. }
  55. )
  56. })
  57. it('should delete text correctly', function (done) {
  58. this.before = ['hello beautiful world']
  59. this.after = ['hello world']
  60. return this.DiffCodec.diffAsShareJsOp(
  61. this.before,
  62. this.after,
  63. (error, ops) => {
  64. expect(ops).to.deep.equal([
  65. {
  66. d: 'beautiful ',
  67. p: 6
  68. }
  69. ])
  70. return done()
  71. }
  72. )
  73. })
  74. return it('should shift later deletes by the first deletes', function (done) {
  75. this.before = ['the tall boy played with the red ball']
  76. this.after = ['the boy played with the ball']
  77. return this.DiffCodec.diffAsShareJsOp(
  78. this.before,
  79. this.after,
  80. (error, ops) => {
  81. expect(ops).to.deep.equal([
  82. { d: 'tall ', p: 4 },
  83. { d: 'red ', p: 24 }
  84. ])
  85. return done()
  86. }
  87. )
  88. })
  89. })
  90. })