Skip to content

Commit f5e5622

Browse files
authored
Merge pull request #5314 from nextcloud/backport/5312/stable32
[stable32] fix(test): stabilize save as test
2 parents fe42edd + 3301250 commit f5e5622

2 files changed

Lines changed: 44 additions & 22 deletions

File tree

cypress/e2e/integration.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ describe('Nextcloud integration', function() {
8181
})
8282

8383

84-
cy.get('.saveas-dialog').should('be.visible')
85-
cy.get('.saveas-dialog input[type=text]')
86-
.should('be.visible')
87-
.should('have.value', `/${exportFilename}`)
84+
cy.get('.saveas-dialog').should('be.visible')
85+
cy.get('.saveas-dialog input[type=text]')
86+
.should('be.visible')
87+
.should('have.value', `/${exportFilename}`)
8888

89-
cy.get('.saveas-dialog button.button-vue--vue-primary').click()
89+
cy.get('.saveas-dialog button.button-vue--vue-primary').click()
9090

91-
cy.get('@loleafletframe').within(() => {
92-
cy.get('#closebutton').click()
93-
cy.waitForViewerClose()
94-
})
91+
// Wait for confirmation from Collabora that the file was saved
92+
cy.waitForPostMessage('Action_Save_Resp', { success: true, fileName: exportFilename })
9593

96-
// FIXME: We should not need to reload
97-
cy.get('.breadcrumb__crumbs a').eq(0).click({ force: true })
94+
cy.get('@loleafletframe').within(() => {
95+
cy.get('#closebutton').click()
96+
cy.waitForViewerClose()
97+
})
9898

99-
cy.openFile(exportFilename)
99+
cy.openFile(exportFilename)
100100
})
101101

102102
it('Open locally', function() {

cypress/support/commands.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,41 @@ Cypress.Commands.add('waitForCollabora', (wrapped = false, federated = false) =>
277277
return cy.get('@loleafletframe')
278278
})
279279

280-
Cypress.Commands.add('waitForPostMessage', (messageId, values = undefined) => {
280+
Cypress.Commands.add('waitForPostMessage', (messageId, expectedValues = undefined) => {
281+
const checkExpectedValues = (message, values) => {
282+
for (const [key, value] of Object.entries(values)) {
283+
if (!message.Values[key] || message.Values[key] !== value) {
284+
return false
285+
}
286+
}
287+
288+
return true
289+
}
290+
281291
cy.get('@postMessage', { timeout: 20000 }).should(spy => {
282292
const calls = spy.getCalls()
283-
const findMatchingCall = calls.find(call => call.args[0].indexOf('"MessageId":"' + messageId + '"') !== -1)
284-
if (!findMatchingCall) {
285-
return expect(findMatchingCall).to.not.be.undefined
293+
const messagesMatchingId = []
294+
295+
// Find all messages matching the given ID
296+
// We do it this way to avoid the shallow copy of Array.filter()
297+
for (const call of calls) {
298+
if (call.args[0].includes(`"MessageId":"${messageId}"`)) {
299+
messagesMatchingId.push(JSON.parse(call.args[0]))
300+
}
286301
}
287-
if (!values) {
288-
const object = JSON.parse(findMatchingCall.args[0])
289-
values.forEach(value => {
290-
expect(object.Values).to.have.property(value, values[value])
291-
})
302+
303+
expect(messagesMatchingId.length).to.be.greaterThan(0)
304+
305+
if (expectedValues) {
306+
const messagesMatchingValues = []
307+
308+
for (const message of messagesMatchingId) {
309+
if (checkExpectedValues(message, expectedValues)) {
310+
messagesMatchingValues.push(message)
311+
}
312+
}
313+
314+
expect(messagesMatchingValues.length).to.be.greaterThan(0)
292315
}
293316
})
294317
})
@@ -404,7 +427,6 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
404427
break
405428
default:
406429
expect.fail('Using a field type not yet supported')
407-
break
408430
}
409431
}
410432
})

0 commit comments

Comments
 (0)