Add new visit functions in e2e tests

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-01-30 21:46:43 +01:00
parent 566b3009b6
commit ca5dae3f82
34 changed files with 88 additions and 56 deletions

View file

@ -6,7 +6,7 @@
describe('Autocompletion works for', () => { describe('Autocompletion works for', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
cy.get('.CodeMirror').click().get('textarea').as('codeinput') cy.get('.CodeMirror').click().get('textarea').as('codeinput')
}) })

View file

@ -6,7 +6,7 @@
describe('Delete note', () => { describe('Delete note', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('correctly deletes a note', () => { it('correctly deletes a note', () => {

View file

@ -6,7 +6,7 @@
describe('Diagram codeblock ', () => { describe('Diagram codeblock ', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
/* /*

View file

@ -4,9 +4,11 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { PAGE_MODE } from '../support/visit'
describe('Document read only page', () => { describe('Document read only page', () => {
it('renders the document mode', () => { it('renders the document mode', () => {
cy.visit('/s/test') cy.visitTestNote(PAGE_MODE.DOCUMENT_READ_ONLY)
cy.getMarkdownBody().should('exist') cy.getMarkdownBody().should('exist')
}) })
}) })

View file

@ -9,7 +9,7 @@ import { branding } from '../support/config'
const title = 'This is a test title' const title = 'This is a test title'
describe('Document Title', () => { describe('Document Title', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
cy.getByCypressId('view-mode-both').should('exist') cy.getByCypressId('view-mode-both').should('exist')
}) })

View file

@ -4,20 +4,22 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { PAGE_MODE } from '../support/visit'
describe('Editor mode from URL parameter is used', () => { describe('Editor mode from URL parameter is used', () => {
it('mode view', () => { it('mode view', () => {
cy.visitTestEditor('view') cy.visitTestNote(PAGE_MODE.EDITOR, 'view')
cy.getByCypressId('splitter-left').should('not.be.visible') cy.getByCypressId('splitter-left').should('not.be.visible')
cy.getByCypressId('splitter-right').should('be.visible') cy.getByCypressId('splitter-right').should('be.visible')
}) })
it('mode both', () => { it('mode both', () => {
cy.visitTestEditor('both') cy.visitTestNote(PAGE_MODE.EDITOR, 'both')
cy.getByCypressId('splitter-left').should('be.visible') cy.getByCypressId('splitter-left').should('be.visible')
cy.getByCypressId('splitter-separator').should('exist') cy.getByCypressId('splitter-separator').should('exist')
cy.getByCypressId('splitter-right').should('be.visible') cy.getByCypressId('splitter-right').should('be.visible')
}) })
it('mode edit', () => { it('mode edit', () => {
cy.visitTestEditor('edit') cy.visitTestNote(PAGE_MODE.EDITOR, 'edit')
cy.getByCypressId('splitter-left').should('be.visible') cy.getByCypressId('splitter-left').should('be.visible')
cy.getByCypressId('splitter-right').should('not.be.visible') cy.getByCypressId('splitter-right').should('not.be.visible')
}) })

View file

@ -8,7 +8,7 @@ describe('emojis', () => {
const HEDGEHOG_UNICODE_CHARACTER = '\n🦔\n' const HEDGEHOG_UNICODE_CHARACTER = '\n🦔\n'
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('renders an emoji shortcode', () => { it('renders an emoji shortcode', () => {

View file

@ -9,7 +9,7 @@ describe('Export', () => {
const testContent = `---\ntitle: ${testTitle}\n---\nThis is some test content` const testContent = `---\ntitle: ${testTitle}\n---\nThis is some test content`
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
cy.setCodemirrorContent(testContent) cy.setCodemirrorContent(testContent)
}) })

View file

@ -8,7 +8,7 @@ const imageUrl = 'http://example.com/non-existing.png'
describe('File upload', () => { describe('File upload', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it("doesn't prevent drag'n'drop of plain text", () => { it("doesn't prevent drag'n'drop of plain text", () => {

View file

@ -6,7 +6,7 @@
describe('Help Dialog', () => { describe('Help Dialog', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('ToDo-List', () => { it('ToDo-List', () => {

View file

@ -10,7 +10,7 @@ const findHljsCodeBlock = () => {
describe('Code', () => { describe('Code', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
describe('with just the language', () => { describe('with just the language', () => {

View file

@ -7,7 +7,7 @@
describe('History', () => { describe('History', () => {
describe('History Mode', () => { describe('History Mode', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/history') cy.visitHistory()
}) })
it('Cards', () => { it('Cards', () => {
@ -35,7 +35,7 @@ describe('History', () => {
} }
] ]
}) })
cy.visit('/history') cy.visitHistory()
}) })
it('in table view', () => { it('in table view', () => {
@ -62,7 +62,7 @@ describe('History', () => {
} }
] ]
}) })
cy.visit('/history') cy.visitHistory()
}) })
it('in table view', () => { it('in table view', () => {
@ -79,7 +79,7 @@ describe('History', () => {
describe('Pinning', () => { describe('Pinning', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/history') cy.visitHistory()
}) })
describe('working', () => { describe('working', () => {
@ -131,7 +131,7 @@ describe('History', () => {
cy.intercept('GET', '/mock-backend/api/private/me/history', { cy.intercept('GET', '/mock-backend/api/private/me/history', {
body: [] body: []
}) })
cy.visit('/history') cy.visitHistory()
cy.logout() cy.logout()
}) })

View file

@ -6,7 +6,7 @@
describe('Iframe capsule', () => { describe('Iframe capsule', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('shows a clickable click shield instead of the iframe', () => { it('shows a clickable click shield instead of the iframe', () => {

View file

@ -6,7 +6,7 @@
describe('Import markdown file', () => { describe('Import markdown file', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('import on blank note', () => { it('import on blank note', () => {

View file

@ -8,7 +8,7 @@
describe('Intro page', () => { describe('Intro page', () => {
beforeEach(() => { beforeEach(() => {
cy.intercept('/mock-backend/public/intro.md', 'test content') cy.intercept('/mock-backend/public/intro.md', 'test content')
cy.visit('/') cy.visitHome()
}) })
describe('customizable content', () => { describe('customizable content', () => {
@ -20,7 +20,7 @@ describe('Intro page', () => {
cy.intercept('/mock-backend/public/intro.md', { cy.intercept('/mock-backend/public/intro.md', {
statusCode: 404 statusCode: 404
}) })
cy.visit('/') cy.visitHome()
cy.getByCypressId('documentIframe').should('not.exist') cy.getByCypressId('documentIframe').should('not.exist')
}) })

View file

@ -8,7 +8,7 @@ import { languages } from '../fixtures/languages'
describe('Languages', () => { describe('Languages', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/') cy.visitHome()
}) })
it('all languages are available', () => { it('all languages are available', () => {

View file

@ -8,7 +8,7 @@ import '../support/index'
describe('Links Intro', () => { describe('Links Intro', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/') cy.visitHome()
}) })
it('History', () => { it('History', () => {

View file

@ -6,7 +6,7 @@
describe('Link gets replaced with embedding: ', () => { describe('Link gets replaced with embedding: ', () => {
beforeEach(() => { 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. // TODO Add general testing of one-click-embedding component. The tests below just test a specific use of the component.

View file

@ -6,7 +6,7 @@
describe('markdown formatted links to', () => { describe('markdown formatted links to', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('external domains render as external link', () => { it('external domains render as external link', () => {
@ -41,7 +41,7 @@ describe('markdown formatted links to', () => {
describe('HTML anchor element links to', () => { describe('HTML anchor element links to', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('external domains render as external link', () => { it('external domains render as external link', () => {

View file

@ -10,7 +10,7 @@ describe('The status bar text length info', () => {
const tooMuchTestContent = `${dangerTestContent}a` const tooMuchTestContent = `${dangerTestContent}a`
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('shows the maximal length of the document as number of available characters in the tooltip', () => { it('shows the maximal length of the document as number of available characters in the tooltip', () => {

View file

@ -28,13 +28,13 @@ describe('Motd', () => {
it('shows the correct alert Motd text', () => { it('shows the correct alert Motd text', () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
}) })
it('can be dismissed using etag', () => { it('can be dismissed using etag', () => {
mockExistingMotd(true) mockExistingMotd(true)
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd-dismiss') cy.getByCypressId('motd-dismiss')
.click() .click()
@ -46,7 +46,7 @@ describe('Motd', () => {
it('can be dismissed', () => { it('can be dismissed', () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd-dismiss') cy.getByCypressId('motd-dismiss')
.click() .click()
@ -58,7 +58,7 @@ describe('Motd', () => {
it("won't show again after dismiss and reload", () => { it("won't show again after dismiss and reload", () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd-dismiss') cy.getByCypressId('motd-dismiss')
.click() .click()
@ -73,7 +73,7 @@ describe('Motd', () => {
it('will show again after reload without dismiss', () => { it('will show again after reload without dismiss', () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
cy.reload() cy.reload()
cy.get('main').should('exist') cy.get('main').should('exist')
@ -82,7 +82,7 @@ describe('Motd', () => {
it("won't show again after dismiss and page navigation", () => { it("won't show again after dismiss and page navigation", () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd-dismiss') cy.getByCypressId('motd-dismiss')
.click() .click()
@ -96,7 +96,7 @@ describe('Motd', () => {
}) })
it("won't show if no file exists", () => { it("won't show if no file exists", () => {
cy.visit('/') cy.visitHome()
cy.get('main').should('exist') cy.get('main').should('exist')
cy.getByCypressId('motd').should('not.exist') cy.getByCypressId('motd').should('not.exist')
}) })

View file

@ -48,7 +48,7 @@ describe('profile page', () => {
body: [] body: []
} }
) )
cy.visit('/profile') cy.visit('/profile', { retryOnNetworkFailure: true })
}) })
describe('access tokens', () => { describe('access tokens', () => {

View file

@ -6,7 +6,7 @@
describe('Quote extra tags', function () { describe('Quote extra tags', function () {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
describe('Name quote tag', () => { describe('Name quote tag', () => {

View file

@ -6,7 +6,7 @@
describe('Renderer mode', () => { describe('Renderer mode', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it("should be 'document' without type specified", () => { it("should be 'document' without type specified", () => {

View file

@ -6,7 +6,7 @@
describe('Short code gets replaced or rendered: ', () => { describe('Short code gets replaced or rendered: ', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
describe('pdf', () => { describe('pdf', () => {

View file

@ -27,13 +27,13 @@ const initLoggedOutTestWithCustomAuthProviders = (
...enabledProviders ...enabledProviders
} }
}) })
cy.visit('/') cy.visitHome()
cy.logout() cy.logout()
} }
describe('When logged-in, ', () => { describe('When logged-in, ', () => {
it('sign-in button is hidden', () => { it('sign-in button is hidden', () => {
cy.visit('/') cy.visitHome()
cy.getByCypressId('sign-in-button').should('not.exist') cy.getByCypressId('sign-in-button').should('not.exist')
}) })
}) })

View file

@ -4,9 +4,11 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { PAGE_MODE } from '../support/visit'
describe('Slideshow only page', () => { describe('Slideshow only page', () => {
it('renders slide show mode', () => { it('renders slide show mode', () => {
cy.visit('/p/test') cy.visitTestNote(PAGE_MODE.PRESENTATION)
cy.getReveal().should('exist') cy.getReveal().should('exist')
}) })
}) })

View file

@ -6,7 +6,7 @@
describe('Split view', () => { describe('Split view', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('can show both panes', () => { it('can show both panes', () => {

View file

@ -11,7 +11,7 @@ const TEST_STRING_INVALID = '- [Y] abc\n\n* [ ] abc\n\n+ [-] abc\n\n1. [.] abc\
describe('Task lists ', () => { describe('Task lists ', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
describe('render with checkboxes ', () => { describe('render with checkboxes ', () => {

View file

@ -6,7 +6,7 @@
describe('Test word count with', () => { describe('Test word count with', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('empty note', () => { it('empty note', () => {

View file

@ -6,7 +6,7 @@
describe('YAML Array for deprecated syntax of document tags in frontmatter', () => { describe('YAML Array for deprecated syntax of document tags in frontmatter', () => {
beforeEach(() => { beforeEach(() => {
cy.visitTestEditor() cy.visitTestNote()
}) })
it('is shown when using old syntax', () => { it('is shown when using old syntax', () => {

View file

@ -28,3 +28,4 @@ import './get-by-id'
import './get-iframe-content' import './get-iframe-content'
import './login' import './login'
import './visit-test-editor' import './visit-test-editor'
import './visit'

View file

@ -4,18 +4,8 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
declare namespace Cypress {
interface Chainable {
visitTestEditor(query?: string): Chainable<Cypress.AUTWindow>
}
}
export const testNoteId = 'test' export const testNoteId = 'test'
Cypress.Commands.add('visitTestEditor', (query?: string) => {
return cy.visit(`/n/${testNoteId}${query ? `?${query}` : ''}`)
})
beforeEach(() => { beforeEach(() => {
cy.intercept(`/mock-backend/api/private/notes/${testNoteId}-get`, { cy.intercept(`/mock-backend/api/private/notes/${testNoteId}-get`, {
content: '', content: '',

35
cypress/support/visit.ts Normal file
View file

@ -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<Cypress.AUTWindow>
visitHome(): Chainable<Cypress.AUTWindow>
visitHistory(): Chainable<Cypress.AUTWindow>
}
}
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 })
})