ProjectRootDocManagerTests.coffee 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. chai = require('chai')
  2. should = chai.should()
  3. sinon = require("sinon")
  4. modulePath = "../../../../app/js/Features/Project/ProjectRootDocManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe 'ProjectRootDocManager', ->
  7. beforeEach ->
  8. @project_id = "project-123"
  9. @sl_req_id = "sl-req-id-123"
  10. @callback = sinon.stub()
  11. @ProjectRootDocManager = SandboxedModule.require modulePath, requires:
  12. "./ProjectEntityHandler" : @ProjectEntityHandler = {}
  13. "./ProjectEntityUpdateHandler" : @ProjectEntityUpdateHandler = {}
  14. describe "setRootDocAutomatically", ->
  15. describe "when there is a suitable root doc", ->
  16. beforeEach (done)->
  17. @docs =
  18. "/chapter1.tex":
  19. _id: "doc-id-1"
  20. lines: ["something else","\\begin{document}", "Hello world", "\\end{document}"]
  21. "/main.tex":
  22. _id: "doc-id-2"
  23. lines: ["different line","\\documentclass{article}", "\\input{chapter1}"]
  24. "/nested/chapter1a.tex":
  25. _id: "doc-id-3"
  26. lines: ["Hello world"]
  27. "/nested/chapter1b.tex":
  28. _id: "doc-id-4"
  29. lines: ["Hello world"]
  30. @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
  31. @ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
  32. @ProjectRootDocManager.setRootDocAutomatically @project_id, done
  33. it "should check the docs of the project", ->
  34. @ProjectEntityHandler.getAllDocs.calledWith(@project_id)
  35. .should.equal true
  36. it "should set the root doc to the doc containing a documentclass", ->
  37. @ProjectEntityUpdateHandler.setRootDoc.calledWith(@project_id, "doc-id-2")
  38. .should.equal true
  39. describe "when the root doc is an Rtex file", ->
  40. beforeEach ->
  41. @docs =
  42. "/chapter1.tex":
  43. _id: "doc-id-1"
  44. lines: ["\\begin{document}", "Hello world", "\\end{document}"]
  45. "/main.Rtex":
  46. _id: "doc-id-2"
  47. lines: ["\\documentclass{article}", "\\input{chapter1}"]
  48. @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
  49. @ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
  50. @ProjectRootDocManager.setRootDocAutomatically @project_id, @callback
  51. it "should set the root doc to the doc containing a documentclass", ->
  52. @ProjectEntityUpdateHandler.setRootDoc.calledWith(@project_id, "doc-id-2")
  53. .should.equal true
  54. describe "when there is no suitable root doc", ->
  55. beforeEach (done)->
  56. @docs =
  57. "/chapter1.tex":
  58. _id: "doc-id-1"
  59. lines: ["\\begin{document}", "Hello world", "\\end{document}"]
  60. "/style.bst":
  61. _id: "doc-id-2"
  62. lines: ["%Example: \\documentclass{article}"]
  63. @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
  64. @ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
  65. @ProjectRootDocManager.setRootDocAutomatically @project_id, done
  66. it "should not set the root doc to the doc containing a documentclass", ->
  67. @ProjectEntityUpdateHandler.setRootDoc.called.should.equal false