Skip to content

Commit f5a4b12

Browse files
committed
cleanup: wait statements - rely on promises instead
If a command returns a promise cypress will wait for that promise before proceeding with the next commands. Since 0162bb0 we return the promises from most commands. The explicit calls to cy.intercept and cy.wait are not needed anymore. Signed-off-by: Max <max@nextcloud.com>
1 parent cfb4903 commit f5a4b12

File tree

2 files changed

+24
-64
lines changed

2 files changed

+24
-64
lines changed

cypress/e2e/images.spec.js

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,7 @@ describe('Test all image insertion methods', () => {
151151
.should('contain', 'test.md')
152152
cy.get('#fileList tr[data-file="github.png"]', { timeout: 10000 })
153153
.should('contain', 'github.png')
154-
155-
cy.get('#app-settings-header', { timeout: 10000 })
156-
.click()
157-
cy.intercept({ method: 'POST', url: '**/showhidden' }).as('showHidden')
158-
cy.get('#app-settings-content label[for=showhiddenfilesToggle]', { timeout: 10000 })
159-
.click()
160-
cy.wait('@showHidden')
154+
cy.showHiddenFiles()
161155
})
162156

163157
it('Insert an image from files', () => {
@@ -234,9 +228,7 @@ describe('Test all image insertion methods', () => {
234228
const files = attachmentFileNameToId[documentId]
235229

236230
cy.expect(Object.keys(files)).to.have.lengthOf(2)
237-
cy.intercept({ method: 'PROPFIND', url: '**/.attachments.' + documentId }).as('chdir')
238-
cy.openFile('.attachments.' + documentId)
239-
cy.wait('@chdir')
231+
cy.openFolder('.attachments.' + documentId)
240232
cy.screenshot()
241233
for (const name in files) {
242234
cy.get(`#fileList tr[data-file="${name}"]`, { timeout: 10000 })
@@ -248,29 +240,16 @@ describe('Test all image insertion methods', () => {
248240
})
249241

250242
it('test if attachment folder is moved with the markdown file', () => {
251-
cy.intercept({ method: 'MKCOL', url: '**/subFolder' }).as('mkdir')
252243
cy.createFolder('subFolder')
253-
cy.wait('@mkdir')
254-
255-
cy.intercept({ method: 'PROPFIND', url: '**/' }).as('reload')
256244
cy.reloadFileList()
257-
cy.wait('@reload')
258-
259-
cy.intercept({ method: 'MOVE', url: '**/test.md' }).as('move')
260245
cy.moveFile('test.md', 'subFolder/test.md')
261-
cy.wait('@move')
262-
cy.intercept({ method: 'PROPFIND', url: '**/subFolder' }).as('chdir')
263-
cy.openFile('subFolder')
264-
cy.wait('@chdir')
265-
246+
cy.openFolder('subFolder')
266247
cy.get('#fileList tr[data-file="test.md"]', { timeout: 10000 })
267248
.should('exist')
268249
.should('have.attr', 'data-id')
269250
.then((documentId) => {
270251
const files = attachmentFileNameToId[documentId]
271-
cy.intercept({ method: 'PROPFIND', url: '**/.attachments.' + documentId }).as('chdir')
272-
cy.openFile('.attachments.' + documentId)
273-
cy.wait('@chdir')
252+
cy.openFolder('.attachments.' + documentId)
274253
cy.screenshot()
275254
for (const name in files) {
276255
cy.get(`#fileList tr[data-file="${name}"]`, { timeout: 10000 })
@@ -282,22 +261,16 @@ describe('Test all image insertion methods', () => {
282261
})
283262

284263
it('test if attachment folder is copied when copying a markdown file', () => {
285-
cy.intercept({ method: 'COPY', url: '**/subFolder/test.md' }).as('copyFile')
286264
cy.copyFile('subFolder/test.md', 'testCopied.md')
287-
cy.wait('@copyFile')
288-
cy.intercept({ method: 'PROPFIND', url: '**/' }).as('reload2')
289265
cy.reloadFileList()
290-
cy.wait('@reload2')
291266

292267
cy.get('#fileList tr[data-file="testCopied.md"]', { timeout: 10000 })
293268
.should('exist')
294269
.should('have.attr', 'data-id')
295270
.then((documentId) => {
296271
const files = attachmentFileNameToId[documentId]
297272

298-
cy.intercept({ method: 'PROPFIND', url: '**/.attachments.' + documentId }).as('chdir')
299-
cy.openFile('.attachments.' + documentId)
300-
cy.wait('@chdir')
273+
cy.openFolder('.attachments.' + documentId)
301274
cy.screenshot()
302275
for (const name in files) {
303276
cy.get(`#fileList tr[data-file="${name}"]`, { timeout: 10000 })
@@ -315,15 +288,8 @@ describe('Test all image insertion methods', () => {
315288
.should('exist')
316289
.should('have.attr', 'data-id')
317290
.then((documentId) => {
318-
cy.intercept({ method: 'DELETE', url: '**/testCopied.md' }).as('deleteFile')
319291
cy.deleteFile('testCopied.md')
320-
cy.wait('@deleteFile')
321-
322-
cy.intercept({ method: 'PROPFIND', url: '**/' }).as('reload3')
323292
cy.reloadFileList()
324-
cy.wait('@reload3')
325-
326-
// cy.wait(2000)
327293
cy.get(`#fileList tr[data-file=".attachments.${documentId}"]`, { timeout: 10000 })
328294
.should('not.exist')
329295
})
@@ -336,14 +302,7 @@ describe('Test all image insertion methods', () => {
336302
cy.get('#fileList tr[data-file="test.md"]', { timeout: 10000 })
337303
.should('contain', 'test.md')
338304
cy.get('#fileList tr[data-file="github.png"]').should('not.exist')
339-
340-
// show hidden files
341-
cy.get('#app-settings-header', { timeout: 10000 })
342-
.click()
343-
cy.intercept({ method: 'POST', url: '**/showhidden' }).as('showHidden')
344-
cy.get('#app-settings-content label[for=showhiddenfilesToggle]', { timeout: 10000 })
345-
.click()
346-
cy.wait('@showHidden')
305+
cy.showHiddenFiles()
347306

348307
// check the attachment folder is not there
349308
cy.get('#fileList tr[data-file="test.md"]', { timeout: 10000 })
@@ -355,14 +314,8 @@ describe('Test all image insertion methods', () => {
355314
})
356315

357316
// move the file and check the attachment folder is still not there
358-
cy.intercept({ method: 'MOVE', url: '**/test.md' }).as('move')
359317
cy.moveFile('test.md', 'testMoved.md')
360-
cy.wait('@move')
361-
362-
cy.intercept({ method: 'PROPFIND', url: '**/' }).as('reload')
363318
cy.reloadFileList()
364-
cy.wait('@reload')
365-
366319
cy.get('#fileList tr[data-file="testMoved.md"]', { timeout: 10000 })
367320
.should('exist')
368321
.should('have.attr', 'data-id')
@@ -372,22 +325,14 @@ describe('Test all image insertion methods', () => {
372325
})
373326

374327
// copy the file and check the attachment folder was copied
375-
cy.intercept({ method: 'COPY', url: '**/testMoved.md' }).as('copyFile')
376328
cy.copyFile('testMoved.md', 'testCopied.md')
377-
cy.wait('@copyFile')
378-
cy.intercept({ method: 'PROPFIND', url: '**/' }).as('reload2')
379329
cy.reloadFileList()
380-
cy.wait('@reload2')
381-
382330
cy.get('#fileList tr[data-file="testCopied.md"]', { timeout: 10000 })
383331
.should('exist')
384332
.should('have.attr', 'data-id')
385333
.then((documentId) => {
386334
const files = attachmentFileNameToId[documentId]
387-
388-
cy.intercept({ method: 'PROPFIND', url: '**/.attachments.' + documentId }).as('chdir')
389-
cy.openFile('.attachments.' + documentId)
390-
cy.wait('@chdir')
335+
cy.openFolder('.attachments.' + documentId)
391336
cy.screenshot()
392337
for (const name in files) {
393338
cy.get(`#fileList tr[data-file="${name}"]`, { timeout: 10000 })

cypress/support/commands.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,16 @@ Cypress.Commands.add('reloadFileList', () => cy.window()
208208
.then(win => win.OCA?.Files?.App?.fileList?.reload())
209209
)
210210

211+
Cypress.Commands.add('openFolder', (name) => {
212+
const url = `**/${encodeURI(name)}`
213+
cy.intercept({ method: 'PROPFIND', url })
214+
.as(`open-${name}`)
215+
cy.openFile(name)
216+
cy.wait(`@open-${name}`)
217+
})
218+
211219
Cypress.Commands.add('openFile', (fileName, params = {}) => {
212220
cy.get(`#fileList tr[data-file="${fileName}"] a.name`).click(params)
213-
// eslint-disable-next-line cypress/no-unnecessary-waiting
214-
cy.wait(250)
215221
})
216222

217223
Cypress.Commands.add('getFile', fileName => {
@@ -263,3 +269,12 @@ Cypress.Commands.add('configureText', (key, value) => {
263269
)
264270
})
265271
})
272+
273+
Cypress.Commands.add('showHiddenFiles', () => {
274+
cy.get('#app-settings-header')
275+
.click()
276+
cy.intercept({ method: 'POST', url: '**/showhidden' }).as('showHidden')
277+
cy.get('#app-settings-content label[for=showhiddenfilesToggle]')
278+
.click()
279+
cy.wait('@showHidden')
280+
})

0 commit comments

Comments
 (0)