From 8a0bfb41f19c3d931de97b45d4a2f97481b75ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 26 Oct 2023 15:12:38 +0200 Subject: [PATCH 1/2] Revert "tmp: skip known attachment failures" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 66d5c7dc07330669b0e7fd7a917648584a2d84d2. Signed-off-by: Julius Härtl --- cypress/e2e/attachments.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/attachments.spec.js b/cypress/e2e/attachments.spec.js index 952ac851279..2917763fcc3 100644 --- a/cypress/e2e/attachments.spec.js +++ b/cypress/e2e/attachments.spec.js @@ -336,7 +336,7 @@ describe('Test all attachment insertion methods', () => { }) }) - it.skip('test if attachment folder is copied when copying a markdown file', () => { + it('test if attachment folder is copied when copying a markdown file', () => { cy.copyFile('subFolder/test.md', 'testCopied.md') cy.visit('/apps/files') @@ -358,7 +358,7 @@ describe('Test all attachment insertion methods', () => { }) }) - it.skip('test if attachment folder is deleted after having deleted a markdown file', () => { + it('test if attachment folder is deleted after having deleted a markdown file', () => { cy.copyFile('subFolder/test.md', 'testCopied.md') cy.visit('/apps/files') cy.getFile('testCopied.md') @@ -374,7 +374,7 @@ describe('Test all attachment insertion methods', () => { currentUser = recipient }) - it.skip('[share] check everything behaves correctly on the share target user side', () => { + it('[share] check everything behaves correctly on the share target user side', () => { cy.visit('/apps/files') // check the file list cy.getFile('test.md') From c5ea7355bf0c9f140347414b98f7653db112c01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 30 Nov 2023 14:20:48 +0100 Subject: [PATCH 2/2] ci: More stable attachment tests and use API calls where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- cypress/e2e/attachments.spec.js | 53 ++++++++++++----- cypress/e2e/nodes/ImageView.spec.js | 15 ++--- cypress/support/commands.js | 88 ++++++++++++++++++++++++----- 3 files changed, 119 insertions(+), 37 deletions(-) diff --git a/cypress/e2e/attachments.spec.js b/cypress/e2e/attachments.spec.js index 2917763fcc3..0222f949768 100644 --- a/cypress/e2e/attachments.spec.js +++ b/cypress/e2e/attachments.spec.js @@ -24,7 +24,7 @@ import { initUserAndFiles, randHash, randUser } from '../utils/index.js' const user = randUser() const recipient = randUser() -let currentUser = user +const currentUser = user const attachmentFileNameToId = {} const ACTION_UPLOAD_LOCAL_FILE = 'insert-attachment-upload' @@ -160,7 +160,6 @@ describe('Test all attachment insertion methods', () => { cy.uploadFile('github.png', 'image/png', 'sub/b/b.png') cy.createUser(recipient) - cy.shareFileToUser('test.md', recipient) }) beforeEach(() => { @@ -317,9 +316,16 @@ describe('Test all attachment insertion methods', () => { }) it('test if attachment folder is moved with the markdown file', () => { + const fileName = 'moveSource.md' cy.createFolder('subFolder') + cy.createMarkdown(fileName, '![git](.attachments.123/github.png)', false).then((fileId) => { + const attachmentsFolder = `.attachments.${fileId}` + cy.createFolder(attachmentsFolder) + cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`) + cy.moveFile(fileName, 'subFolder/test.md') + }) + cy.visit('/apps/files') - cy.moveFile('test.md', 'subFolder/test.md') cy.openFolder('subFolder') cy.getFile('test.md') .should('exist') @@ -337,9 +343,16 @@ describe('Test all attachment insertion methods', () => { }) it('test if attachment folder is copied when copying a markdown file', () => { - cy.copyFile('subFolder/test.md', 'testCopied.md') - cy.visit('/apps/files') + const fileName = 'copySource.md' + cy.createMarkdown(fileName, '![git](.attachments.123/github.png)', false).then((fileId) => { + const attachmentsFolder = `.attachments.${fileId}` + cy.createFolder(attachmentsFolder) + cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`) + }) + cy.copyFile(fileName, 'testCopied.md') + + cy.visit('/apps/files') cy.getFile('testCopied.md') .should('exist') .should('have.attr', 'data-cy-files-list-row-fileid') @@ -359,32 +372,46 @@ describe('Test all attachment insertion methods', () => { }) it('test if attachment folder is deleted after having deleted a markdown file', () => { - cy.copyFile('subFolder/test.md', 'testCopied.md') + const fileName = 'deleteSource.md' + cy.createMarkdown(fileName, '![git](.attachments.123/github.png)', false).then((fileId) => { + const attachmentsFolder = `.attachments.${fileId}` + cy.createFolder(attachmentsFolder) + cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`) + }) + cy.visit('/apps/files') - cy.getFile('testCopied.md') + cy.getFile(fileName) .should('exist') .should('have.attr', 'data-cy-files-list-row-fileid') .then((documentId) => { - cy.deleteFile('testCopied.md') + cy.deleteFile(fileName) cy.reloadFileList() cy.getFile('.attachments.' + documentId) .should('not.exist') }) - // change the current user for next tests - currentUser = recipient }) it('[share] check everything behaves correctly on the share target user side', () => { + const fileName = 'testShared.md' + cy.createMarkdown(fileName, '![git](.attachments.123/github.png)', false).then((fileId) => { + const attachmentsFolder = `.attachments.${fileId}` + cy.createFolder(attachmentsFolder) + cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`) + cy.shareFileToUser(fileName, recipient) + }) + + cy.login(recipient) + cy.visit('/apps/files') // check the file list - cy.getFile('test.md') + cy.getFile('testShared.md') .should('exist') cy.getFile('github.png') .should('not.exist') cy.showHiddenFiles() // check the attachment folder is not there - cy.getFile('test.md') + cy.getFile('testShared.md') .should('exist') .should('have.attr', 'data-cy-files-list-row-fileid') .then((documentId) => { @@ -393,7 +420,7 @@ describe('Test all attachment insertion methods', () => { }) // move the file and check the attachment folder is still not there - cy.moveFile('test.md', 'testMoved.md') + cy.moveFile('testShared.md', 'testMoved.md') cy.reloadFileList() cy.getFile('testMoved.md') .should('exist') diff --git a/cypress/e2e/nodes/ImageView.spec.js b/cypress/e2e/nodes/ImageView.spec.js index eb648583639..bb1fe9cf858 100644 --- a/cypress/e2e/nodes/ImageView.spec.js +++ b/cypress/e2e/nodes/ImageView.spec.js @@ -2,11 +2,6 @@ import { randUser } from '../../utils/index.js' const user = randUser() -const createMarkdown = (fileName, content) => { - return cy.createFile(fileName, content, 'text/markdown') - .then(cy.reload) -} - describe('Image View', () => { before(() => { cy.createUser(user) @@ -27,7 +22,7 @@ describe('Image View', () => { it('from root', () => { const fileName = `${Cypress.currentTest.title}.md` - createMarkdown(fileName, '# from root\n\n ![git](/github.png)') + cy.createMarkdown(fileName, '# from root\n\n ![git](/github.png)') cy.openFile(fileName) @@ -45,7 +40,7 @@ describe('Image View', () => { it('from child folder', () => { const fileName = `${Cypress.currentTest.title}.md` - createMarkdown(fileName, '# from child\n\n ![git](child-folder/github.png)') + cy.createMarkdown(fileName, '# from child\n\n ![git](child-folder/github.png)') cy.openFile(fileName) @@ -65,7 +60,7 @@ describe('Image View', () => { const fileName = `${Cypress.currentTest.title}.md` - createMarkdown(`/child-folder/${fileName}`, '# from parent\n\n ![git](../github.png)') + cy.createMarkdown(`/child-folder/${fileName}`, '# from parent\n\n ![git](../github.png)') cy.openFile(fileName, { force: true }) @@ -85,7 +80,7 @@ describe('Image View', () => { it('direct access', () => { const fileName = `${Cypress.currentTest.title}.md` - createMarkdown(fileName, '# from root\n\n ![yaha](/yaha.png)') + cy.createMarkdown(fileName, '# from root\n\n ![yaha](/yaha.png)') cy.openFile(fileName) @@ -112,7 +107,7 @@ describe('Image View', () => { cy.login(user) cy.visit('/apps/files') const fileName = 'native attachments.md' - createMarkdown(fileName, '# open image in modal\n\n ![git](.attachments.123/github.png)\n\n ![file.txt.gz](.attachments.123/file.txt.gz)') + cy.createMarkdown(fileName, '# open image in modal\n\n ![git](.attachments.123/github.png)\n\n ![file.txt.gz](.attachments.123/file.txt.gz)') cy.getFileId(fileName).then((fileId) => { const attachmentsFolder = `.attachments.${fileId}` diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 55b1043a0a5..9fe05ea79a6 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -155,11 +155,25 @@ Cypress.Commands.add('createFile', (target, content, mimeType = 'text/markdown', ...headers, }, }).then((response) => { - return cy.log(`Uploaded ${target}`, response.status) + cy.log(`Uploaded ${target}`, response.status) + const fileId = Number( + response.headers['oc-fileid']?.split('oc')?.[0], + ) + return cy.wrap(fileId) }) }) }) +Cypress.Commands.add('createMarkdown', (fileName, content, reload = true) => { + return cy.createFile(fileName, content, 'text/markdown') + .then((fileId) => { + if (reload) { + cy.reloadFileList() + } + return cy.wrap(fileId) + }) +}) + Cypress.Commands.add('shareFileToUser', (path, targetUser, shareData = {}) => { cy.ocsRequest({ method: 'POST', @@ -266,17 +280,53 @@ Cypress.Commands.add('createFolder', (target) => { }) }) -Cypress.Commands.add('moveFile', (path, destinationPath) => cy.window() - .then(win => win.OC.Files.getClient().move(path, destinationPath)), -) +Cypress.Commands.add('moveFile', (path, destinationPath) => { + return cy.getRequestToken() + .then(requesttoken => { + return cy.request({ + method: 'MOVE', + url: `${url}/remote.php/webdav/${path}`, + auth, + headers: { + requesttoken, + Destination: `${url}/remote.php/webdav/${destinationPath}`, + }, + }).then(response => { + cy.wrap(response.body) + }) + }) +}) -Cypress.Commands.add('removeFile', (path) => cy.window() - .then(win => win.OC.Files.getClient().remove(path)), -) +Cypress.Commands.add('removeFile', (path) => { + return cy.getRequestToken() + .then(requesttoken => { + return cy.request({ + url: `${url}/remote.php/webdav/${path}`, + method: 'DELETE', + auth, + headers: { + requesttoken, + }, + }) + }) +}) -Cypress.Commands.add('copyFile', (path, destinationPath) => cy.window() - .then(win => win.OC.Files.getClient().copy(path, destinationPath)), -) +Cypress.Commands.add('copyFile', (path, destinationPath) => { + return cy.getRequestToken() + .then(requesttoken => { + return cy.request({ + method: 'COPY', + url: `${url}/remote.php/webdav/${path}`, + auth, + headers: { + requesttoken, + Destination: `${url}/remote.php/webdav/${destinationPath}`, + }, + }).then(response => { + cy.wrap(response.body) + }) + }) +}) Cypress.Commands.add('getFileContent', (path) => { return cy.request({ @@ -315,7 +365,7 @@ Cypress.Commands.add('propfindFolder', (path, depth = 0) => { }) Cypress.Commands.add('reloadFileList', () => { - return cy.reload() + return cy.get('.vue-crumb:last-child a').click() }) Cypress.Commands.add('openFolder', (name) => { @@ -355,9 +405,19 @@ Cypress.Commands.add('getFile', fileName => { }) Cypress.Commands.add('deleteFile', fileName => { - cy.get(`[data-cy-files-list] tr[data-cy-files-list-row-name="${fileName}"] .files-list__row-actions .action-item__menutoggle`).click() - cy.get('.files-list__row-action-delete:visible button').click() - cy.get(`[data-cy-files-list] tr[data-cy-files-list-row-name="${fileName}"]`).should('not.exist') + return cy.getRequestToken() + .then(requesttoken => { + return cy.request({ + method: 'DELETE', + url: `${url}/remote.php/webdav/${fileName}`, + auth, + headers: { + requesttoken, + }, + }).then(response => { + cy.wrap(response.body) + }) + }) }) Cypress.Commands.add('getModal', () => {