sandboxed-compiles.spec.ts 7.3 KB

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