diff --git a/cypress/integration/autocompletion.spec.ts b/cypress/integration/autocompletion.spec.ts index 9851907d4..26f3f4b20 100644 --- a/cypress/integration/autocompletion.spec.ts +++ b/cypress/integration/autocompletion.spec.ts @@ -6,7 +6,7 @@ describe('Autocompletion works for', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() cy.get('.CodeMirror').click().get('textarea').as('codeinput') }) diff --git a/cypress/integration/deleteNote.spec.ts b/cypress/integration/deleteNote.spec.ts index f87de889e..48e4cad6b 100644 --- a/cypress/integration/deleteNote.spec.ts +++ b/cypress/integration/deleteNote.spec.ts @@ -6,7 +6,7 @@ describe('Delete note', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('correctly deletes a note', () => { diff --git a/cypress/integration/diagrams.spec.ts b/cypress/integration/diagrams.spec.ts index efdd3131e..03268e4f9 100644 --- a/cypress/integration/diagrams.spec.ts +++ b/cypress/integration/diagrams.spec.ts @@ -6,7 +6,7 @@ describe('Diagram codeblock ', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) /* diff --git a/cypress/integration/document-read-only-page.spec.ts b/cypress/integration/document-read-only-page.spec.ts index dddaf0905..da5410752 100644 --- a/cypress/integration/document-read-only-page.spec.ts +++ b/cypress/integration/document-read-only-page.spec.ts @@ -4,9 +4,11 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +import { PAGE_MODE } from '../support/visit' + describe('Document read only page', () => { it('renders the document mode', () => { - cy.visit('/s/test') + cy.visitTestNote(PAGE_MODE.DOCUMENT_READ_ONLY) cy.getMarkdownBody().should('exist') }) }) diff --git a/cypress/integration/documentTitle.spec.ts b/cypress/integration/documentTitle.spec.ts index 08bcf554e..2ecd67a9e 100644 --- a/cypress/integration/documentTitle.spec.ts +++ b/cypress/integration/documentTitle.spec.ts @@ -9,7 +9,7 @@ import { branding } from '../support/config' const title = 'This is a test title' describe('Document Title', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() cy.getByCypressId('view-mode-both').should('exist') }) diff --git a/cypress/integration/editorMode.spec.ts b/cypress/integration/editorMode.spec.ts index 9428b060c..e318d2c7e 100644 --- a/cypress/integration/editorMode.spec.ts +++ b/cypress/integration/editorMode.spec.ts @@ -4,20 +4,22 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +import { PAGE_MODE } from '../support/visit' + describe('Editor mode from URL parameter is used', () => { it('mode view', () => { - cy.visitTestEditor('view') + cy.visitTestNote(PAGE_MODE.EDITOR, 'view') cy.getByCypressId('splitter-left').should('not.be.visible') cy.getByCypressId('splitter-right').should('be.visible') }) it('mode both', () => { - cy.visitTestEditor('both') + cy.visitTestNote(PAGE_MODE.EDITOR, 'both') cy.getByCypressId('splitter-left').should('be.visible') cy.getByCypressId('splitter-separator').should('exist') cy.getByCypressId('splitter-right').should('be.visible') }) it('mode edit', () => { - cy.visitTestEditor('edit') + cy.visitTestNote(PAGE_MODE.EDITOR, 'edit') cy.getByCypressId('splitter-left').should('be.visible') cy.getByCypressId('splitter-right').should('not.be.visible') }) diff --git a/cypress/integration/emoji.spec.ts b/cypress/integration/emoji.spec.ts index 811cca78a..e087b8b98 100644 --- a/cypress/integration/emoji.spec.ts +++ b/cypress/integration/emoji.spec.ts @@ -8,7 +8,7 @@ describe('emojis', () => { const HEDGEHOG_UNICODE_CHARACTER = '\n🦔\n' beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('renders an emoji shortcode', () => { diff --git a/cypress/integration/export.spec.ts b/cypress/integration/export.spec.ts index 401f49dad..08787e550 100644 --- a/cypress/integration/export.spec.ts +++ b/cypress/integration/export.spec.ts @@ -9,7 +9,7 @@ describe('Export', () => { const testContent = `---\ntitle: ${testTitle}\n---\nThis is some test content` beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() cy.setCodemirrorContent(testContent) }) diff --git a/cypress/integration/fileUpload.spec.ts b/cypress/integration/fileUpload.spec.ts index 167c3c3ff..935099aec 100644 --- a/cypress/integration/fileUpload.spec.ts +++ b/cypress/integration/fileUpload.spec.ts @@ -8,7 +8,7 @@ const imageUrl = 'http://example.com/non-existing.png' describe('File upload', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it("doesn't prevent drag'n'drop of plain text", () => { diff --git a/cypress/integration/helpDialog.spec.ts b/cypress/integration/helpDialog.spec.ts index a7901588b..6bb1e5683 100644 --- a/cypress/integration/helpDialog.spec.ts +++ b/cypress/integration/helpDialog.spec.ts @@ -6,7 +6,7 @@ describe('Help Dialog', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('ToDo-List', () => { diff --git a/cypress/integration/highlightedCodeBlock.spec.ts b/cypress/integration/highlightedCodeBlock.spec.ts index 4006b5995..c160b84ce 100644 --- a/cypress/integration/highlightedCodeBlock.spec.ts +++ b/cypress/integration/highlightedCodeBlock.spec.ts @@ -10,7 +10,7 @@ const findHljsCodeBlock = () => { describe('Code', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) describe('with just the language', () => { diff --git a/cypress/integration/history.spec.ts b/cypress/integration/history.spec.ts index a22389e80..d2b68faeb 100644 --- a/cypress/integration/history.spec.ts +++ b/cypress/integration/history.spec.ts @@ -7,7 +7,7 @@ describe('History', () => { describe('History Mode', () => { beforeEach(() => { - cy.visit('/history') + cy.visitHistory() }) it('Cards', () => { @@ -35,7 +35,7 @@ describe('History', () => { } ] }) - cy.visit('/history') + cy.visitHistory() }) it('in table view', () => { @@ -62,7 +62,7 @@ describe('History', () => { } ] }) - cy.visit('/history') + cy.visitHistory() }) it('in table view', () => { @@ -79,7 +79,7 @@ describe('History', () => { describe('Pinning', () => { beforeEach(() => { - cy.visit('/history') + cy.visitHistory() }) describe('working', () => { @@ -131,7 +131,7 @@ describe('History', () => { cy.intercept('GET', '/mock-backend/api/private/me/history', { body: [] }) - cy.visit('/history') + cy.visitHistory() cy.logout() }) diff --git a/cypress/integration/iframe-capsule.ts b/cypress/integration/iframe-capsule.ts index 1b7e1886b..2000352a2 100644 --- a/cypress/integration/iframe-capsule.ts +++ b/cypress/integration/iframe-capsule.ts @@ -6,7 +6,7 @@ describe('Iframe capsule', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('shows a clickable click shield instead of the iframe', () => { diff --git a/cypress/integration/import.spec.ts b/cypress/integration/import.spec.ts index e48afd2bd..b5dda955e 100644 --- a/cypress/integration/import.spec.ts +++ b/cypress/integration/import.spec.ts @@ -6,7 +6,7 @@ describe('Import markdown file', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('import on blank note', () => { diff --git a/cypress/integration/intro.spec.ts b/cypress/integration/intro.spec.ts index 923208899..e5bb144b8 100644 --- a/cypress/integration/intro.spec.ts +++ b/cypress/integration/intro.spec.ts @@ -8,7 +8,7 @@ describe('Intro page', () => { beforeEach(() => { cy.intercept('/mock-backend/public/intro.md', 'test content') - cy.visit('/') + cy.visitHome() }) describe('customizable content', () => { @@ -20,7 +20,7 @@ describe('Intro page', () => { cy.intercept('/mock-backend/public/intro.md', { statusCode: 404 }) - cy.visit('/') + cy.visitHome() cy.getByCypressId('documentIframe').should('not.exist') }) diff --git a/cypress/integration/language.spec.ts b/cypress/integration/language.spec.ts index 94e6ee8dc..7808a2354 100644 --- a/cypress/integration/language.spec.ts +++ b/cypress/integration/language.spec.ts @@ -8,7 +8,7 @@ import { languages } from '../fixtures/languages' describe('Languages', () => { beforeEach(() => { - cy.visit('/') + cy.visitHome() }) it('all languages are available', () => { diff --git a/cypress/integration/link.spec.ts b/cypress/integration/link.spec.ts index c75fbaf2b..0052b0ab3 100644 --- a/cypress/integration/link.spec.ts +++ b/cypress/integration/link.spec.ts @@ -8,7 +8,7 @@ import '../support/index' describe('Links Intro', () => { beforeEach(() => { - cy.visit('/') + cy.visitHome() }) it('History', () => { diff --git a/cypress/integration/linkEmbedder.spec.ts b/cypress/integration/linkEmbedder.spec.ts index 2ef6f477c..9e0a421b8 100644 --- a/cypress/integration/linkEmbedder.spec.ts +++ b/cypress/integration/linkEmbedder.spec.ts @@ -6,7 +6,7 @@ describe('Link gets replaced with embedding: ', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) // TODO Add general testing of one-click-embedding component. The tests below just test a specific use of the component. diff --git a/cypress/integration/linkSchemes.spec.ts b/cypress/integration/linkSchemes.spec.ts index e98dd7b0b..348502dee 100644 --- a/cypress/integration/linkSchemes.spec.ts +++ b/cypress/integration/linkSchemes.spec.ts @@ -6,7 +6,7 @@ describe('markdown formatted links to', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('external domains render as external link', () => { @@ -41,7 +41,7 @@ describe('markdown formatted links to', () => { describe('HTML anchor element links to', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('external domains render as external link', () => { diff --git a/cypress/integration/maxLength.spec.ts b/cypress/integration/maxLength.spec.ts index 2fe3b0b51..228348be7 100644 --- a/cypress/integration/maxLength.spec.ts +++ b/cypress/integration/maxLength.spec.ts @@ -10,7 +10,7 @@ describe('The status bar text length info', () => { const tooMuchTestContent = `${dangerTestContent}a` beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('shows the maximal length of the document as number of available characters in the tooltip', () => { diff --git a/cypress/integration/motd.spec.ts b/cypress/integration/motd.spec.ts index 686b2c00b..89f62b709 100644 --- a/cypress/integration/motd.spec.ts +++ b/cypress/integration/motd.spec.ts @@ -28,13 +28,13 @@ describe('Motd', () => { it('shows the correct alert Motd text', () => { mockExistingMotd() - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) }) it('can be dismissed using etag', () => { mockExistingMotd(true) - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd-dismiss') .click() @@ -46,7 +46,7 @@ describe('Motd', () => { it('can be dismissed', () => { mockExistingMotd() - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd-dismiss') .click() @@ -58,7 +58,7 @@ describe('Motd', () => { it("won't show again after dismiss and reload", () => { mockExistingMotd() - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd-dismiss') .click() @@ -73,7 +73,7 @@ describe('Motd', () => { it('will show again after reload without dismiss', () => { mockExistingMotd() - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) cy.reload() cy.get('main').should('exist') @@ -82,7 +82,7 @@ describe('Motd', () => { it("won't show again after dismiss and page navigation", () => { mockExistingMotd() - cy.visit('/') + cy.visitHome() cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd-dismiss') .click() @@ -96,7 +96,7 @@ describe('Motd', () => { }) it("won't show if no file exists", () => { - cy.visit('/') + cy.visitHome() cy.get('main').should('exist') cy.getByCypressId('motd').should('not.exist') }) diff --git a/cypress/integration/profile.spec.ts b/cypress/integration/profile.spec.ts index f4aae57e1..bf82a6512 100644 --- a/cypress/integration/profile.spec.ts +++ b/cypress/integration/profile.spec.ts @@ -48,7 +48,7 @@ describe('profile page', () => { body: [] } ) - cy.visit('/profile') + cy.visit('/profile', { retryOnNetworkFailure: true }) }) describe('access tokens', () => { diff --git a/cypress/integration/quote-extra.spec.ts b/cypress/integration/quote-extra.spec.ts index 4a2a80de8..5f0ec2bf6 100644 --- a/cypress/integration/quote-extra.spec.ts +++ b/cypress/integration/quote-extra.spec.ts @@ -6,7 +6,7 @@ describe('Quote extra tags', function () { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) describe('Name quote tag', () => { diff --git a/cypress/integration/renderer-mode.spec.ts b/cypress/integration/renderer-mode.spec.ts index c309ca72c..1141d5e09 100644 --- a/cypress/integration/renderer-mode.spec.ts +++ b/cypress/integration/renderer-mode.spec.ts @@ -6,7 +6,7 @@ describe('Renderer mode', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it("should be 'document' without type specified", () => { diff --git a/cypress/integration/shortcodes.spec.ts b/cypress/integration/shortcodes.spec.ts index dd3dec917..deceaced1 100644 --- a/cypress/integration/shortcodes.spec.ts +++ b/cypress/integration/shortcodes.spec.ts @@ -6,7 +6,7 @@ describe('Short code gets replaced or rendered: ', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) describe('pdf', () => { diff --git a/cypress/integration/signInButton.spec.ts b/cypress/integration/signInButton.spec.ts index 6fdc6e2fe..c82961be8 100644 --- a/cypress/integration/signInButton.spec.ts +++ b/cypress/integration/signInButton.spec.ts @@ -27,13 +27,13 @@ const initLoggedOutTestWithCustomAuthProviders = ( ...enabledProviders } }) - cy.visit('/') + cy.visitHome() cy.logout() } describe('When logged-in, ', () => { it('sign-in button is hidden', () => { - cy.visit('/') + cy.visitHome() cy.getByCypressId('sign-in-button').should('not.exist') }) }) diff --git a/cypress/integration/slideshow-only-page.spec.ts b/cypress/integration/slideshow-only-page.spec.ts index 4edc9f39f..6b5987a4d 100644 --- a/cypress/integration/slideshow-only-page.spec.ts +++ b/cypress/integration/slideshow-only-page.spec.ts @@ -4,9 +4,11 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +import { PAGE_MODE } from '../support/visit' + describe('Slideshow only page', () => { it('renders slide show mode', () => { - cy.visit('/p/test') + cy.visitTestNote(PAGE_MODE.PRESENTATION) cy.getReveal().should('exist') }) }) diff --git a/cypress/integration/splitter.spec.ts b/cypress/integration/splitter.spec.ts index 9dd1c6f7c..ca1f943a6 100644 --- a/cypress/integration/splitter.spec.ts +++ b/cypress/integration/splitter.spec.ts @@ -6,7 +6,7 @@ describe('Split view', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('can show both panes', () => { diff --git a/cypress/integration/taskLists.spec.ts b/cypress/integration/taskLists.spec.ts index 540fbd944..582970637 100644 --- a/cypress/integration/taskLists.spec.ts +++ b/cypress/integration/taskLists.spec.ts @@ -11,7 +11,7 @@ const TEST_STRING_INVALID = '- [Y] abc\n\n* [ ] abc\n\n+ [-] abc\n\n1. [.] abc\ describe('Task lists ', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) describe('render with checkboxes ', () => { diff --git a/cypress/integration/word-count.spec.ts b/cypress/integration/word-count.spec.ts index 584bcd8e1..2fb674da3 100644 --- a/cypress/integration/word-count.spec.ts +++ b/cypress/integration/word-count.spec.ts @@ -6,7 +6,7 @@ describe('Test word count with', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('empty note', () => { diff --git a/cypress/integration/yamlArrayDeprecationMessage.spec.ts b/cypress/integration/yamlArrayDeprecationMessage.spec.ts index 074cff165..0e65fcc56 100644 --- a/cypress/integration/yamlArrayDeprecationMessage.spec.ts +++ b/cypress/integration/yamlArrayDeprecationMessage.spec.ts @@ -6,7 +6,7 @@ describe('YAML Array for deprecated syntax of document tags in frontmatter', () => { beforeEach(() => { - cy.visitTestEditor() + cy.visitTestNote() }) it('is shown when using old syntax', () => { diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 3117d3d49..8cff8b391 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -28,3 +28,4 @@ import './get-by-id' import './get-iframe-content' import './login' import './visit-test-editor' +import './visit' diff --git a/cypress/support/visit-test-editor.ts b/cypress/support/visit-test-editor.ts index 1500258b2..fc21cb13c 100644 --- a/cypress/support/visit-test-editor.ts +++ b/cypress/support/visit-test-editor.ts @@ -4,18 +4,8 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -declare namespace Cypress { - interface Chainable { - visitTestEditor(query?: string): Chainable - } -} - export const testNoteId = 'test' -Cypress.Commands.add('visitTestEditor', (query?: string) => { - return cy.visit(`/n/${testNoteId}${query ? `?${query}` : ''}`) -}) - beforeEach(() => { cy.intercept(`/mock-backend/api/private/notes/${testNoteId}-get`, { content: '', diff --git a/cypress/support/visit.ts b/cypress/support/visit.ts new file mode 100644 index 000000000..1995dd7cb --- /dev/null +++ b/cypress/support/visit.ts @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { testNoteId } from './visit-test-editor' + +declare namespace Cypress { + interface Chainable { + visitTestNote(pageMode?: PAGE_MODE, query?: string): Chainable + + visitHome(): Chainable + + visitHistory(): Chainable + } +} + +Cypress.Commands.add('visitHome', () => { + return cy.visit('/', { retryOnNetworkFailure: true }) +}) + +Cypress.Commands.add('visitHistory', () => { + return cy.visit(`/history`, { retryOnNetworkFailure: true }) +}) + +export enum PAGE_MODE { + EDITOR = 'n', + PRESENTATION = 'p', + DOCUMENT_READ_ONLY = 's' +} + +Cypress.Commands.add('visitTestNote', (pageMode: PAGE_MODE = PAGE_MODE.EDITOR, query?: string) => { + return cy.visit(`/${pageMode}/${testNoteId}${query ? `?${query}` : ''}`, { retryOnNetworkFailure: true }) +})