Skip to content

Commit 6fe0dff

Browse files
committed
fix(cypress): to not chain from actions
Makes the current eslint plugin pass. Signed-off-by: Max <max@nextcloud.com>
1 parent 75f1257 commit 6fe0dff

File tree

12 files changed

+160
-207
lines changed

12 files changed

+160
-207
lines changed

cypress/e2e/attachments.spec.js

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,44 +82,41 @@ const checkAttachment = (documentId, fileName, fileId, index, isImage = true) =>
8282
const src = `.attachments.${documentId}/${encodedName}`
8383

8484
cy.log('Check the attachment is visible and well formed', documentId, fileName, fileId, index, encodedName)
85-
return new Cypress.Promise((resolve, reject) => {
86-
cy.get(`.text-editor__main [data-component="image-view"][data-src="${src}"]`)
87-
.find('.image__view') // wait for load finish
88-
.within(($el) => {
89-
// keep track that we have created this attachment in the attachment dir
90-
if (!attachmentFileNameToId[documentId]) {
91-
attachmentFileNameToId[documentId] = {}
92-
}
93-
94-
attachmentFileNameToId[documentId][fileName] = fileId
95-
96-
if (index > 0) {
97-
expect(fileName).include(`(${index + 1})`)
98-
}
99-
100-
const srcPathEnd = isImage ? 'image' : 'mediaPreview'
101-
const srcFileNameParam = isImage ? 'imageFileName' : 'mediaFileName'
102-
103-
cy.wrap($el)
85+
return cy.get(`.text-editor__main [data-component="image-view"][data-src="${src}"]`)
86+
.find('.image__view') // wait for load finish
87+
.within(($el) => {
88+
// keep track that we have created this attachment in the attachment dir
89+
if (!attachmentFileNameToId[documentId]) {
90+
attachmentFileNameToId[documentId] = {}
91+
}
92+
93+
attachmentFileNameToId[documentId][fileName] = fileId
94+
95+
if (index > 0) {
96+
expect(fileName).include(`(${index + 1})`)
97+
}
98+
99+
const srcPathEnd = isImage ? 'image' : 'mediaPreview'
100+
const srcFileNameParam = isImage ? 'imageFileName' : 'mediaFileName'
101+
102+
cy.wrap($el)
103+
.should('be.visible')
104+
.find('img')
105+
.should('have.attr', 'src')
106+
.should('contain', 'apps/text/' + srcPathEnd + '?documentId=' + documentId)
107+
.should('contain', srcFileNameParam + '=' + encodeURIComponent(fileName))
108+
109+
return isImage
110+
? cy.wrap($el)
111+
.find('.image__caption input')
104112
.should('be.visible')
105-
.find('img')
106-
.should('have.attr', 'src')
107-
.should('contain', 'apps/text/' + srcPathEnd + '?documentId=' + documentId)
108-
.should('contain', srcFileNameParam + '=' + encodeURIComponent(fileName))
109-
110-
return isImage
111-
? cy.wrap($el)
112-
.find('.image__caption input')
113-
.should('be.visible')
114-
.should('have.value', fileName)
115-
: cy.wrap($el)
116-
.find('.metadata .name')
117-
.should('be.visible')
118-
.should('have.text', fileName)
113+
.should('have.value', fileName)
114+
: cy.wrap($el)
115+
.find('.metadata .name')
116+
.should('be.visible')
117+
.should('have.text', fileName)
119118

120-
})
121-
.then(resolve, reject)
122-
})
119+
})
123120
}
124121

