ProjectRootDocManagerTests.coffee 2.8 KB

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