Răsfoiți Sursa

Merge pull request #19791 from overleaf/jpa-enable-synctex-test

[server-ce] tests: re-enable test for sync to pdf

GitOrigin-RevId: fd111ba1ff846acfe82735b4bc47f68929266254
Jakob Ackermann 2 ani în urmă
părinte
comite
eede7fe313

+ 1 - 1
server-ce/test/package.json

@@ -4,7 +4,7 @@
   "private": true,
   "scripts": {
     "cypress:open": "cypress open",
-    "cypress:run": "cypress run",
+    "cypress:run": "cypress run --browser chrome",
     "format": "prettier --list-different $PWD/'**/*.{js,mjs,ts,tsx,json}'",
     "format:fix": "prettier --write $PWD/'**/*.{js,mjs,ts,tsx,json}'"
   },

+ 9 - 22
server-ce/test/sandboxed-compiles.spec.ts

@@ -63,9 +63,8 @@ describe('SandboxedCompiles', function () {
   function checkSyncTeX() {
     describe('SyncTeX', () => {
       let projectName: string
-      beforeWithReRunOnTestRetry(function () {
+      beforeEach(function () {
         projectName = `Project ${uuid()}`
-        login('user@example.com')
         cy.visit('/project')
         createProject(projectName)
         const recompile = throttledRecompile()
@@ -76,12 +75,13 @@ describe('SandboxedCompiles', function () {
             `\n\\pagebreak\n\\section{{}Section A}\n\\pagebreak\n\\section{{}Section B}\n\\pagebreak`
           )
         recompile()
+        cy.log('wait for pdf-rendering')
+        cy.get('.pdf-viewer').within(() => {
+          cy.findByText(projectName)
+        })
       })
 
       it('should sync to code', () => {
-        cy.visit('/project')
-        cy.findByText(projectName).click()
-
         cy.log('navigate to \\maketitle using double click in PDF')
         cy.get('.pdf-viewer').within(() => {
           cy.findByText(projectName).dblclick()
@@ -112,26 +112,13 @@ describe('SandboxedCompiles', function () {
         cy.get('.cm-activeLine').should('have.text', '\\section{Section B}')
       })
 
-      // Waiting for a fix of https://github.com/overleaf/internal/issues/18603
-      it.skip('should sync to pdf', () => {
-        cy.visit('/project')
-        cy.findByText(projectName).click()
-
-        cy.log('wait for compile')
-        cy.get('.pdf-viewer').within(() => {
-          cy.findByText(projectName)
-        })
-
+      it('should sync to pdf', () => {
         cy.log('zoom in')
-        for (let i = 0; i < 8; i++) {
-          cy.get('[aria-label="Zoom in"]').click({ force: true })
-        }
+        cy.findByText('45%').click()
+        cy.findByText('400%').click()
         cy.log('scroll to top')
         cy.get('.pdfjs-viewer-inner').scrollTo('top')
-        waitUntilScrollingFinished('.pdfjs-viewer-inner', -1)
-        cy.get('.pdfjs-viewer-inner')
-          .should('have.prop', 'scrollTop')
-          .as('start')
+        waitUntilScrollingFinished('.pdfjs-viewer-inner', -1).as('start')
 
         cy.log('navigate to title')
         cy.findByText('\\maketitle').parent().click()

+ 11 - 6
services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.tsx

@@ -341,7 +341,7 @@ function PdfJsViewer({ url, pdfFile }: PdfJsViewerProps) {
               timers.push(
                 window.setTimeout(() => {
                   element.style.opacity = '0'
-                }, 1000)
+                }, 1100)
               )
             }
           }
@@ -367,11 +367,16 @@ function PdfJsViewer({ url, pdfFile }: PdfJsViewerProps) {
 
       if (firstElement) {
         // scroll to the first highlighted element
-        firstElement.scrollIntoView({
-          block: 'center',
-          inline: 'start',
-          behavior: 'smooth',
-        })
+        // Briefly delay the scrolling after adding the element to the DOM.
+        timers.push(
+          window.setTimeout(() => {
+            firstElement.scrollIntoView({
+              block: 'center',
+              inline: 'start',
+              behavior: 'smooth',
+            })
+          }, 100)
+        )
       }
 
       return () => {