DraftModeManagerTests.js 2.2 KB

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