UtilsTests.js 1.0 KB

123456789101112131415161718192021222324252627
  1. // @ts-check
  2. const { expect } = require('chai')
  3. const Utils = require('../../../app/js/Utils')
  4. describe('Utils', function () {
  5. describe('addTrackedDeletesToContent', function () {
  6. it("doesn't modify text without tracked deletes", function () {
  7. const content = 'the quick brown fox'
  8. const trackedChanges = []
  9. const result = Utils.addTrackedDeletesToContent(content, trackedChanges)
  10. expect(result).to.equal(content)
  11. })
  12. it('adds tracked deletes to text but skips tracked inserts', function () {
  13. const content = 'the brown fox jumps over the dog'
  14. const metadata = { user_id: 'user1', ts: new Date().toString() }
  15. const trackedChanges = [
  16. { id: 'tc1', op: { d: 'quick ', p: 4 }, metadata },
  17. { id: 'tc2', op: { i: 'brown ', p: 5 }, metadata },
  18. { id: 'tc3', op: { d: 'lazy ', p: 29 }, metadata },
  19. ]
  20. const result = Utils.addTrackedDeletesToContent(content, trackedChanges)
  21. expect(result).to.equal('the quick brown fox jumps over the lazy dog')
  22. })
  23. })
  24. })