diff --git a/server-ce/test/package.json b/server-ce/test/package.json index b31e0f9302..e2932b8a6b 100644 --- a/server-ce/test/package.json +++ b/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}'" }, diff --git a/server-ce/test/sandboxed-compiles.spec.ts b/server-ce/test/sandboxed-compiles.spec.ts index 3b158e0166..19ddc9b5d5 100644 --- a/server-ce/test/sandboxed-compiles.spec.ts +++ b/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() diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.tsx index d45075792e..6ac2466f13 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.tsx +++ b/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 () => {