DiffCodecTests.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 { expect } = require('chai')
  15. const modulePath = '../../../../app/js/DiffCodec.js'
  16. const SandboxedModule = require('sandboxed-module')
  17. describe('DiffCodec', function () {
  18. beforeEach(function () {
  19. this.callback = sinon.stub()
  20. return (this.DiffCodec = SandboxedModule.require(modulePath))
  21. })
  22. return describe('diffAsShareJsOps', function () {
  23. it('should insert new text correctly', function (done) {
  24. this.before = ['hello world']
  25. this.after = ['hello beautiful world']
  26. return this.DiffCodec.diffAsShareJsOp(
  27. this.before,
  28. this.after,
  29. (error, ops) => {
  30. expect(ops).to.deep.equal([
  31. {
  32. i: 'beautiful ',
  33. p: 6,
  34. },
  35. ])
  36. return done()
  37. }
  38. )
  39. })
  40. it('should shift later inserts by previous inserts', function (done) {
  41. this.before = ['the boy played with the ball']
  42. this.after = ['the tall boy played with the red ball']
  43. return this.DiffCodec.diffAsShareJsOp(
  44. this.before,
  45. this.after,
  46. (error, ops) => {
  47. expect(ops).to.deep.equal([
  48. { i: 'tall ', p: 4 },
  49. { i: 'red ', p: 29 },
  50. ])
  51. return done()
  52. }
  53. )
  54. })
  55. it('should delete text correctly', function (done) {
  56. this.before = ['hello beautiful world']
  57. this.after = ['hello world']
  58. return this.DiffCodec.diffAsShareJsOp(
  59. this.before,
  60. this.after,
  61. (error, ops) => {
  62. expect(ops).to.deep.equal([
  63. {
  64. d: 'beautiful ',
  65. p: 6,
  66. },
  67. ])
  68. return done()
  69. }
  70. )
  71. })
  72. return it('should shift later deletes by the first deletes', function (done) {
  73. this.before = ['the tall boy played with the red ball']
  74. this.after = ['the boy played with the ball']
  75. return this.DiffCodec.diffAsShareJsOp(
  76. this.before,
  77. this.after,
  78. (error, ops) => {
  79. expect(ops).to.deep.equal([
  80. { d: 'tall ', p: 4 },
  81. { d: 'red ', p: 24 },
  82. ])
  83. return done()
  84. }
  85. )
  86. })
  87. })
  88. })