DiffCodecTests.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* eslint-disable
  2. no-return-assign,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const sinon = require('sinon')
  13. const { expect } = require('chai')
  14. const modulePath = '../../../../app/js/DiffCodec.js'
  15. const SandboxedModule = require('sandboxed-module')
  16. describe('DiffCodec', function () {
  17. beforeEach(function () {
  18. this.callback = sinon.stub()
  19. return (this.DiffCodec = SandboxedModule.require(modulePath))
  20. })
  21. return describe('diffAsShareJsOps', function () {
  22. it('should insert new text correctly', function (done) {
  23. this.before = ['hello world']
  24. this.after = ['hello beautiful world']
  25. return this.DiffCodec.diffAsShareJsOp(
  26. this.before,
  27. this.after,
  28. (error, ops) => {
  29. if (error) return done(error)
  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. if (error) return done(error)
  48. expect(ops).to.deep.equal([
  49. { i: 'tall ', p: 4 },
  50. { i: 'red ', p: 29 },
  51. ])
  52. return done()
  53. }
  54. )
  55. })
  56. it('should delete text correctly', function (done) {
  57. this.before = ['hello beautiful world']
  58. this.after = ['hello world']
  59. return this.DiffCodec.diffAsShareJsOp(
  60. this.before,
  61. this.after,
  62. (error, ops) => {
  63. if (error) return done(error)
  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. if (error) return done(error)
  82. expect(ops).to.deep.equal([
  83. { d: 'tall ', p: 4 },
  84. { d: 'red ', p: 24 },
  85. ])
  86. return done()
  87. }
  88. )
  89. })
  90. })
  91. })