2020-02-19 06:15:25 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 06:15:08 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SandboxedModule = require('sandboxed-module');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
require('chai').should();
|
|
|
|
const modulePath = require('path').join(__dirname, '../../../app/js/DraftModeManager');
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
describe('DraftModeManager', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return this.DraftModeManager = SandboxedModule.require(modulePath, { requires: {
|
|
|
|
"fs": (this.fs = {}),
|
|
|
|
"logger-sharelatex": (this.logger = {log() {}})
|
|
|
|
}
|
|
|
|
});});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
describe("_injectDraftOption", function() {
|
|
|
|
it("should add draft option into documentclass with existing options", function() {
|
|
|
|
return this.DraftModeManager
|
|
|
|
._injectDraftOption(`\
|
|
|
|
\\documentclass[a4paper,foo=bar]{article}\
|
|
|
|
`)
|
|
|
|
.should.equal(`\
|
|
|
|
\\documentclass[draft,a4paper,foo=bar]{article}\
|
|
|
|
`);
|
|
|
|
});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
return it("should add draft option into documentclass with no options", function() {
|
|
|
|
return this.DraftModeManager
|
|
|
|
._injectDraftOption(`\
|
|
|
|
\\documentclass{article}\
|
|
|
|
`)
|
|
|
|
.should.equal(`\
|
|
|
|
\\documentclass[draft]{article}\
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
return describe("injectDraftMode", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.filename = "/mock/filename.tex";
|
|
|
|
this.callback = sinon.stub();
|
|
|
|
const content = `\
|
|
|
|
\\documentclass{article}
|
|
|
|
\\begin{document}
|
|
|
|
Hello world
|
|
|
|
\\end{document}\
|
|
|
|
`;
|
|
|
|
this.fs.readFile = sinon.stub().callsArgWith(2, null, content);
|
|
|
|
this.fs.writeFile = sinon.stub().callsArg(2);
|
|
|
|
return this.DraftModeManager.injectDraftMode(this.filename, this.callback);
|
|
|
|
});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
it("should read the file", function() {
|
|
|
|
return this.fs.readFile
|
|
|
|
.calledWith(this.filename, "utf8")
|
|
|
|
.should.equal(true);
|
|
|
|
});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
it("should write the modified file", function() {
|
|
|
|
return this.fs.writeFile
|
|
|
|
.calledWith(this.filename, `\
|
|
|
|
\\documentclass[draft]{article}
|
|
|
|
\\begin{document}
|
|
|
|
Hello world
|
|
|
|
\\end{document}\
|
|
|
|
`)
|
|
|
|
.should.equal(true);
|
|
|
|
});
|
2016-02-02 09:26:14 -05:00
|
|
|
|
2020-02-19 06:15:08 -05:00
|
|
|
return it("should call the callback", function() {
|
|
|
|
return this.callback.called.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|