DraftModeManagerTests.js 2.2 KB

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