Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Revert "tmp: skip known attachment failures" #5067

Merged
merged 2 commits into from Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 43 additions & 16 deletions cypress/e2e/attachments.spec.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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')
Expand All @@ -336,10 +342,17 @@ describe('Test all attachment insertion methods', () => {
})
})

it.skip('test if attachment folder is copied when copying a markdown file', () => {
cy.copyFile('subFolder/test.md', 'testCopied.md')
cy.visit('/apps/files')
it('test if attachment folder is copied when copying a markdown file', () => {
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')
Expand All @@ -358,33 +371,47 @@ describe('Test all attachment insertion methods', () => {
})
})

it.skip('test if attachment folder is deleted after having deleted a markdown file', () => {
cy.copyFile('subFolder/test.md', 'testCopied.md')
it('test if attachment folder is deleted after having deleted a markdown file', () => {
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.skip('[share] check everything behaves correctly on the share target user side', () => {
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) => {
Expand All @@ -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')
Expand Down
15 changes: 5 additions & 10 deletions cypress/e2e/nodes/ImageView.spec.js
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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 })

Expand All @@ -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)

Expand All @@ -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}`
Expand Down
88 changes: 74 additions & 14 deletions cypress/support/commands.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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', () => {
Expand Down