sandboxed-compiles.spec.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { throttledRecompile } from './helpers/compile'
  5. import { v4 as uuid } from 'uuid'
  6. import { waitUntilScrollingFinished } from './helpers/waitUntilScrollingFinished'
  7. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  8. const LABEL_TEX_LIVE_VERSION = 'TeX Live version'
  9. describe('SandboxedCompiles', function () {
  10. const enabledVars = {
  11. SANDBOXED_COMPILES: 'true',
  12. ALL_TEX_LIVE_DOCKER_IMAGE_NAMES: '2023,2022',
  13. }
  14. describe('enabled in Server Pro', function () {
  15. if (isExcludedBySharding('PRO_CUSTOM_2')) return
  16. startWith({
  17. pro: true,
  18. vars: enabledVars,
  19. resetData: true,
  20. })
  21. ensureUserExists({ email: 'user@example.com' })
  22. beforeEach(function () {
  23. login('user@example.com')
  24. })
  25. it('should offer TexLive images and switch the compiler', function () {
  26. createProject('sandboxed')
  27. const recompile = throttledRecompile()
  28. cy.log('wait for compile')
  29. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  30. cy.log('Check which compiler version was used, expect 2023')
  31. cy.get('[aria-label="View logs"]').click()
  32. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2023\) /)
  33. cy.log('Switch TeXLive version from 2023 to 2022')
  34. cy.get('header').findByText('Menu').click()
  35. cy.findByText(LABEL_TEX_LIVE_VERSION)
  36. .parent()
  37. .findByText('2023')
  38. .parent()
  39. .select('2022')
  40. cy.get('.left-menu-modal-backdrop').click()
  41. cy.log('Trigger compile with other TeX Live version')
  42. recompile()
  43. cy.log('Check which compiler version was used, expect 2022')
  44. cy.get('[aria-label="View logs"]').click()
  45. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2022\) /)
  46. })
  47. checkSyncTeX()
  48. checkXeTeX()
  49. checkRecompilesAfterErrors()
  50. })
  51. function checkSyncTeX() {
  52. describe('SyncTeX', function () {
  53. let projectName: string
  54. beforeEach(function () {
  55. projectName = `Project ${uuid()}`
  56. createProject(projectName)
  57. const recompile = throttledRecompile()
  58. cy.findByText('\\maketitle').parent().click()
  59. cy.findByText('\\maketitle')
  60. .parent()
  61. .type(
  62. `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
  63. )
  64. recompile()
  65. cy.log('wait for pdf-rendering')
  66. cy.get('.pdf-viewer').within(() => {
  67. cy.findByText(projectName)
  68. })
  69. })
  70. it('should sync to code', function () {
  71. cy.log('navigate to \\maketitle using double click in PDF')
  72. cy.get('.pdf-viewer').within(() => {
  73. cy.findByText(projectName).dblclick()
  74. })
  75. cy.get('.cm-activeLine').should('have.text', '\\maketitle')
  76. cy.log('navigate to Section A using double click in PDF')
  77. cy.get('.pdf-viewer').within(() => {
  78. cy.findByText('Section A').dblclick()
  79. })
  80. cy.get('.cm-activeLine').should('have.text', '\\section{Section A}')
  81. cy.log('navigate to Section B using arrow button')
  82. cy.get('.pdfjs-viewer-inner')
  83. .should('have.prop', 'scrollTop')
  84. .as('start')
  85. cy.get('.pdf-viewer').within(() => {
  86. cy.findByText('Section B').scrollIntoView()
  87. })
  88. cy.get('@start').then((start: any) => {
  89. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  90. })
  91. // The sync button is swapped as the position in the PDF changes.
  92. // Cypress appears to click on a button that references a stale position.
  93. // Adding a cy.wait() statement is the most reliable "fix" so far :/
  94. cy.wait(1000)
  95. cy.get('[aria-label^="Go to PDF location in code"]').click()
  96. cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
  97. })
  98. it('should sync to pdf', function () {
  99. cy.log('zoom in')
  100. cy.findByText('45%').click()
  101. cy.findByText('400%').click()
  102. cy.log('scroll to top')
  103. cy.get('.pdfjs-viewer-inner').scrollTo('top')
  104. waitUntilScrollingFinished('.pdfjs-viewer-inner', -1).as('start')
  105. cy.log('navigate to title')
  106. cy.findByText('\\maketitle').parent().click()
  107. cy.get('[aria-label="Go to code location in PDF"]').click()
  108. cy.get('@start').then((start: any) => {
  109. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  110. .as('title')
  111. .should('be.greaterThan', start)
  112. })
  113. cy.log('navigate to Section A')
  114. cy.get('.cm-content').within(() => cy.findByText('Section A').click())
  115. cy.get('[aria-label="Go to code location in PDF"]').click()
  116. cy.get('@title').then((title: any) => {
  117. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  118. .as('sectionA')
  119. .should('be.greaterThan', title)
  120. })
  121. cy.log('navigate to Section B')
  122. cy.get('.cm-content').within(() => cy.findByText('Section B').click())
  123. cy.get('[aria-label="Go to code location in PDF"]').click()
  124. cy.get('@sectionA').then((title: any) => {
  125. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  126. .as('sectionB')
  127. .should('be.greaterThan', title)
  128. })
  129. })
  130. })
  131. }
  132. function checkRecompilesAfterErrors() {
  133. it('recompiles even if there are Latex errors', function () {
  134. login('user@example.com')
  135. createProject('test-project')
  136. const recompile = throttledRecompile()
  137. cy.findByText('\\maketitle').parent().click()
  138. cy.findByText('\\maketitle')
  139. .parent()
  140. .type('\n\\fakeCommand{} \n\\section{{}Test Section}')
  141. recompile()
  142. recompile()
  143. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  144. cy.get('.logs-pane').should('not.contain.text', 'No PDF')
  145. })
  146. }
  147. function checkXeTeX() {
  148. it('should be able to use XeLaTeX', function () {
  149. createProject('XeLaTeX')
  150. const recompile = throttledRecompile()
  151. cy.log('wait for compile')
  152. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  153. cy.log('Check which compiler was used, expect pdfLaTeX')
  154. cy.get('[aria-label="View logs"]').click()
  155. cy.findByText(/This is pdfTeX/)
  156. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  157. cy.get('header').findByText('Menu').click()
  158. cy.findByText('Compiler')
  159. .parent()
  160. .findByText('pdfLaTeX')
  161. .parent()
  162. .select('XeLaTeX')
  163. cy.get('.left-menu-modal-backdrop').click()
  164. cy.log('Trigger compile with other compiler')
  165. recompile()
  166. cy.log('Check which compiler was used, expect XeLaTeX')
  167. cy.get('[aria-label="View logs"]').click()
  168. cy.findByText(/This is XeTeX/)
  169. })
  170. }
  171. function checkUsesDefaultCompiler() {
  172. beforeEach(function () {
  173. login('user@example.com')
  174. })
  175. it('should not offer TexLive images and use default compiler', function () {
  176. createProject('sandboxed')
  177. cy.log('wait for compile')
  178. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  179. cy.log('Check which compiler version was used, expect 2025')
  180. cy.get('[aria-label="View logs"]').click()
  181. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2025\) /)
  182. cy.log('Check that there is no TeX Live version toggle')
  183. cy.get('header').findByText('Menu').click()
  184. cy.findByText('Word Count') // wait for lazy loading
  185. cy.findByText(LABEL_TEX_LIVE_VERSION).should('not.exist')
  186. })
  187. }
  188. describe('disabled in Server Pro', function () {
  189. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  190. startWith({ pro: true })
  191. ensureUserExists({ email: 'user@example.com' })
  192. beforeEach(function () {
  193. login('user@example.com')
  194. })
  195. checkUsesDefaultCompiler()
  196. checkSyncTeX()
  197. checkXeTeX()
  198. checkRecompilesAfterErrors()
  199. })
  200. describe.skip('unavailable in CE', function () {
  201. if (isExcludedBySharding('CE_CUSTOM_1')) return
  202. startWith({ pro: false, vars: enabledVars, resetData: true })
  203. ensureUserExists({ email: 'user@example.com' })
  204. beforeEach(function () {
  205. login('user@example.com')
  206. })
  207. checkUsesDefaultCompiler()
  208. checkSyncTeX()
  209. checkXeTeX()
  210. checkRecompilesAfterErrors()
  211. })
  212. })