sandboxed-compiles.spec.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { startWith } from './helpers/config'
  4. import { throttledRecompile } from './helpers/compile'
  5. import { v4 as uuid } from 'uuid'
  6. import { waitUntilScrollingFinished } from './helpers/waitUntilScrollingFinished'
  7. describe('SandboxedCompiles', function () {
  8. ensureUserExists({ email: 'user@example.com' })
  9. const enabledVars = {
  10. DOCKER_RUNNER: 'true',
  11. SANDBOXED_COMPILES: 'true',
  12. SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true',
  13. ALL_TEX_LIVE_DOCKER_IMAGE_NAMES: '2023,2022',
  14. }
  15. describe('enabled in Server Pro', () => {
  16. startWith({
  17. pro: true,
  18. vars: enabledVars,
  19. })
  20. beforeEach(function () {
  21. login('user@example.com')
  22. })
  23. it('should offer TexLive images and switch the compiler', () => {
  24. cy.visit('/project')
  25. createProject('sandboxed')
  26. const recompile = throttledRecompile()
  27. // check produced PDF
  28. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  29. cy.get('[aria-label="View logs"]').click()
  30. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2023\) /)
  31. cy.get('header').findByText('Menu').click()
  32. cy.findByText('TeX Live version')
  33. .parent()
  34. .findByText('2023')
  35. .parent()
  36. .select('2022')
  37. // close editor menu
  38. cy.get('#left-menu-modal').click()
  39. // Trigger compile with other TexLive version
  40. recompile()
  41. cy.get('[aria-label="View logs"]').click()
  42. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2022\) /)
  43. })
  44. checkSyncTeX()
  45. checkXeTeX()
  46. })
  47. function checkSyncTeX() {
  48. describe('SyncTeX', () => {
  49. const projectName = `Project ${uuid()}`
  50. before(function () {
  51. login('user@example.com')
  52. cy.visit('/project')
  53. createProject(projectName)
  54. const recompile = throttledRecompile()
  55. cy.findByText('\\maketitle').parent().click()
  56. cy.findByText('\\maketitle')
  57. .parent()
  58. .type(
  59. `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
  60. )
  61. recompile()
  62. })
  63. it('should sync to code', () => {
  64. cy.visit('/project')
  65. cy.findByText(projectName).click()
  66. cy.log('navigate to \\maketitle using double click in PDF')
  67. cy.get('.pdf-viewer').within(() => {
  68. cy.findByText(projectName).dblclick()
  69. })
  70. cy.get('.cm-activeLine').should('have.text', '\\maketitle')
  71. cy.log('navigate to Section A using double click in PDF')
  72. cy.get('.pdf-viewer').within(() => {
  73. cy.findByText('Section A').dblclick()
  74. })
  75. cy.get('.cm-activeLine').should('have.text', '\\section{Section A}')
  76. cy.log('navigate to Section B using arrow button')
  77. cy.get('.pdfjs-viewer-inner')
  78. .should('have.prop', 'scrollTop')
  79. .as('start')
  80. cy.get('.pdf-viewer').within(() => {
  81. cy.findByText('Section B').scrollIntoView()
  82. })
  83. cy.get('@start').then((start: any) => {
  84. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  85. })
  86. cy.get('[aria-label^="Go to PDF location in code"]').click()
  87. cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
  88. })
  89. // Waiting for a fix of https://github.com/overleaf/internal/issues/18603
  90. it.skip('should sync to pdf', () => {
  91. cy.visit('/project')
  92. cy.findByText(projectName).click()
  93. cy.log('wait for compile')
  94. cy.get('.pdf-viewer').within(() => {
  95. cy.findByText(projectName)
  96. })
  97. cy.log('zoom in')
  98. for (let i = 0; i < 8; i++) {
  99. cy.get('[aria-label="Zoom in"]').click({ force: true })
  100. }
  101. cy.log('scroll to top')
  102. cy.get('.pdfjs-viewer-inner').scrollTo('top')
  103. waitUntilScrollingFinished('.pdfjs-viewer-inner', -1)
  104. cy.get('.pdfjs-viewer-inner')
  105. .should('have.prop', 'scrollTop')
  106. .as('start')
  107. cy.log('navigate to title')
  108. cy.findByText('\\maketitle').parent().click()
  109. cy.get('[aria-label="Go to code location in PDF"]').click()
  110. cy.get('@start').then((start: any) => {
  111. waitUntilScrollingFinished('.pdfjs-viewer-inner', start)
  112. .as('title')
  113. .should('be.greaterThan', start)
  114. })
  115. cy.log('navigate to Section A')
  116. cy.get('.cm-content').within(() => cy.findByText('Section A').click())
  117. cy.get('[aria-label="Go to code location in PDF"]').click()
  118. cy.get('@title').then((title: any) => {
  119. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  120. .as('sectionA')
  121. .should('be.greaterThan', title)
  122. })
  123. cy.log('navigate to Section B')
  124. cy.get('.cm-content').within(() => cy.findByText('Section B').click())
  125. cy.get('[aria-label="Go to code location in PDF"]').click()
  126. cy.get('@sectionA').then((title: any) => {
  127. waitUntilScrollingFinished('.pdfjs-viewer-inner', title)
  128. .as('sectionB')
  129. .should('be.greaterThan', title)
  130. })
  131. })
  132. })
  133. }
  134. function checkXeTeX() {
  135. it('should be able to use XeLaTeX', () => {
  136. cy.visit('/project')
  137. createProject('XeLaTeX')
  138. const recompile = throttledRecompile()
  139. cy.log('wait for compile')
  140. cy.get('.pdf-viewer').should('contain.text', 'XeLaTeX')
  141. cy.log('Check which compiler was used, expect pdfLaTeX')
  142. cy.get('[aria-label="View logs"]').click()
  143. cy.findByText(/This is pdfTeX/)
  144. cy.log('Switch compiler to from pdfLaTeX to XeLaTeX')
  145. cy.get('header').findByText('Menu').click()
  146. cy.findByText('Compiler')
  147. .parent()
  148. .findByText('pdfLaTeX')
  149. .parent()
  150. .select('XeLaTeX')
  151. cy.get('#left-menu-modal').click()
  152. cy.log('Trigger compile with other compiler')
  153. recompile()
  154. cy.log('Check which compiler was used, expect XeLaTeX')
  155. cy.get('[aria-label="View logs"]').click()
  156. cy.findByText(/This is XeTeX/)
  157. })
  158. }
  159. function checkUsesDefaultCompiler() {
  160. beforeEach(function () {
  161. login('user@example.com')
  162. })
  163. it('should not offer TexLive images and use default compiler', () => {
  164. cy.visit('/project')
  165. createProject('sandboxed')
  166. // check produced PDF
  167. cy.get('.pdf-viewer').should('contain.text', 'sandboxed')
  168. cy.get('[aria-label="View logs"]').click()
  169. cy.findByText(/This is pdfTeX, Version .+ \(TeX Live 2024\) /)
  170. cy.get('header').findByText('Menu').click()
  171. cy.findByText('Word Count') // wait for lazy loading
  172. cy.findByText('TeX Live version').should('not.exist')
  173. })
  174. }
  175. describe('disabled in Server Pro', () => {
  176. startWith({ pro: true })
  177. checkUsesDefaultCompiler()
  178. checkSyncTeX()
  179. checkXeTeX()
  180. })
  181. describe.skip('unavailable in CE', () => {
  182. startWith({ pro: false, vars: enabledVars })
  183. checkUsesDefaultCompiler()
  184. checkSyncTeX()
  185. checkXeTeX()
  186. })
  187. })