Skip to content

Commit

Permalink
fix(cypress): to not chain from actions
Browse files Browse the repository at this point in the history
Makes the current eslint plugin pass.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Apr 28, 2023
1 parent 75f1257 commit 6fe0dff
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 207 deletions.
75 changes: 35 additions & 40 deletions cypress/e2e/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,44 +82,41 @@ const checkAttachment = (documentId, fileName, fileId, index, isImage = true) =>
const src = `.attachments.${documentId}/${encodedName}`

cy.log('Check the attachment is visible and well formed', documentId, fileName, fileId, index, encodedName)
return new Cypress.Promise((resolve, reject) => {
cy.get(`.text-editor__main [data-component="image-view"][data-src="${src}"]`)
.find('.image__view') // wait for load finish
.within(($el) => {
// keep track that we have created this attachment in the attachment dir
if (!attachmentFileNameToId[documentId]) {
attachmentFileNameToId[documentId] = {}
}

attachmentFileNameToId[documentId][fileName] = fileId

if (index > 0) {
expect(fileName).include(`(${index + 1})`)
}

const srcPathEnd = isImage ? 'image' : 'mediaPreview'
const srcFileNameParam = isImage ? 'imageFileName' : 'mediaFileName'

cy.wrap($el)
return cy.get(`.text-editor__main [data-component="image-view"][data-src="${src}"]`)
.find('.image__view') // wait for load finish
.within(($el) => {
// keep track that we have created this attachment in the attachment dir
if (!attachmentFileNameToId[documentId]) {
attachmentFileNameToId[documentId] = {}
}

attachmentFileNameToId[documentId][fileName] = fileId

if (index > 0) {
expect(fileName).include(`(${index + 1})`)
}

const srcPathEnd = isImage ? 'image' : 'mediaPreview'
const srcFileNameParam = isImage ? 'imageFileName' : 'mediaFileName'

cy.wrap($el)
.should('be.visible')
.find('img')
.should('have.attr', 'src')
.should('contain', 'apps/text/' + srcPathEnd + '?documentId=' + documentId)
.should('contain', srcFileNameParam + '=' + encodeURIComponent(fileName))

return isImage
? cy.wrap($el)
.find('.image__caption input')
.should('be.visible')
.find('img')
.should('have.attr', 'src')
.should('contain', 'apps/text/' + srcPathEnd + '?documentId=' + documentId)
.should('contain', srcFileNameParam + '=' + encodeURIComponent(fileName))

return isImage
? cy.wrap($el)
.find('.image__caption input')
.should('be.visible')
.should('have.value', fileName)
: cy.wrap($el)
.find('.metadata .name')
.should('be.visible')
.should('have.text', fileName)
.should('have.value', fileName)
: cy.wrap($el)
.find('.metadata .name')
.should('be.visible')
.should('have.text', fileName)

})
.then(resolve, reject)
})
})
}

