diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js index 287ef6bd31..ced41ee76e 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js @@ -28,6 +28,17 @@ function GoToCodeButton({ 'detach-synctex-control': !!isDetachLayout, }) + let buttonIcon = null + if (syncToCodeInFlight) { + buttonIcon = ( + + ) + } else if (!isDetachLayout) { + buttonIcon = ( + + ) + } + return ( - {syncToCodeInFlight ? ( - - ) : ( - - )} + {buttonIcon} {isDetachLayout ?  {t('show_in_code')} : ''} @@ -68,6 +75,17 @@ function GoToPdfButton({ 'detach-synctex-control': !!isDetachLayout, }) + let buttonIcon = null + if (syncToPdfInFlight) { + buttonIcon = ( + + ) + } else if (!isDetachLayout) { + buttonIcon = ( + + ) + } + return ( - {syncToPdfInFlight ? ( - - ) : ( - - )} + {buttonIcon} {isDetachLayout ?  {t('show_in_pdf')} : ''} diff --git a/services/web/test/frontend/features/pdf-preview/components/pdf-synctex-controls.test.js b/services/web/test/frontend/features/pdf-preview/components/pdf-synctex-controls.test.js index 04c598aa8b..3b1c7cc773 100644 --- a/services/web/test/frontend/features/pdf-preview/components/pdf-synctex-controls.test.js +++ b/services/web/test/frontend/features/pdf-preview/components/pdf-synctex-controls.test.js @@ -125,7 +125,7 @@ describe('', function () { return null } - renderWithEditorContext( + const { container } = renderWithEditorContext( <> @@ -141,6 +141,10 @@ describe('', function () { name: 'Go to PDF location in code', }) + expect(container.querySelectorAll('.synctex-control-icon').length).to.equal( + 2 + ) + // mock editor cursor position update fireEvent( window, @@ -173,14 +177,18 @@ describe('', function () { window.metaAttributesCache.set('ol-detachRole', 'detacher') }) - it('does not have go to PDF location button', async function () { - renderWithEditorContext(, { scope }) + it('does not have go to PDF location button nor arrow icon', async function () { + const { container } = renderWithEditorContext(, { + scope, + }) expect( await screen.queryByRole('button', { name: 'Go to PDF location in code', }) ).to.not.exist + + expect(container.querySelector('.synctex-control-icon')).to.not.exist }) it('send go to PDF location action', async function () { @@ -212,7 +220,9 @@ describe('', function () { }) it('update inflight state', async function () { - renderWithEditorContext(, { scope }) + const { container } = renderWithEditorContext(, { + scope, + }) sysendTestHelper.resetHistory() const syncToPdfButton = await screen.findByRole('button', { @@ -233,6 +243,9 @@ describe('', function () { data: { value: true }, }) expect(syncToPdfButton.disabled).to.be.true + expect(container.querySelectorAll('.synctex-spin-icon').length).to.equal( + 1 + ) sysendTestHelper.receiveMessage({ role: 'detached', @@ -240,6 +253,9 @@ describe('', function () { data: { value: false }, }) expect(syncToPdfButton.disabled).to.be.false + expect(container.querySelectorAll('.synctex-spin-icon').length).to.equal( + 0 + ) }) }) @@ -248,18 +264,24 @@ describe('', function () { window.metaAttributesCache.set('ol-detachRole', 'detached') }) - it('does not have go to code location button', async function () { - renderWithEditorContext(, { scope }) + it('does not have go to code location button nor arrow icon', async function () { + const { container } = renderWithEditorContext(, { + scope, + }) expect( await screen.queryByRole('button', { name: 'Go to code location in PDF', }) ).to.not.exist + + expect(container.querySelector('.synctex-control-icon')).to.not.exist }) it('send go to code line action and update inflight state', async function () { - renderWithEditorContext(, { scope }) + const { container } = renderWithEditorContext(, { + scope, + }) sysendTestHelper.resetHistory() const syncToCodeButton = await screen.findByRole('button', { @@ -268,9 +290,17 @@ describe('', function () { sysendTestHelper.resetHistory() + expect(syncToCodeButton.disabled).to.be.false + expect(container.querySelectorAll('.synctex-spin-icon').length).to.equal( + 0 + ) + fireEvent.click(syncToCodeButton) expect(syncToCodeButton.disabled).to.be.true + expect(container.querySelectorAll('.synctex-spin-icon').length).to.equal( + 1 + ) await waitFor(() => { expect(fetchMock.called('express:/project/:projectId/sync/pdf')).to.be