pdf-preview.spec.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. import localStorage from '@/infrastructure/local-storage'
  2. import PdfPreview from '../../../../frontend/js/features/pdf-preview/components/pdf-preview'
  3. import { EditorProviders } from '../../helpers/editor-providers'
  4. import { mockScope } from './scope'
  5. import {
  6. IdeLayout,
  7. IdeView,
  8. useLayoutContext,
  9. } from '../../../../frontend/js/shared/context/layout-context'
  10. import { FC, useEffect } from 'react'
  11. const storeAndFireEvent = (win: typeof window, key: string, value: unknown) => {
  12. localStorage.setItem(key, value)
  13. win.dispatchEvent(new StorageEvent('storage', { key }))
  14. }
  15. const Layout: FC<{ layout: IdeLayout; view?: IdeView }> = ({
  16. layout,
  17. view,
  18. }) => {
  19. const { changeLayout } = useLayoutContext()
  20. useEffect(() => {
  21. changeLayout(layout, view)
  22. }, [changeLayout, layout, view])
  23. return null
  24. }
  25. describe('<PdfPreview/>', function () {
  26. let projectId: string
  27. beforeEach(function () {
  28. /**
  29. * There are time sensitive tests in this test suite. They need to wait for a Promise before resolving a request.
  30. *
  31. * Using a promise across the test-env (browser) vs stub-env (server) causes additional latency.
  32. *
  33. * This latency seems to stack up when adding more intercepts for the same path. Using static responses for some of these intercepts does not help.
  34. *
  35. * All of that seems like a bug in Cypress. For now just work around it by using a unique projectId for each intercept.
  36. */
  37. projectId = Math.random().toString().slice(2)
  38. window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
  39. window.metaAttributesCache.set(
  40. 'ol-compilesUserContentDomain',
  41. 'https://compiles-user.dev-overleaf.com'
  42. )
  43. window.metaAttributesCache.set('ol-splitTestVariants', {
  44. 'populate-clsi-cache': 'enabled',
  45. })
  46. window.metaAttributesCache.set('ol-projectOwnerHasPremiumOnPageLoad', true)
  47. cy.interceptEvents()
  48. })
  49. it('renders the PDF preview', function () {
  50. window.metaAttributesCache.set('ol-preventCompileOnLoad', false)
  51. cy.interceptCompile()
  52. const scope = mockScope()
  53. cy.mount(
  54. <EditorProviders scope={scope}>
  55. <div className="pdf-viewer">
  56. <PdfPreview />
  57. </div>
  58. </EditorProviders>
  59. )
  60. // wait for "compile on load" to finish
  61. cy.waitForCompile({ pdf: true })
  62. cy.findByRole('button', { name: 'Recompile' })
  63. })
  64. it('uses the cache when available', function () {
  65. cy.interceptCompile({
  66. prefix: 'compile',
  67. times: 1,
  68. cached: true,
  69. regular: false,
  70. })
  71. const scope = mockScope()
  72. cy.mount(
  73. <EditorProviders scope={scope}>
  74. <div className="pdf-viewer">
  75. <PdfPreview />
  76. </div>
  77. </EditorProviders>
  78. )
  79. // wait for "compile from cache on load" to finish
  80. cy.waitForCompile({ pdf: true, cached: true, regular: false })
  81. cy.contains('Your Paper')
  82. })
  83. it('uses the cache when available then compiles', function () {
  84. cy.interceptCompile({
  85. prefix: 'compile',
  86. times: 1,
  87. cached: true,
  88. regular: false,
  89. })
  90. const scope = mockScope()
  91. cy.mount(
  92. <EditorProviders scope={scope}>
  93. <div className="pdf-viewer">
  94. <PdfPreview />
  95. </div>
  96. </EditorProviders>
  97. )
  98. // wait for "compile from cache on load" to finish
  99. cy.waitForCompile({ pdf: true, cached: true, regular: false })
  100. cy.contains('Your Paper')
  101. // Then trigger a new compile
  102. cy.interceptCompile({
  103. prefix: 'recompile',
  104. times: 1,
  105. cached: false,
  106. outputPDFFixture: 'output-2.pdf',
  107. })
  108. // press the Recompile button => compile
  109. cy.findByRole('button', { name: 'Recompile' }).click()
  110. // wait for compile to finish
  111. cy.waitForCompile({ prefix: 'recompile', pdf: true })
  112. cy.contains('Modern Authoring Tools for Science')
  113. })
  114. describe('racing compile from cache and regular compile trigger', function () {
  115. for (const [timing] of ['before rendering', 'after rendering']) {
  116. it(`replaces the compile from cache with a regular compile - ${timing}`, function () {
  117. const requestedOnce = new Set()
  118. ;['log', 'pdf', 'blg'].forEach(ext => {
  119. cy.intercept({ pathname: `/build/*/output.${ext}` }, req => {
  120. if (requestedOnce.has(ext)) {
  121. throw new Error(
  122. `compile from cache triggered extra ${ext} request: ${req.url}`
  123. )
  124. }
  125. requestedOnce.add(ext)
  126. req.reply({ fixture: `build/output.${ext},null` })
  127. }).as(`compile-${ext}`)
  128. })
  129. const { promise, resolve } = Promise.withResolvers<void>()
  130. cy.interceptCompileFromCacheRequest({
  131. promise,
  132. times: 1,
  133. }).as('cached-compile')
  134. cy.interceptCompileRequest().as('compile')
  135. const scope = mockScope()
  136. cy.mount(
  137. <EditorProviders scope={scope} projectId={projectId}>
  138. <div className="pdf-viewer">
  139. <PdfPreview />
  140. </div>
  141. </EditorProviders>
  142. )
  143. // press the Recompile button => compile
  144. cy.findByRole('button', { name: 'Recompile' }).click()
  145. if (timing === 'before rendering') {
  146. cy.then(() => resolve())
  147. cy.wait('@cached-compile')
  148. }
  149. // wait for rendering to finish
  150. cy.waitForCompile({ pdf: true, cached: false })
  151. if (timing === 'after rendering') {
  152. cy.then(() => resolve())
  153. cy.wait('@cached-compile')
  154. }
  155. cy.contains('Your Paper')
  156. cy.then(() => Array.from(requestedOnce).sort().join(',')).should(
  157. 'equal',
  158. 'blg,log,pdf'
  159. )
  160. })
  161. }
  162. })
  163. describe('clsi-cache project settings validation', function () {
  164. const cases = {
  165. // Flaky, skip for now
  166. 'uses compile from cache when nothing changed': {
  167. cached: true,
  168. setup: () => {},
  169. props: {},
  170. },
  171. 'ignores the compile from cache when imageName changed': {
  172. cached: false,
  173. setup: () => {},
  174. props: {
  175. imageName: 'texlive-full:2025.1',
  176. },
  177. },
  178. 'ignores the compile from cache when compiler changed': {
  179. cached: false,
  180. setup: () => {},
  181. props: {
  182. compiler: 'lualatex',
  183. },
  184. },
  185. 'ignores the compile from cache when draft mode changed': {
  186. cached: false,
  187. setup: () => {
  188. cy.window().then(w =>
  189. w.localStorage.setItem(`draft:${projectId}`, 'true')
  190. )
  191. },
  192. props: {},
  193. },
  194. 'ignores the compile from cache when stopOnFirstError mode changed': {
  195. cached: false,
  196. setup: () => {
  197. cy.window().then(w =>
  198. w.localStorage.setItem(`stop_on_first_error:${projectId}`, 'true')
  199. )
  200. },
  201. props: {},
  202. },
  203. 'ignores the compile from cache when rootDoc changed': {
  204. cached: false,
  205. setup: () => {},
  206. props: {
  207. rootDocId: 'new-root-doc-id',
  208. rootFolder: [
  209. {
  210. _id: 'root-folder-id',
  211. name: 'rootFolder',
  212. docs: [
  213. {
  214. _id: '_root_doc_id',
  215. name: 'main.tex',
  216. },
  217. {
  218. _id: 'new-root-doc-id',
  219. name: 'new-main.tex',
  220. },
  221. ],
  222. folders: [],
  223. fileRefs: [],
  224. },
  225. ],
  226. },
  227. },
  228. }
  229. Object.entries(cases).forEach(([name, { cached, setup, props }]) => {
  230. it(name, function () {
  231. cy.interceptCompile({
  232. cached: true,
  233. regular: !cached,
  234. })
  235. const scope = mockScope()
  236. window.metaAttributesCache.set('ol-preventCompileOnLoad', false)
  237. setup()
  238. cy.mount(
  239. <EditorProviders scope={scope} projectId={projectId} {...props}>
  240. <div className="pdf-viewer">
  241. <PdfPreview />
  242. </div>
  243. </EditorProviders>
  244. )
  245. // wait for compile to finish
  246. cy.waitForCompile({ pdf: true, cached, regular: !cached })
  247. cy.contains('Your Paper')
  248. })
  249. })
  250. })
  251. it('runs a compile when the Recompile button is pressed', function () {
  252. cy.interceptCompile()
  253. const scope = mockScope()
  254. cy.mount(
  255. <EditorProviders scope={scope}>
  256. <div className="pdf-viewer">
  257. <PdfPreview />
  258. </div>
  259. </EditorProviders>
  260. )
  261. // press the Recompile button => compile
  262. cy.findByRole('button', { name: 'Recompile' }).click()
  263. // wait for compile to finish
  264. cy.waitForCompile({ pdf: true })
  265. cy.contains('Your Paper')
  266. })
  267. it('runs a compile on `pdf:recompile` event', function () {
  268. cy.interceptCompile()
  269. const scope = mockScope()
  270. cy.mount(
  271. <EditorProviders scope={scope}>
  272. <div className="pdf-viewer">
  273. <PdfPreview />
  274. </div>
  275. </EditorProviders>
  276. )
  277. cy.window().then(win => {
  278. win.dispatchEvent(new CustomEvent('pdf:recompile'))
  279. })
  280. // wait for compile to finish
  281. cy.waitForCompile({ pdf: true })
  282. cy.contains('Your Paper')
  283. })
  284. it('does not compile while compiling', function () {
  285. let counter = 0
  286. cy.interceptDeferredCompile(() => counter++).then(
  287. resolveDeferredCompile => {
  288. const scope = mockScope()
  289. cy.mount(
  290. <EditorProviders scope={scope}>
  291. <div className="pdf-viewer">
  292. <PdfPreview />
  293. </div>
  294. </EditorProviders>
  295. )
  296. // start compiling
  297. cy.findByRole('button', { name: 'Recompile' }).click()
  298. cy.findByRole('button', { name: 'Compiling…' }).then(() => {
  299. // trigger a recompile
  300. cy.window().then(win => {
  301. win.dispatchEvent(new CustomEvent('pdf:recompile'))
  302. })
  303. // finish the original compile
  304. resolveDeferredCompile()
  305. // wait for the original compile to finish
  306. cy.waitForCompile().then(() => {
  307. // NOTE: difficult to assert that a second request won't be sent, at some point
  308. expect(counter).to.equal(1)
  309. })
  310. })
  311. }
  312. )
  313. })
  314. it('disables compile button while compile is running', function () {
  315. cy.interceptDeferredCompile().then(resolveDeferredCompile => {
  316. const scope = mockScope()
  317. cy.mount(
  318. <EditorProviders scope={scope}>
  319. <div className="pdf-viewer">
  320. <PdfPreview />
  321. </div>
  322. </EditorProviders>
  323. )
  324. cy.findByRole('button', { name: 'Recompile' }).click()
  325. cy.findByRole('button', { name: 'Compiling…' })
  326. .should('be.disabled')
  327. .then(() => resolveDeferredCompile())
  328. cy.waitForCompile()
  329. cy.findByRole('button', { name: 'Recompile' }).should('not.be.disabled')
  330. })
  331. })
  332. it('runs a compile on doc change if autocompile is enabled', function () {
  333. cy.interceptCompile()
  334. const scope = mockScope()
  335. cy.mount(
  336. <EditorProviders scope={scope}>
  337. <div className="pdf-viewer">
  338. <PdfPreview />
  339. </div>
  340. </EditorProviders>
  341. )
  342. cy.window().then(win => {
  343. cy.clock()
  344. // switch on auto compile
  345. storeAndFireEvent(win, 'autocompile_enabled:project123', true)
  346. // fire a doc:changed event => compile
  347. win.dispatchEvent(new CustomEvent('doc:changed'))
  348. // wait enough time for the compile to start
  349. cy.tick(6000) // > AUTO_COMPILE_DEBOUNCE
  350. cy.clock().invoke('restore')
  351. })
  352. // wait for compile to finish
  353. cy.waitForCompile({ pdf: true })
  354. cy.findByRole('button', { name: 'Recompile' })
  355. })
  356. it('does not run a compile on doc change if autocompile is disabled', function () {
  357. cy.interceptCompile()
  358. const scope = mockScope()
  359. cy.mount(
  360. <EditorProviders scope={scope}>
  361. <div className="pdf-viewer">
  362. <PdfPreview />
  363. </div>
  364. </EditorProviders>
  365. )
  366. cy.window().then(win => {
  367. cy.clock()
  368. // make sure auto compile is switched off
  369. storeAndFireEvent(win, 'autocompile_enabled:project123', false)
  370. // fire a doc:changed event => no compile
  371. win.dispatchEvent(new CustomEvent('doc:changed'))
  372. // wait enough time for the compile to start
  373. cy.tick(6000) // AUTO_COMPILE_DEBOUNCE
  374. cy.clock().invoke('restore')
  375. })
  376. // NOTE: difficult to assert that a request hasn't been sent
  377. cy.findByRole('button', { name: 'Recompile' })
  378. })
  379. it('does not run a compile on doc change if autocompile is blocked by syntax check', function () {
  380. cy.interceptCompile()
  381. const scope = mockScope()
  382. // enable linting in the editor
  383. const userSettings = { syntaxValidation: true }
  384. // mock a linting error
  385. scope.hasLintingError = true
  386. cy.mount(
  387. <EditorProviders scope={scope} userSettings={userSettings}>
  388. <div className="pdf-viewer">
  389. <PdfPreview />
  390. </div>
  391. </EditorProviders>
  392. )
  393. cy.window().then(win => {
  394. cy.clock()
  395. // switch on auto compile
  396. storeAndFireEvent(win, 'autocompile_enabled:project123', true)
  397. // switch on syntax checking
  398. storeAndFireEvent(win, 'stop_on_validation_error', true)
  399. // fire a doc:changed event => no compile
  400. win.dispatchEvent(new CustomEvent('doc:changed'))
  401. // wait enough time for the compile to start
  402. cy.tick(6000) // AUTO_COMPILE_DEBOUNCE
  403. cy.clock().invoke('restore')
  404. })
  405. // NOTE: difficult to assert that a request hasn't been sent
  406. cy.findByRole('button', { name: 'Recompile' })
  407. cy.findByText('Code check failed')
  408. })
  409. it('does not run a compile on doc change if the PDF preview is not open', function () {
  410. cy.interceptCompile()
  411. const scope = mockScope()
  412. cy.mount(
  413. <EditorProviders scope={scope}>
  414. <Layout layout="flat" view="editor" />
  415. <div className="pdf-viewer">
  416. <PdfPreview />
  417. </div>
  418. </EditorProviders>
  419. )
  420. cy.window().then(win => {
  421. cy.clock()
  422. // switch on auto compile
  423. storeAndFireEvent(win, 'autocompile_enabled:project123', true)
  424. // fire a doc:changed event => compile
  425. win.dispatchEvent(new CustomEvent('doc:changed'))
  426. // wait enough time for the compile to start
  427. cy.tick(6000) // > AUTO_COMPILE_DEBOUNCE
  428. cy.clock().invoke('restore')
  429. })
  430. // NOTE: difficult to assert that a request hasn't been sent
  431. cy.findByRole('button', { name: 'Recompile' })
  432. })
  433. describe('error messages', function () {
  434. const compileErrorStatuses = {
  435. 'clear-cache':
  436. 'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
  437. 'clsi-maintenance':
  438. 'The compile servers are down for maintenance, and will be back shortly.',
  439. 'compile-in-progress':
  440. 'A previous compile is still running. Please wait a minute and try compiling again.',
  441. exited: 'Server Error',
  442. failure: 'No PDF',
  443. generic: 'Server Error',
  444. 'project-too-large': 'Project too large',
  445. 'rate-limited': 'Compile rate limit hit',
  446. terminated: 'Compilation cancelled',
  447. timedout: 'Timed out',
  448. 'too-recently-compiled':
  449. 'This project was compiled very recently, so this compile has been skipped.',
  450. unavailable:
  451. 'Sorry, the compile server for your project was temporarily unavailable. Please try again in a few moments.',
  452. foo: 'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
  453. }
  454. for (const [status, message] of Object.entries(compileErrorStatuses)) {
  455. it(`displays error message for '${status}' status`, function () {
  456. cy.intercept('POST', '/project/*/compile*', {
  457. body: {
  458. status,
  459. clsiServerId: 'foo',
  460. compileGroup: 'priority',
  461. },
  462. }).as('compile')
  463. const scope = mockScope()
  464. cy.mount(
  465. <EditorProviders scope={scope}>
  466. <div className="pdf-viewer">
  467. <PdfPreview />
  468. </div>
  469. </EditorProviders>
  470. )
  471. cy.findByRole('button', { name: 'Recompile' }).click()
  472. cy.wait('@compile')
  473. cy.findByText(message)
  474. })
  475. }
  476. })
  477. it('displays expandable raw logs', function () {
  478. cy.interceptCompile()
  479. const scope = mockScope()
  480. cy.mount(
  481. <EditorProviders scope={scope}>
  482. <div className="pdf-viewer">
  483. <PdfPreview />
  484. </div>
  485. </EditorProviders>
  486. )
  487. cy.findByRole('button', { name: 'Recompile' }).click()
  488. cy.waitForCompile({ pdf: true })
  489. cy.findByRole('button', { name: 'View logs' }).click()
  490. cy.findByRole('button', { name: 'View PDF' })
  491. cy.findByRole('button', { name: 'Expand' }).click()
  492. cy.findByRole('button', { name: 'Collapse' }).click()
  493. })
  494. it('displays error messages if there were validation problems', function () {
  495. const validationProblems = {
  496. sizeCheck: {
  497. resources: [
  498. { path: 'foo/bar', kbSize: 76221 },
  499. { path: 'bar/baz', kbSize: 2342 },
  500. ],
  501. },
  502. mainFile: true,
  503. conflictedPaths: [
  504. {
  505. path: 'foo/bar',
  506. },
  507. {
  508. path: 'foo/baz',
  509. },
  510. ],
  511. }
  512. cy.intercept('POST', '/project/*/compile*', {
  513. body: {
  514. status: 'validation-problems',
  515. validationProblems,
  516. clsiServerId: 'foo',
  517. compileGroup: 'priority',
  518. },
  519. }).as('compile')
  520. const scope = mockScope()
  521. cy.mount(
  522. <EditorProviders scope={scope}>
  523. <div className="pdf-viewer">
  524. <PdfPreview />
  525. </div>
  526. </EditorProviders>
  527. )
  528. cy.findByRole('button', { name: 'Recompile' }).click()
  529. cy.wait('@compile')
  530. cy.findByText('Project too large')
  531. cy.findByText('Unknown main document')
  532. cy.findByText('Conflicting Paths Found')
  533. })
  534. describe('clear cache', function () {
  535. it('sends a clear cache request when the button is pressed', function () {
  536. cy.interceptCompile()
  537. const scope = mockScope()
  538. cy.mount(
  539. <EditorProviders scope={scope}>
  540. <div className="pdf-viewer">
  541. <PdfPreview />
  542. </div>
  543. </EditorProviders>
  544. )
  545. cy.findByRole('button', { name: 'Recompile' }).click()
  546. cy.waitForCompile({ pdf: true })
  547. cy.findByRole('button', { name: 'View logs' }).click()
  548. cy.findByRole('button', { name: 'Clear cached files' }).should(
  549. 'not.be.disabled'
  550. )
  551. const { promise, resolve } = Promise.withResolvers<void>()
  552. cy.intercept('DELETE', '/project/*/output*', req => {
  553. return promise
  554. .then(() => Cypress.Promise.delay(100))
  555. .then(() => {
  556. req.reply({ statusCode: 204 })
  557. })
  558. }).as('clear-cache')
  559. // click the button
  560. cy.findByRole('button', { name: 'Clear cached files' }).click()
  561. cy.findByRole('button', { name: 'Clear cached files' }).should(
  562. 'be.disabled'
  563. )
  564. cy.then(() => {
  565. resolve()
  566. })
  567. cy.wait('@clear-cache')
  568. cy.findByRole('button', { name: 'Clear cached files' }).should(
  569. 'not.be.disabled'
  570. )
  571. })
  572. it('handle "recompile from scratch"', function () {
  573. cy.interceptCompile()
  574. const scope = mockScope()
  575. cy.mount(
  576. <EditorProviders scope={scope}>
  577. <div className="pdf-viewer">
  578. <PdfPreview />
  579. </div>
  580. </EditorProviders>
  581. )
  582. cy.findByRole('button', { name: 'Recompile' }).click()
  583. cy.waitForCompile({ pdf: true })
  584. cy.interceptCompile({ prefix: 'recompile' })
  585. cy.intercept('DELETE', '/project/*/output*', {
  586. statusCode: 204,
  587. delay: 100,
  588. }).as('clear-cache')
  589. // show the logs UI
  590. cy.findByRole('button', { name: 'View logs' }).click()
  591. cy.findByRole('button', { name: 'Clear cached files' }).should(
  592. 'not.be.disabled'
  593. )
  594. cy.interceptDeferredCompile().then(resolveDeferredCompile => {
  595. cy.findByRole('button', { name: 'Toggle compile options menu' }).click()
  596. cy.findByRole('menuitem', {
  597. name: 'Recompile from scratch',
  598. }).trigger('click')
  599. cy.findByRole('button', { name: 'Clear cached files' }).should(
  600. 'be.disabled'
  601. )
  602. cy.wait('@clear-cache')
  603. cy.findByRole('button', { name: 'Compiling…' }).then(() =>
  604. resolveDeferredCompile()
  605. )
  606. // wait for recompile from scratch to finish
  607. cy.waitForCompile({ pdf: true })
  608. cy.findByRole('button', { name: 'Recompile' })
  609. })
  610. })
  611. })
  612. describe('invalid URLs and broken PDFs', function () {
  613. it('shows an error for an invalid URL', function () {
  614. cy.interceptCompile()
  615. cy.intercept('/build/*/output.pdf*', {
  616. statusCode: 500,
  617. body: {
  618. message: 'something awful happened',
  619. code: 'AWFUL_ERROR',
  620. },
  621. }).as('compile-pdf-error')
  622. const scope = mockScope()
  623. cy.mount(
  624. <EditorProviders scope={scope}>
  625. <div className="pdf-viewer">
  626. <PdfPreview />
  627. </div>
  628. </EditorProviders>
  629. )
  630. cy.findByRole('button', { name: 'Recompile' }).click()
  631. cy.waitForCompile()
  632. cy.wait('@compile-pdf-error')
  633. cy.contains('Something went wrong while rendering this PDF.')
  634. cy.contains(
  635. 'Please try recompiling the project from scratch, and if that doesn’t help, follow our troubleshooting guide.'
  636. )
  637. cy.findByLabelText('Page 1').should('not.exist')
  638. })
  639. it('shows an error for a corrupt PDF', function () {
  640. cy.interceptCompile()
  641. cy.intercept('/build/*/output.pdf*', {
  642. fixture: 'build/output-corrupt.pdf,null',
  643. }).as('compile-pdf-corrupt')
  644. const scope = mockScope()
  645. cy.mount(
  646. <EditorProviders scope={scope}>
  647. <div className="pdf-viewer">
  648. <PdfPreview />
  649. </div>
  650. </EditorProviders>
  651. )
  652. cy.findByRole('button', { name: 'Recompile' }).click()
  653. cy.waitForCompile()
  654. cy.wait('@compile-pdf-corrupt')
  655. cy.contains('Something went wrong while rendering this PDF.')
  656. cy.contains(
  657. 'Please try recompiling the project from scratch, and if that doesn’t help, follow our troubleshooting guide.'
  658. )
  659. cy.findByLabelText('Page 1').should('not.exist')
  660. })
  661. })
  662. describe('human readable logs', function () {
  663. it('shows human readable hint for undefined reference errors', function () {
  664. cy.interceptCompile()
  665. cy.intercept('/build/*/output.log*', {
  666. fixture: 'build/output-human-readable.log',
  667. }).as('compile-log')
  668. const scope = mockScope()
  669. cy.mount(
  670. <EditorProviders scope={scope}>
  671. <div className="pdf-viewer">
  672. <PdfPreview />
  673. </div>
  674. </EditorProviders>
  675. )
  676. cy.findByRole('button', { name: 'Recompile' }).click()
  677. cy.waitForCompile()
  678. cy.findByRole('button', { name: 'View logs' }).click()
  679. cy.findByText(
  680. "Reference `intorduction' on page 1 undefined on input line 11."
  681. )
  682. cy.findByText(
  683. "Reference `section1' on page 1 undefined on input line 13."
  684. )
  685. cy.findByText('There were undefined references.')
  686. cy.findAllByText(
  687. /You have referenced something which has not yet been labelled/
  688. ).should('have.length', 3)
  689. })
  690. it('does not show human readable hint when no undefined reference errors', function () {
  691. cy.interceptCompile()
  692. cy.intercept('/build/*/output.log?*', {
  693. fixture: 'build/output-undefined-references.log',
  694. }).as('compile-log')
  695. const scope = mockScope()
  696. cy.mount(
  697. <EditorProviders scope={scope}>
  698. <div className="pdf-viewer">
  699. <PdfPreview />
  700. </div>
  701. </EditorProviders>
  702. )
  703. cy.findByRole('button', { name: 'Recompile' }).click()
  704. cy.waitForCompile()
  705. cy.findByRole('button', { name: 'View logs' }).click()
  706. cy.findByText(
  707. "Package rerunfilecheck Warning: File `output.brf' has changed. Rerun to get bibliographical references right."
  708. )
  709. cy.findByText(
  710. /You have referenced something which has not yet been labelled/
  711. ).should('not.exist')
  712. })
  713. })
  714. })