DiffCodecTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  5. */
  6. const sinon = require('sinon');
  7. const chai = require('chai');
  8. const should = chai.should();
  9. const {
  10. expect
  11. } = chai;
  12. const modulePath = "../../../../app/js/DiffCodec.js";
  13. const SandboxedModule = require('sandboxed-module');
  14. describe("DiffCodec", function() {
  15. beforeEach(function() {
  16. this.callback = sinon.stub();
  17. return this.DiffCodec = SandboxedModule.require(modulePath);
  18. });
  19. return describe("diffAsShareJsOps", function() {
  20. it("should insert new text correctly", function(done) {
  21. this.before = ["hello world"];
  22. this.after = ["hello beautiful world"];
  23. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, function(error, ops) {
  24. expect(ops).to.deep.equal([{
  25. i: "beautiful ",
  26. p: 6
  27. }
  28. ]);
  29. return done();
  30. });
  31. });
  32. it("should shift later inserts by previous inserts", function(done) {
  33. this.before = ["the boy played with the ball"];
  34. this.after = ["the tall boy played with the red ball"];
  35. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, function(error, ops) {
  36. expect(ops).to.deep.equal([
  37. { i: "tall ", p: 4 },
  38. { i: "red ", p: 29 }
  39. ]);
  40. return done();
  41. });
  42. });
  43. it("should delete text correctly", function(done) {
  44. this.before = ["hello beautiful world"];
  45. this.after = ["hello world"];
  46. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, function(error, ops) {
  47. expect(ops).to.deep.equal([{
  48. d: "beautiful ",
  49. p: 6
  50. }
  51. ]);
  52. return done();
  53. });
  54. });
  55. return it("should shift later deletes by the first deletes", function(done) {
  56. this.before = ["the tall boy played with the red ball"];
  57. this.after = ["the boy played with the ball"];
  58. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, function(error, ops) {
  59. expect(ops).to.deep.equal([
  60. { d: "tall ", p: 4 },
  61. { d: "red ", p: 24 }
  62. ]);
  63. return done();
  64. });
  65. });
  66. });
  67. });