DraftModeManagerTests.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  5. */
  6. const SandboxedModule = require('sandboxed-module');
  7. const sinon = require('sinon');
  8. require('chai').should();
  9. const modulePath = require('path').join(__dirname, '../../../app/js/DraftModeManager');
  10. describe('DraftModeManager', function() {
  11. beforeEach(function() {
  12. return this.DraftModeManager = SandboxedModule.require(modulePath, { requires: {
  13. "fs": (this.fs = {}),
  14. "logger-sharelatex": (this.logger = {log() {}})
  15. }
  16. });});
  17. describe("_injectDraftOption", function() {
  18. it("should add draft option into documentclass with existing options", function() {
  19. return this.DraftModeManager
  20. ._injectDraftOption(`\
  21. \\documentclass[a4paper,foo=bar]{article}\
  22. `)
  23. .should.equal(`\
  24. \\documentclass[draft,a4paper,foo=bar]{article}\
  25. `);
  26. });
  27. return it("should add draft option into documentclass with no options", function() {
  28. return this.DraftModeManager
  29. ._injectDraftOption(`\
  30. \\documentclass{article}\
  31. `)
  32. .should.equal(`\
  33. \\documentclass[draft]{article}\
  34. `);
  35. });
  36. });
  37. return describe("injectDraftMode", function() {
  38. beforeEach(function() {
  39. this.filename = "/mock/filename.tex";
  40. this.callback = sinon.stub();
  41. const content = `\
  42. \\documentclass{article}
  43. \\begin{document}
  44. Hello world
  45. \\end{document}\
  46. `;
  47. this.fs.readFile = sinon.stub().callsArgWith(2, null, content);
  48. this.fs.writeFile = sinon.stub().callsArg(2);
  49. return this.DraftModeManager.injectDraftMode(this.filename, this.callback);
  50. });
  51. it("should read the file", function() {
  52. return this.fs.readFile
  53. .calledWith(this.filename, "utf8")
  54. .should.equal(true);
  55. });
  56. it("should write the modified file", function() {
  57. return this.fs.writeFile
  58. .calledWith(this.filename, `\
  59. \\documentclass[draft]{article}
  60. \\begin{document}
  61. Hello world
  62. \\end{document}\
  63. `)
  64. .should.equal(true);
  65. });
  66. return it("should call the callback", function() {
  67. return this.callback.called.should.equal(true);
  68. });
  69. });
  70. });