DocLinesComparitorTests.mjs 2.5 KB

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