diff --git a/cypress/e2e/integration.spec.js b/cypress/e2e/integration.spec.js index 489c1edd67..e13aec3f32 100644 --- a/cypress/e2e/integration.spec.js +++ b/cypress/e2e/integration.spec.js @@ -81,22 +81,22 @@ describe('Nextcloud integration', function() { }) - cy.get('.saveas-dialog').should('be.visible') - cy.get('.saveas-dialog input[type=text]') - .should('be.visible') - .should('have.value', `/${exportFilename}`) + cy.get('.saveas-dialog').should('be.visible') + cy.get('.saveas-dialog input[type=text]') + .should('be.visible') + .should('have.value', `/${exportFilename}`) - cy.get('.saveas-dialog button.button-vue--vue-primary').click() + cy.get('.saveas-dialog button.button-vue--vue-primary').click() - cy.get('@loleafletframe').within(() => { - cy.get('#closebutton').click() - cy.waitForViewerClose() - }) + // Wait for confirmation from Collabora that the file was saved + cy.waitForPostMessage('Action_Save_Resp', { success: true, fileName: exportFilename }) - // FIXME: We should not need to reload - cy.get('.breadcrumb__crumbs a').eq(0).click({ force: true }) + cy.get('@loleafletframe').within(() => { + cy.get('#closebutton').click() + cy.waitForViewerClose() + }) - cy.openFile(exportFilename) + cy.openFile(exportFilename) }) it('Open locally', function() { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 8000036a88..84d5f927c0 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -277,18 +277,41 @@ Cypress.Commands.add('waitForCollabora', (wrapped = false, federated = false) => return cy.get('@loleafletframe') }) -Cypress.Commands.add('waitForPostMessage', (messageId, values = undefined) => { +Cypress.Commands.add('waitForPostMessage', (messageId, expectedValues = undefined) => { + const checkExpectedValues = (message, values) => { + for (const [key, value] of Object.entries(values)) { + if (!message.Values[key] || message.Values[key] !== value) { + return false + } + } + + return true + } + cy.get('@postMessage', { timeout: 20000 }).should(spy => { const calls = spy.getCalls() - const findMatchingCall = calls.find(call => call.args[0].indexOf('"MessageId":"' + messageId + '"') !== -1) - if (!findMatchingCall) { - return expect(findMatchingCall).to.not.be.undefined + const messagesMatchingId = [] + + // Find all messages matching the given ID + // We do it this way to avoid the shallow copy of Array.filter() + for (const call of calls) { + if (call.args[0].includes(`"MessageId":"${messageId}"`)) { + messagesMatchingId.push(JSON.parse(call.args[0])) + } } - if (!values) { - const object = JSON.parse(findMatchingCall.args[0]) - values.forEach(value => { - expect(object.Values).to.have.property(value, values[value]) - }) + + expect(messagesMatchingId.length).to.be.greaterThan(0) + + if (expectedValues) { + const messagesMatchingValues = [] + + for (const message of messagesMatchingId) { + if (checkExpectedValues(message, expectedValues)) { + messagesMatchingValues.push(message) + } + } + + expect(messagesMatchingValues.length).to.be.greaterThan(0) } }) }) @@ -404,7 +427,6 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => { break default: expect.fail('Using a field type not yet supported') - break } } }) diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index abf4d95f28..e60b0be3bb 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -11,7 +11,7 @@ import axios from '@nextcloud/axios' import { emit } from '@nextcloud/event-bus' import { getCurrentDirectory } from '../helpers/filesApp.js' import { - getSidebar + getSidebar, } from '@nextcloud/files' import { getClient,