Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(cy): introduce insertLine command
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 2, 2024
commit 49a8dfe8fc8197feda0e0807f709a2d5b6d7ac0a
6 changes: 2 additions & 4 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ function enterContentAndClose() {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')
cy.insertLine('# This is a headline')
cy.insertLine('Some text')
cy.getContent().type('{ctrl+s}')
cy.wait('@push')
cy.wait('@sync')
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/nodes/CodeBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('Front matter support', function() {
cy.isolateTest({ sourceFile: 'codeblock.md' })
cy.openFile('codeblock.md').then(() => {
cy.clearContent()
cy.getContent().type('{enter}```javascript{enter}')
cy.insertLine('```javascript')
cy.getContent().type('const foo = "bar"{enter}{enter}{enter}')
cy.getContent().find('.hljs-keyword').first().contains('const')
})
Expand All @@ -108,7 +108,7 @@ describe('Front matter support', function() {
it('Add an invalid mermaid block', function() {
cy.isolateTest()
cy.openFile('empty.md').then(() => {
cy.getContent().type('```mermaid{enter}')
cy.insertLine('```mermaid')
cy.getContent().find('code').should('exist')
cy.getContent().get('.split-view__preview').should('be.visible')
// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand All @@ -123,7 +123,7 @@ describe('Front matter support', function() {
it('Add a valid mermaid block', function() {
cy.isolateTest()
cy.openFile('empty.md').then(() => {
cy.getContent().type('```mermaid{enter}')
cy.insertLine('```mermaid')
cy.getContent().find('code').should('exist')
cy.getContent().get('.split-view__preview').should('be.visible')
// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand Down
31 changes: 11 additions & 20 deletions cypress/e2e/nodes/Links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { initUserAndFiles, randUser } from '../../utils/index.js'
import { randUser } from '../../utils/index.js'

const user = randUser()
const fileName = 'empty.md'

describe('test link marks', function() {
before(function() {
initUserAndFiles(user)
cy.createUser(user)
})

beforeEach(function() {
Expand All @@ -28,8 +28,7 @@ describe('test link marks', function() {
describe('link bubble', function() {
it('shows a link preview in the bubble after clicking link', () => {
const link = 'https://nextcloud.com/'
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)

cy.getContent()
.find(`a[href*="${link}"]`)
Expand All @@ -43,8 +42,7 @@ describe('test link marks', function() {

it('shows a link preview in the bubble after browsing to link', () => {
const link = 'https://nextcloud.com/'
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)
cy.getContent()
.find(`a[href*="${link}"]`)

Expand All @@ -58,8 +56,7 @@ describe('test link marks', function() {

it('closes the link bubble when clicking elsewhere', () => {
const link = 'https://nextcloud.com/'
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)
cy.getContent()
.find(`a[href*="${link}"]`)
cy.getContent()
Expand All @@ -75,8 +72,7 @@ describe('test link marks', function() {
})

it('allows to edit a link in the bubble', () => {
cy.getContent()
.type('https://example.org{enter}')
cy.insertLine('https://example.org')
cy.getContent()
.type('{upArrow}{rightArrow}')

Expand All @@ -96,8 +92,7 @@ describe('test link marks', function() {

it('allows to remove a link in the bubble', () => {
const link = 'https://nextcloud.com'
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)
cy.getContent()
.type('{upArrow}{rightArrow}')

Expand All @@ -112,8 +107,7 @@ describe('test link marks', function() {

it('Ctrl-click on a link opens a new tab', () => {
const link = 'https://nextcloud.com/'
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)

cy.getContent()
.find(`a[href*="${link}"]`)
Expand All @@ -133,8 +127,7 @@ describe('test link marks', function() {

const link = `${Cypress.env('baseUrl')}/apps/files/?dir=/&openfile=${id}#relPath=/${fileName}`
cy.clearContent()
cy.getContent()
.type(`${link}{enter}`)
cy.insertLine(link)

cy.getContent()
.find(`a[href*="${Cypress.env('baseUrl')}"]`)
Expand All @@ -143,16 +136,14 @@ describe('test link marks', function() {

it('without protocol', () => {
cy.clearContent()
cy.getContent()
.type('google.com{enter}')
cy.insertLine('google.com')
cy.getContent()
.find('a[href*="google.com"]')
.should('not.exist')
})

it('with protocol but without space', () => {
cy.getContent()
.type('https://nextcloud.com')
cy.getContent().type('https://nextcloud.com')

cy.getContent()
.find('a[href*="nextcloud.com"]')
Expand Down
5 changes: 2 additions & 3 deletions cypress/e2e/sections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Content Sections', () => {
it('Anchor ID is updated', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent().type('# Heading 1{enter}')
cy.insertLine('# Heading 1')
cy.getContent()
.find('h1 > a')
.should('have.attr', 'id')
Expand Down Expand Up @@ -89,8 +89,7 @@ describe('Content Sections', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
// Issue #2868
cy.getContent()
.type('# Heading 1{enter}')
cy.insertLine('# Heading 1')
cy.getContent()
.find('h1 > a')
.should('have.attr', 'id')
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Sync', () => {
cy.openTestFile()
cy.wait('@sync', { timeout: 10000 })
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().type('{moveToEnd}* Saving the doc saves the doc state{enter}')
cy.insertLine('{moveToEnd}* Saving the doc saves the doc state')
cy.wait('@sync', { timeout: 10000 })
})

Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Sync', () => {
.should('not.contain', 'Document could not be loaded.')
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.getContent().type('* more content added after the lost connection{enter}')
cy.insertLine('* more content added after the lost connection')
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.closeFile()
cy.testName()
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('Sync', () => {
.should('not.contain', 'Document could not be loaded.')
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.getContent().type('* more content added after the lost connection{enter}')
cy.insertLine('* more content added after the lost connection')
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.closeFile()
cy.testName()
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/viewer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ describe('Open test.md in viewer', function() {
// This used to break with the focus trap that the viewer modal has
cy.openFile('empty.md')

cy.getContent()
.type('- test{enter}')
cy.insertLine('- test')

// Cypress does not have native tab key support, though this seems to work
// for triggering the key handler of tiptap
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ Cypress.Commands.add('clearContent', () => {
cy.getContent()
})

Cypress.Commands.add('insertLine', (line = '') => {
cy.getContent()
.type(`${line}{enter}`)
})

Cypress.Commands.add('openWorkspace', () => {
cy.createDescription()
cy.get('#rich-workspace .editor__content').click({ force: true })
Expand Down