DocLinesComparitorTests.coffee 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/Features/Project/DocLinesComparitor.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe 'doc lines comparitor', ->
  7. beforeEach ->
  8. @comparitor = SandboxedModule.require modulePath, requires:
  9. 'logger-sharelatex':{log:->}
  10. it 'should return true when the lines are the same', ->
  11. lines1 = ["hello", "world"]
  12. lines2 = ["hello", "world"]
  13. result = @comparitor.areSame lines1, lines2
  14. result.should.equal true
  15. it 'should return false when the lines are different', ->
  16. lines1 = ["hello", "world"]
  17. lines2 = ["diff", "world"]
  18. result = @comparitor.areSame lines1, lines2
  19. result.should.equal false
  20. it 'should return false when the lines are different', ->
  21. lines1 = ["hello", "world"]
  22. lines2 = ["hello", "wrld"]
  23. result = @comparitor.areSame lines1, lines2
  24. result.should.equal false
  25. it 'should return true when the lines are same', ->
  26. lines1 = ["hello", "world"]
  27. lines2 = ['hello', "world"]
  28. result = @comparitor.areSame lines1, lines2
  29. result.should.equal true
  30. it 'should return false if the doc lines are different in length', ->
  31. lines1 = ["hello", "world"]
  32. lines2 = ['hello', "world", "please"]
  33. result = @comparitor.areSame lines1, lines2
  34. result.should.equal false
  35. it 'should return false if the first array is undefined', ->
  36. lines1 = undefined
  37. lines2 = ['hello', "world"]
  38. result = @comparitor.areSame lines1, lines2
  39. result.should.equal false
  40. it 'should return false if the second array is undefined', ->
  41. lines1 = ["hello"]
  42. lines2 = undefined
  43. result = @comparitor.areSame lines1, lines2
  44. result.should.equal false
  45. it 'should return false if the second array is not an array', ->
  46. lines1 = ["hello"]
  47. lines2 = ""
  48. result = @comparitor.areSame lines1, lines2
  49. result.should.equal false
  50. it "should return true when comparing equal orchard docs", ->
  51. lines1 = [{ text: "hello world" }]
  52. lines2 = [{ text: "hello world" }]
  53. result = @comparitor.areSame lines1, lines2
  54. result.should.equal true
  55. it "should return false when comparing different orchard docs", ->
  56. lines1 = [{ text: "goodbye world" }]
  57. lines2 = [{ text: "hello world" }]
  58. result = @comparitor.areSame lines1, lines2
  59. result.should.equal false