DocLinesComparitor.test.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const modulePath = '../../../../app/src/Features/Project/DocLinesComparitor.mjs'
  2. describe('doc lines comparitor', function () {
  3. beforeEach(async function (ctx) {
  4. ctx.comparitor = (await import(modulePath)).default
  5. })
  6. it('should return true when the lines are the same', function (ctx) {
  7. const lines1 = ['hello', 'world']
  8. const lines2 = ['hello', 'world']
  9. const result = ctx.comparitor.areSame(lines1, lines2)
  10. result.should.equal(true)
  11. })
  12. ;[
  13. {
  14. lines1: ['hello', 'world'],
  15. lines2: ['diff', 'world'],
  16. },
  17. {
  18. lines1: ['hello', 'world'],
  19. lines2: ['hello', 'wrld'],
  20. },
  21. ].forEach(({ lines1, lines2 }) => {
  22. it('should return false when the lines are different', function (ctx) {
  23. const result = ctx.comparitor.areSame(lines1, lines2)
  24. result.should.equal(false)
  25. })
  26. })
  27. it('should return true when the lines are same', function (ctx) {
  28. const lines1 = ['hello', 'world']
  29. const lines2 = ['hello', 'world']
  30. const result = ctx.comparitor.areSame(lines1, lines2)
  31. result.should.equal(true)
  32. })
  33. it('should return false if the doc lines are different in length', function (ctx) {
  34. const lines1 = ['hello', 'world']
  35. const lines2 = ['hello', 'world', 'please']
  36. const result = ctx.comparitor.areSame(lines1, lines2)
  37. result.should.equal(false)
  38. })
  39. it('should return false if the first array is undefined', function (ctx) {
  40. const lines1 = undefined
  41. const lines2 = ['hello', 'world']
  42. const result = ctx.comparitor.areSame(lines1, lines2)
  43. result.should.equal(false)
  44. })
  45. it('should return false if the second array is undefined', function (ctx) {
  46. const lines1 = ['hello']
  47. const lines2 = undefined
  48. const result = ctx.comparitor.areSame(lines1, lines2)
  49. result.should.equal(false)
  50. })
  51. it('should return false if the second array is not an array', function (ctx) {
  52. const lines1 = ['hello']
  53. const lines2 = ''
  54. const result = ctx.comparitor.areSame(lines1, lines2)
  55. result.should.equal(false)
  56. })
  57. it('should return true when comparing equal orchard docs', function (ctx) {
  58. const lines1 = [{ text: 'hello world' }]
  59. const lines2 = [{ text: 'hello world' }]
  60. const result = ctx.comparitor.areSame(lines1, lines2)
  61. result.should.equal(true)
  62. })
  63. it('should return false when comparing different orchard docs', function (ctx) {
  64. const lines1 = [{ text: 'goodbye world' }]
  65. const lines2 = [{ text: 'hello world' }]
  66. const result = ctx.comparitor.areSame(lines1, lines2)
  67. result.should.equal(false)
  68. })
  69. })