/**
Expand Down Expand Up @@ -280,10 +277,8 @@ describe('Test all attachment insertion methods', () => {
assertImage(index).then(resolve, reject)
})
})
.then(() => {
return cy.getEditor().find('[data-component="image-view"]')
.should('have.length', 3)
})
return cy.getEditor().find('[data-component="image-view"]')
.should('have.length', 3)
})

it('test if attachment files are in the attachment folder', () => {
Expand Down
27 changes: 12 additions & 15 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ describe('direct editing', function() {
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
Expand All @@ -90,11 +89,10 @@ describe('direct editing', function() {
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
Expand All @@ -118,11 +116,10 @@ describe('direct editing', function() {
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
Expand Down
13 changes: 6 additions & 7 deletions cypress/e2e/nodes/FrontMatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ describe('Front matter support', function() {

it('Add front matter', function() {
cy.openFile('empty.md').clearContent().then(() => {
cy.getContent()
.type('---')
.type('test')
cy.getContent().type('---')
cy.getContent().type('test')
cy.getContent().find('pre.frontmatter').should(pre => {
expect(pre.length === 1)
expect(pre[0].text === 'test')
Expand All @@ -55,10 +54,9 @@ describe('Front matter support', function() {

it('Do not add multiple front matter', function() {
cy.openFile('empty.md').clearContent().then(() => {
cy.getContent()
.type('---test')
.type('{downArrow}')
.type('---test')
cy.getContent().type('---test')
cy.getContent().type('{downArrow}')
cy.getContent().type('---test')
cy.getContent().find('pre.frontmatter').should(pre => expect(pre.length === 1))
cy.getContent().find('hr').should(hr => expect(hr.length === 1))
})
Expand All @@ -68,6 +66,7 @@ describe('Front matter support', function() {
cy.openFile('frontmatter.md')
cy.getContent()
.type('{moveToEnd}New line{enter}')
cy.getContent()
.find('pre.frontmatter').should(pre => {
expect(pre.length === 1)
})
Expand Down
17 changes: 7 additions & 10 deletions cypress/e2e/nodes/HardBreak.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@ describe('Hard break support', function() {
})

it('Can create hard breaks with shift+enter', () => {
cy.getContent()
.type('Hello')
.type('{shift+enter}world')
cy.getContent().type('Hello')
cy.getContent().type('{shift+enter}world')
cy.getContent()
.find('p br')
.should('exist')
})

it('Convert paragraph break into hard break', () => {
cy.getContent()
.type('Hello')
.type('{enter}')
.type('world')
cy.getContent().type('Hello')
cy.getContent().type('{enter}')
cy.getContent().type('world')
cy.getContent()
.find('p')
.should('have.length', 2)
Expand All @@ -66,9 +64,8 @@ describe('Hard break support', function() {
})

it('Do not create hard breaks within headings', () => {
cy.getContent()
.type('# Hello')
.type('{shift+enter}world')
cy.getContent().type('# Hello')
cy.getContent().type('{shift+enter}world')
cy.getContent()
.find('h1 br')
.should('not.exist')
Expand Down
17 changes: 7 additions & 10 deletions cypress/e2e/nodes/Links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ describe('test link marks', function() {

describe('link preview', function() {
it('shows a link preview', () => {
cy.getContent()
.type('https://nextcloud.com')
.type('{enter}')
cy.getContent().type('https://nextcloud.com')
cy.getContent().type('{enter}')

cy.getContent()
.find('.widgets--list', { timeout: 10000 })
Expand All @@ -33,9 +32,8 @@ describe('test link marks', function() {
})

it('does not show a link preview for links within a paragraph', () => {
cy.getContent()
.type('Please visit https://nextcloud.com')
.type('{enter}')
cy.getContent().type('Please visit https://nextcloud.com')
cy.getContent().type('{enter}')

cy.getContent()
.find('.widgets--list', { timeout: 10000 })
Expand Down Expand Up @@ -85,10 +83,9 @@ describe('test link marks', function() {
it('without protocol', () => {
cy.clearContent()
.type('google.com{enter}')
.then(() => cy.getContent()
.find('a[href*="google.com"]')
.should('not.exist')
)
cy.getContent()
.find('a[href*="google.com"]')
.should('not.exist')
})

it('with protocol but without space', () => {
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/nodes/Mentions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('Test mentioning users', () => {

cy.get('.text-editor__content div[contenteditable="true"]')
.clear()
cy.get('.text-editor__content div[contenteditable="true"]')
.type(`@${mention.substring(0, 3)}`)

return cy.wait(`@${autocompleteReauestAlias}`)
Expand Down
9 changes: 4 additions & 5 deletions cypress/e2e/nodes/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ describe('table plugin', () => {
.find('table tr')
.should('have.length', 3)

cy.getContent()
.type('first{Enter}row')
.type('{Enter}{Enter}second row')
.type('{Enter}{Enter}third row')
.type('{Enter}{Enter}forth row')
cy.getContent().type('first{Enter}row')
cy.getContent().type('{Enter}{Enter}second row')
cy.getContent().type('{Enter}{Enter}third row')
cy.getContent().type('{Enter}{Enter}forth row')

// Added a row
cy.getContent()
Expand Down
92 changes: 36 additions & 56 deletions cypress/e2e/sections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,36 @@ describe('Content Sections', () => {
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# Heading\nText\n## Heading 2\nText\n## Heading 2')
.then(() => {
cy.getContent()
.find('a.heading-anchor')
.should(($anchor) => {
expect($anchor).to.have.length(3)
expect($anchor.eq(0)).to.have.attr('href').and.equal('#h-heading')
expect($anchor.eq(1)).to.have.attr('href').and.equal('#h-heading-2')
expect($anchor.eq(2)).to.have.attr('href').and.equal('#h-heading-2--1')
})
cy.getContent().find('a.heading-anchor')
.should(($anchor) => {
expect($anchor).to.have.length(3)
expect($anchor.eq(0)).to.have.attr('href').and.equal('#h-heading')
expect($anchor.eq(1)).to.have.attr('href').and.equal('#h-heading-2')
expect($anchor.eq(2)).to.have.attr('href').and.equal('#h-heading-2--1')
})
})

it('Anchor ID is updated', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent().type('# Heading 1{enter}')
cy.getContent()
.type('# Heading 1{enter}')
.then(() => {
cy.getContent()
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-1')
})
cy.then(() => {
cy.getContent()
.type('{backspace}{backspace}2{enter}')
.then(() => {
cy.getContent()
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-2')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-2')
})
})
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-1')
cy.getContent().type('{backspace}{backspace}2{enter}')
cy.getContent()
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-2')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-2')
})

it('scrolls anchor into view', () => {
Expand All @@ -100,27 +89,18 @@ describe('Content Sections', () => {
// Issue #2868
cy.getContent()
.type('# Heading 1{enter}')
.then(() => {
cy.getContent()
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
})
cy.then(() => {
cy.getContent()
.find('h1 [data-node-view-content]')
.click({ force: true, position: 'center' })
.then(() => {
cy.getActionEntry('headings')
.click()
cy.get('.v-popper__wrapper .open').getActionEntry('headings-h3')
.click()
cy.getContent()
.find('h3')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
})
})
cy.getContent()
.find('h1')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
cy.getContent()
.find('h1 [data-node-view-content]')
.click({ force: true, position: 'center' })
cy.getActionEntry('headings').click()
cy.get('.v-popper__wrapper .open').getActionEntry('headings-h3').click()
cy.getContent().find('h3')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
})
})

Expand All @@ -130,7 +110,7 @@ describe('Content Sections', () => {
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# T1 \n## T2 \n### T3 \n#### T4 \n##### T5 \n###### T6\n')
.then(refresh)
cy.then(refresh)
.then(() => cy.openFile(fileName, { force: true }))
.then(clickOutline)

Expand Down
Loading

0 comments on commit 6fe0dff

Please sign in to comment.