2014-02-12 05:23:40 -05:00
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
sinon = require("sinon")
|
|
|
|
modulePath = "../../../../app/js/Features/Project/ProjectRootDocManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe 'ProjectRootDocManager', ->
|
|
|
|
beforeEach ->
|
|
|
|
@project_id = "project-123"
|
|
|
|
@sl_req_id = "sl-req-id-123"
|
2014-10-15 09:11:02 -04:00
|
|
|
@callback = sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@ProjectRootDocManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"./ProjectEntityHandler" : @ProjectEntityHandler = {}
|
|
|
|
|
|
|
|
describe "setRootDocAutomatically", ->
|
|
|
|
describe "when there is a suitable root doc", ->
|
2014-11-26 12:19:21 -05:00
|
|
|
beforeEach (done)->
|
2014-02-12 05:23:40 -05:00
|
|
|
@docs =
|
|
|
|
"/chapter1.tex":
|
|
|
|
_id: "doc-id-1"
|
2014-11-30 20:07:03 -05:00
|
|
|
lines: ["something else","\\begin{document}", "Hello world", "\\end{document}"]
|
2014-02-12 05:23:40 -05:00
|
|
|
"/main.tex":
|
|
|
|
_id: "doc-id-2"
|
2014-11-30 20:07:03 -05:00
|
|
|
lines: ["different line","\\documentclass{article}", "\\input{chapter1}"]
|
2014-11-26 12:19:21 -05:00
|
|
|
"/nested/chapter1a.tex":
|
|
|
|
_id: "doc-id-3"
|
|
|
|
lines: ["Hello world"]
|
|
|
|
"/nested/chapter1b.tex":
|
|
|
|
_id: "doc-id-4"
|
|
|
|
lines: ["Hello world"]
|
|
|
|
|
2014-10-15 09:11:02 -04:00
|
|
|
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
|
|
|
@ProjectEntityHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
2014-11-26 12:19:21 -05:00
|
|
|
@ProjectRootDocManager.setRootDocAutomatically @project_id, done
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it "should check the docs of the project", ->
|
|
|
|
@ProjectEntityHandler.getAllDocs.calledWith(@project_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should set the root doc to the doc containing a documentclass", ->
|
|
|
|
@ProjectEntityHandler.setRootDoc.calledWith(@project_id, "doc-id-2")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when the root doc is an Rtex file", ->
|
|
|
|
beforeEach ->
|
|
|
|
@docs =
|
|
|
|
"/chapter1.tex":
|
|
|
|
_id: "doc-id-1"
|
|
|
|
lines: ["\\begin{document}", "Hello world", "\\end{document}"]
|
|
|
|
"/main.Rtex":
|
|
|
|
_id: "doc-id-2"
|
|
|
|
lines: ["\\documentclass{article}", "\\input{chapter1}"]
|
2014-10-15 09:11:02 -04:00
|
|
|
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
|
|
|
@ProjectEntityHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
|
@ProjectRootDocManager.setRootDocAutomatically @project_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it "should set the root doc to the doc containing a documentclass", ->
|
|
|
|
@ProjectEntityHandler.setRootDoc.calledWith(@project_id, "doc-id-2")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when there is no suitable root doc", ->
|
2014-11-26 12:19:21 -05:00
|
|
|
beforeEach (done)->
|
2014-02-12 05:23:40 -05:00
|
|
|
@docs =
|
|
|
|
"/chapter1.tex":
|
|
|
|
_id: "doc-id-1"
|
|
|
|
lines: ["\\begin{document}", "Hello world", "\\end{document}"]
|
|
|
|
"/style.bst":
|
|
|
|
_id: "doc-id-2"
|
|
|
|
lines: ["%Example: \\documentclass{article}"]
|
2014-10-15 09:11:02 -04:00
|
|
|
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
|
|
|
@ProjectEntityHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
2014-11-26 12:19:21 -05:00
|
|
|
@ProjectRootDocManager.setRootDocAutomatically @project_id, done
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it "should not set the root doc to the doc containing a documentclass", ->
|
|
|
|
@ProjectEntityHandler.setRootDoc.called.should.equal false
|
|
|
|
|