125122
/**
@@ -280,10 +277,8 @@ describe('Test all attachment insertion methods', () => {
280277
assertImage(index).then(resolve, reject)
281278
})
282279
})
283-
.then(() => {
284-
return cy.getEditor().find('[data-component="image-view"]')
285-
.should('have.length', 3)
286-
})
280+
return cy.getEditor().find('[data-component="image-view"]')
281+
.should('have.length', 3)
287282
})
288283

289284
it('test if attachment files are in the attachment folder', () => {

cypress/e2e/directediting.spec.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ describe('direct editing', function() {
6262
const closeRequestAlias = 'closeRequest'
6363
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
6464
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
65-
cy.getContent()
66-
.type('# This is a headline')
67-
.type('{enter}')
68-
.type('Some text')
69-
.type('{enter}')
65+
cy.getContent().type('# This is a headline')
66+
cy.getContent().type('{enter}')
67+
cy.getContent().type('Some text')
68+
cy.getContent().type('{enter}')
7069

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

93-
cy.getContent()
94-
.type('# This is a headline')
95-
.type('{enter}')
96-
.type('Some text')
97-
.type('{enter}')
92+
cy.getContent().type('# This is a headline')
93+
cy.getContent().type('{enter}')
94+
cy.getContent().type('Some text')
95+
cy.getContent().type('{enter}')
9896

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

121-
cy.getContent()
122-
.type('# This is a headline')
123-
.type('{enter}')
124-
.type('Some text')
125-
.type('{enter}')
119+
cy.getContent().type('# This is a headline')
120+
cy.getContent().type('{enter}')
121+
cy.getContent().type('Some text')
122+
cy.getContent().type('{enter}')
126123

127124
// ensure we have received our own steps
128125
cy.wait('@sync', { timeout: 7000 })

cypress/e2e/nodes/FrontMatter.spec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ describe('Front matter support', function() {
4343

4444
it('Add front matter', function() {
4545
cy.openFile('empty.md').clearContent().then(() => {
46-
cy.getContent()
47-
.type('---')
48-
.type('test')
46+
cy.getContent().type('---')
47+
cy.getContent().type('test')
4948
cy.getContent().find('pre.frontmatter').should(pre => {
5049
expect(pre.length === 1)
5150
expect(pre[0].text === 'test')
@@ -55,10 +54,9 @@ describe('Front matter support', function() {
5554

5655
it('Do not add multiple front matter', function() {
5756
cy.openFile('empty.md').clearContent().then(() => {
58-
cy.getContent()
59-
.type('---test')
60-
.type('{downArrow}')
61-
.type('---test')
57+
cy.getContent().type('---test')
58+
cy.getContent().type('{downArrow}')
59+
cy.getContent().type('---test')
6260
cy.getContent().find('pre.frontmatter').should(pre => expect(pre.length === 1))
6361
cy.getContent().find('hr').should(hr => expect(hr.length === 1))
6462
})
@@ -68,6 +66,7 @@ describe('Front matter support', function() {
6866
cy.openFile('frontmatter.md')
6967
cy.getContent()
7068
.type('{moveToEnd}New line{enter}')
69+
cy.getContent()
7170
.find('pre.frontmatter').should(pre => {
7271
expect(pre.length === 1)
7372
})

cypress/e2e/nodes/HardBreak.spec.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@ describe('Hard break support', function() {
3838
})
3939

4040
it('Can create hard breaks with shift+enter', () => {
41-
cy.getContent()
42-
.type('Hello')
43-
.type('{shift+enter}world')
41+
cy.getContent().type('Hello')
42+
cy.getContent().type('{shift+enter}world')
4443
cy.getContent()
4544
.find('p br')
4645
.should('exist')
4746
})
4847

4948
it('Convert paragraph break into hard break', () => {
50-
cy.getContent()
51-
.type('Hello')
52-
.type('{enter}')
53-
.type('world')
49+
cy.getContent().type('Hello')
50+
cy.getContent().type('{enter}')
51+
cy.getContent().type('world')
5452
cy.getContent()
5553
.find('p')
5654
.should('have.length', 2)
@@ -66,9 +64,8 @@ describe('Hard break support', function() {
6664
})
6765

6866
it('Do not create hard breaks within headings', () => {
69-
cy.getContent()
70-
.type('# Hello')
71-
.type('{shift+enter}world')
67+
cy.getContent().type('# Hello')
68+
cy.getContent().type('{shift+enter}world')
7269
cy.getContent()
7370
.find('h1 br')
7471
.should('not.exist')

cypress/e2e/nodes/Links.spec.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ describe('test link marks', function() {
2222

2323
describe('link preview', function() {
2424
it('shows a link preview', () => {
25-
cy.getContent()
26-
.type('https://nextcloud.com')
27-
.type('{enter}')
25+
cy.getContent().type('https://nextcloud.com')
26+
cy.getContent().type('{enter}')
2827

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

3534
it('does not show a link preview for links within a paragraph', () => {
36-
cy.getContent()
37-
.type('Please visit https://nextcloud.com')
38-
.type('{enter}')
35+
cy.getContent().type('Please visit https://nextcloud.com')
36+
cy.getContent().type('{enter}')
3937

4038
cy.getContent()
4139
.find('.widgets--list', { timeout: 10000 })
@@ -85,10 +83,9 @@ describe('test link marks', function() {
8583
it('without protocol', () => {
8684
cy.clearContent()
8785
.type('google.com{enter}')
88-
.then(() => cy.getContent()
89-
.find('a[href*="google.com"]')
90-
.should('not.exist')
91-
)
86+
cy.getContent()
87+
.find('a[href*="google.com"]')
88+
.should('not.exist')
9289
})
9390

9491
it('with protocol but without space', () => {

cypress/e2e/nodes/Mentions.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('Test mentioning users', () => {
7474

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

7980
return cy.wait(`@${autocompleteReauestAlias}`)

cypress/e2e/nodes/Table.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ describe('table plugin', () => {
5454
.find('table tr')
5555
.should('have.length', 3)
5656

57-
cy.getContent()
58-
.type('first{Enter}row')
59-
.type('{Enter}{Enter}second row')
60-
.type('{Enter}{Enter}third row')
61-
.type('{Enter}{Enter}forth row')
57+
cy.getContent().type('first{Enter}row')
58+
cy.getContent().type('{Enter}{Enter}second row')
59+
cy.getContent().type('{Enter}{Enter}third row')
60+
cy.getContent().type('{Enter}{Enter}forth row')
6261

6362
// Added a row
6463
cy.getContent()

cypress/e2e/sections.spec.js

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,36 @@ describe('Content Sections', () => {
3636
cy.openFile(fileName, { force: true })
3737
cy.getContent()
3838
.type('# Heading\nText\n## Heading 2\nText\n## Heading 2')
39-
.then(() => {
40-
cy.getContent()
41-
.find('a.heading-anchor')
42-
.should(($anchor) => {
43-
expect($anchor).to.have.length(3)
44-
expect($anchor.eq(0)).to.have.attr('href').and.equal('#h-heading')
45-
expect($anchor.eq(1)).to.have.attr('href').and.equal('#h-heading-2')
46-
expect($anchor.eq(2)).to.have.attr('href').and.equal('#h-heading-2--1')
47-
})
39+
cy.getContent().find('a.heading-anchor')
40+
.should(($anchor) => {
41+
expect($anchor).to.have.length(3)
42+
expect($anchor.eq(0)).to.have.attr('href').and.equal('#h-heading')
43+
expect($anchor.eq(1)).to.have.attr('href').and.equal('#h-heading-2')
44+
expect($anchor.eq(2)).to.have.attr('href').and.equal('#h-heading-2--1')
4845
})
4946
})
5047

5148
it('Anchor ID is updated', () => {
5249
cy.visitTestFolder()
5350
cy.openFile(fileName, { force: true })
51+
cy.getContent().type('# Heading 1{enter}')
5452
cy.getContent()
55-
.type('# Heading 1{enter}')
56-
.then(() => {
57-
cy.getContent()
58-
.find('h1')
59-
.should('have.attr', 'id')
60-
.and('equal', 'h-heading-1')
61-
cy.getContent()
62-
.find('a.heading-anchor')
63-
.should('have.attr', 'href')
64-
.and('equal', '#h-heading-1')
65-
})
66-
cy.then(() => {
67-
cy.getContent()
68-
.type('{backspace}{backspace}2{enter}')
69-
.then(() => {
70-
cy.getContent()
71-
.find('h1')
72-
.should('have.attr', 'id')
73-
.and('equal', 'h-heading-2')
74-
cy.getContent()
75-
.find('a.heading-anchor')
76-
.should('have.attr', 'href')
77-
.and('equal', '#h-heading-2')
78-
})
79-
})
53+
.find('h1')
54+
.should('have.attr', 'id')
55+
.and('equal', 'h-heading-1')
56+
cy.getContent()
57+
.find('a.heading-anchor')
58+
.should('have.attr', 'href')
59+
.and('equal', '#h-heading-1')
60+
cy.getContent().type('{backspace}{backspace}2{enter}')
61+
cy.getContent()
62+
.find('h1')
63+
.should('have.attr', 'id')
64+
.and('equal', 'h-heading-2')
65+
cy.getContent()
66+
.find('a.heading-anchor')
67+
.should('have.attr', 'href')
68+
.and('equal', '#h-heading-2')
8069
})
8170

8271
it('scrolls anchor into view', () => {
@@ -100,27 +89,18 @@ describe('Content Sections', () => {
10089
// Issue #2868
10190
cy.getContent()
10291
.type('# Heading 1{enter}')
103-
.then(() => {
104-
cy.getContent()
105-
.find('h1')
106-
.should('have.attr', 'id')
107-
.and('equal', 'h-heading-1')
108-
})
109-
cy.then(() => {
110-
cy.getContent()
111-
.find('h1 [data-node-view-content]')
112-
.click({ force: true, position: 'center' })
113-
.then(() => {
114-
cy.getActionEntry('headings')
115-
.click()
116-
cy.get('.v-popper__wrapper .open').getActionEntry('headings-h3')
117-
.click()
118-
cy.getContent()
119-
.find('h3')
120-
.should('have.attr', 'id')
121-
.and('equal', 'h-heading-1')
122-
})
123-
})
92+
cy.getContent()
93+
.find('h1')
94+
.should('have.attr', 'id')
95+
.and('equal', 'h-heading-1')
96+
cy.getContent()
97+
.find('h1 [data-node-view-content]')
98+
.click({ force: true, position: 'center' })
99+
cy.getActionEntry('headings').click()
100+
cy.get('.v-popper__wrapper .open').getActionEntry('headings-h3').click()
101+
cy.getContent().find('h3')
102+
.should('have.attr', 'id')
103+
.and('equal', 'h-heading-1')
124104
})
125105
})
126106

@@ -130,7 +110,7 @@ describe('Content Sections', () => {
130110
cy.openFile(fileName, { force: true })
131111
cy.getContent()
132112
.type('# T1 \n## T2 \n### T3 \n#### T4 \n##### T5 \n###### T6\n')
133-
.then(refresh)
113+
cy.then(refresh)
134114
.then(() => cy.openFile(fileName, { force: true }))
135115
.then(clickOutline)
136116

0 commit comments

Comments
 (0)