From b2fbc3993069b1a0ef00dd49364857675218ffe1 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 25 Mar 2024 11:55:06 +0000 Subject: [PATCH] Improve tests for layout components (#17518) GitOrigin-RevId: 1d08224a5282482dcf153a2ebcff69a08be2eb58 --- .../switch-to-editor-button.spec.tsx | 38 +++++++++++++++++ .../components/switch-to-pdf-button.spec.tsx | 42 +++++++++++++++++++ .../components/switch-to-pdf-button.test.jsx | 36 ---------------- 3 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 services/web/test/frontend/features/layout/components/switch-to-editor-button.spec.tsx create mode 100644 services/web/test/frontend/features/layout/components/switch-to-pdf-button.spec.tsx delete mode 100644 services/web/test/frontend/features/source-editor/components/switch-to-pdf-button.test.jsx diff --git a/services/web/test/frontend/features/layout/components/switch-to-editor-button.spec.tsx b/services/web/test/frontend/features/layout/components/switch-to-editor-button.spec.tsx new file mode 100644 index 0000000000..3cb8ea2fee --- /dev/null +++ b/services/web/test/frontend/features/layout/components/switch-to-editor-button.spec.tsx @@ -0,0 +1,38 @@ +import { EditorProviders } from '../../../helpers/editor-providers' +import SwitchToEditorButton from '@/features/pdf-preview/components/switch-to-editor-button' + +describe('', function () { + it('shows button in full screen pdf layout', function () { + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to editor' }) + }) + + it('does not show button in split screen layout', function () { + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to editor' }).should('not.exist') + }) + + it('does not show button when detached', function () { + window.metaAttributesCache.set('ol-detachRole', 'detacher') + + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to editor' }).should('not.exist') + }) +}) diff --git a/services/web/test/frontend/features/layout/components/switch-to-pdf-button.spec.tsx b/services/web/test/frontend/features/layout/components/switch-to-pdf-button.spec.tsx new file mode 100644 index 0000000000..43fc1cabfc --- /dev/null +++ b/services/web/test/frontend/features/layout/components/switch-to-pdf-button.spec.tsx @@ -0,0 +1,42 @@ +import SwitchToPDFButton from '@/features/source-editor/components/switch-to-pdf-button' +import { EditorProviders } from '../../../helpers/editor-providers' + +describe('', function () { + it('shows button in full screen editor layout', function () { + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to PDF' }) + }) + + it('does not show button in split screen layout', function () { + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to PDF' }).should('not.exist') + }) + + it('does not show button when detached', function () { + window.metaAttributesCache.set('ol-detachRole', 'detacher') + + cy.mount( + + + + ) + + cy.findByRole('button', { name: 'Switch to PDF' }).should('not.exist') + }) +}) diff --git a/services/web/test/frontend/features/source-editor/components/switch-to-pdf-button.test.jsx b/services/web/test/frontend/features/source-editor/components/switch-to-pdf-button.test.jsx deleted file mode 100644 index 635d29f019..0000000000 --- a/services/web/test/frontend/features/source-editor/components/switch-to-pdf-button.test.jsx +++ /dev/null @@ -1,36 +0,0 @@ -import { screen } from '@testing-library/react' -import { expect } from 'chai' -import { renderWithEditorContext } from '../../../helpers/render-with-context' -import SwitchToPDFButton from '../../../../../frontend/js/features/source-editor/components/switch-to-pdf-button' - -describe('', function () { - beforeEach(function () { - window.metaAttributesCache = new Map() - }) - - afterEach(function () { - window.metaAttributesCache = new Map() - }) - - it('shows button in full screen layout', function () { - renderWithEditorContext(, { - ui: { view: 'editor', pdfLayout: 'flat' }, - }) - screen.getByRole('button', { name: 'Switch to PDF' }) - }) - - it('does not show button in split screen layout', function () { - renderWithEditorContext(, { - ui: { view: 'editor', pdfLayout: 'sideBySide' }, - }) - expect(screen.queryByRole('button', { name: 'Full screen' })).to.not.exist - }) - - it('does not show button when detached', function () { - window.metaAttributesCache.set('ol-detachRole', 'detacher') - renderWithEditorContext(, { - ui: { view: 'editor', pdfLayout: 'flat' }, - }) - expect(screen.queryByRole('button', { name: 'Full screen' })).to.not.exist - }) -})