SynctexTests.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const Client = require('./helpers/Client')
  2. const { expect } = require('chai')
  3. const ClsiApp = require('./helpers/ClsiApp')
  4. describe('Syncing', function () {
  5. before(async function () {
  6. const content = `\
  7. \\documentclass{article}
  8. \\begin{document}
  9. Hello world
  10. \\end{document}\
  11. `
  12. this.request = {
  13. resources: [
  14. {
  15. path: 'main.tex',
  16. content,
  17. },
  18. ],
  19. }
  20. this.project_id = Client.randomId()
  21. await ClsiApp.ensureRunning()
  22. this.body = await Client.compile(this.project_id, this.request)
  23. })
  24. describe('from code to pdf', function () {
  25. it('should return the correct location', async function () {
  26. const pdfPositions = await Client.syncFromCode(
  27. this.project_id,
  28. 'main.tex',
  29. 3,
  30. 5
  31. )
  32. expect(pdfPositions).to.deep.equal({
  33. pdf: [
  34. {
  35. page: 1,
  36. h: 133.768356,
  37. v: 134.764618,
  38. height: 6.918498,
  39. width: 343.71106,
  40. },
  41. ],
  42. downloadedFromCache: false,
  43. })
  44. })
  45. })
  46. describe('from pdf to code', function () {
  47. it('should return the correct location', async function () {
  48. const codePositions = await Client.syncFromPdf(
  49. this.project_id,
  50. 1,
  51. 100,
  52. 200
  53. )
  54. expect(codePositions).to.deep.equal({
  55. code: [{ file: 'main.tex', line: 3, column: -1 }],
  56. downloadedFromCache: false,
  57. })
  58. })
  59. })
  60. describe('when the project directory is not available', function () {
  61. before(function () {
  62. this.other_project_id = Client.randomId()
  63. })
  64. describe('from code to pdf', function () {
  65. it('should return a 404 response', async function () {
  66. const rejects = () =>
  67. expect(Client.syncFromCode(this.other_project_id, 'main.tex', 3, 5))
  68. .to.eventually.be.rejected
  69. await rejects().and.have.property('info').to.contain({ status: 404 })
  70. await rejects().and.have.property('body', 'Not Found')
  71. })
  72. })
  73. describe('from pdf to code', function () {
  74. it('should return a 404 response', async function () {
  75. const rejects = () =>
  76. expect(Client.syncFromPdf(this.other_project_id, 1, 100, 200)).to
  77. .eventually.be.rejected
  78. await rejects().and.have.property('info').to.contain({ status: 404 })
  79. await rejects().and.have.property('body', 'Not Found')
  80. })
  81. })
  82. })
  83. describe('when the synctex file is not available', function () {
  84. before(async function () {
  85. this.broken_project_id = Client.randomId()
  86. const content = 'this is not valid tex' // not a valid tex file
  87. this.request = {
  88. resources: [
  89. {
  90. path: 'main.tex',
  91. content,
  92. },
  93. ],
  94. }
  95. this.body = await Client.compile(this.broken_project_id, this.request)
  96. })
  97. describe('from code to pdf', function () {
  98. it('should return a 404 response', async function () {
  99. const rejects = () =>
  100. expect(Client.syncFromCode(this.broken_project_id, 'main.tex', 3, 5))
  101. .to.eventually.be.rejected
  102. await rejects().and.have.property('info').to.contain({ status: 404 })
  103. await rejects().and.have.property('body', 'Not Found')
  104. })
  105. })
  106. describe('from pdf to code', function () {
  107. it('should return a 404 response', async function () {
  108. const rejects = () =>
  109. expect(Client.syncFromPdf(this.broken_project_id, 1, 100, 200)).to
  110. .eventually.be.rejected
  111. await rejects().and.have.property('info').to.contain({ status: 404 })
  112. await rejects().and.have.property('body', 'Not Found')
  113. })
  114. })
  115. })
  116. })