DraftModeManagerTests.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(
  15. __dirname,
  16. '../../../app/js/DraftModeManager'
  17. )
  18. describe('DraftModeManager', function () {
  19. beforeEach(function () {
  20. return (this.DraftModeManager = SandboxedModule.require(modulePath, {
  21. requires: {
  22. fs: (this.fs = {}),
  23. 'logger-sharelatex': (this.logger = { log() {} })
  24. }
  25. }))
  26. })
  27. describe('_injectDraftOption', function () {
  28. it('should add draft option into documentclass with existing options', function () {
  29. return this.DraftModeManager._injectDraftOption(`\
  30. \\documentclass[a4paper,foo=bar]{article}\
  31. `).should.equal(`\
  32. \\documentclass[draft,a4paper,foo=bar]{article}\
  33. `)
  34. })
  35. return it('should add draft option into documentclass with no options', function () {
  36. return this.DraftModeManager._injectDraftOption(`\
  37. \\documentclass{article}\
  38. `).should.equal(`\
  39. \\documentclass[draft]{article}\
  40. `)
  41. })
  42. })
  43. return describe('injectDraftMode', function () {
  44. beforeEach(function () {
  45. this.filename = '/mock/filename.tex'
  46. this.callback = sinon.stub()
  47. const content = `\
  48. \\documentclass{article}
  49. \\begin{document}
  50. Hello world
  51. \\end{document}\
  52. `
  53. this.fs.readFile = sinon.stub().callsArgWith(2, null, content)
  54. this.fs.writeFile = sinon.stub().callsArg(2)
  55. return this.DraftModeManager.injectDraftMode(this.filename, this.callback)
  56. })
  57. it('should read the file', function () {
  58. return this.fs.readFile
  59. .calledWith(this.filename, 'utf8')
  60. .should.equal(true)
  61. })
  62. it('should write the modified file', function () {
  63. return this.fs.writeFile
  64. .calledWith(
  65. this.filename,
  66. `\
  67. \\documentclass[draft]{article}
  68. \\begin{document}
  69. Hello world
  70. \\end{document}\
  71. `
  72. )
  73. .should.equal(true)
  74. })
  75. return it('should call the callback', function () {
  76. return this.callback.called.should.equal(true)
  77. })
  78. })
  79. })