mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
test: adjust cypress tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
3726596ad0
commit
fd96a32dda
10 changed files with 188 additions and 312 deletions
|
|
@ -25,9 +25,9 @@ export default defineConfig({
|
|||
viewportWidth: 1280,
|
||||
viewportHeight: 720,
|
||||
|
||||
// Tries again 2 more times on failure
|
||||
// Tries again when in run mode (cypress run) e.g. on CI
|
||||
retries: {
|
||||
runMode: 2,
|
||||
runMode: 3,
|
||||
// do not retry in `cypress open`
|
||||
openMode: 0,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ export const getActionButtonForFile = (filename: string) => getActionsForFile(fi
|
|||
export function getActionEntryForFileId(fileid: number, actionId: string) {
|
||||
return getActionButtonForFileId(fileid)
|
||||
.should('have.attr', 'aria-controls')
|
||||
.then((menuId) => cy.get(`#${menuId}`).find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`))
|
||||
.then((menuId) => cy.get(`#${menuId}`)
|
||||
.should('exist')
|
||||
.find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,10 +35,11 @@ export function getActionEntryForFileId(fileid: number, actionId: string) {
|
|||
* @param actionId
|
||||
*/
|
||||
export function getActionEntryForFile(file: string, actionId: string) {
|
||||
getActionButtonForFile(file)
|
||||
return getActionButtonForFile(file)
|
||||
.should('have.attr', 'aria-controls')
|
||||
return cy.findByRole('menu')
|
||||
.find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`)
|
||||
.then((menuId) => cy.get(`#${menuId}`)
|
||||
.should('exist')
|
||||
.find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,9 +69,8 @@ export function getInlineActionEntryForFile(file: string, actionId: string) {
|
|||
*/
|
||||
export function triggerActionForFileId(fileid: number, actionId: string) {
|
||||
getActionButtonForFileId(fileid)
|
||||
.as('actionButton')
|
||||
.scrollIntoView()
|
||||
cy.get('@actionButton')
|
||||
getActionButtonForFileId(fileid)
|
||||
.click({ force: true }) // force to avoid issues with overlaying file list header
|
||||
getActionEntryForFileId(fileid, actionId)
|
||||
.find('button')
|
||||
|
|
@ -83,9 +85,8 @@ export function triggerActionForFileId(fileid: number, actionId: string) {
|
|||
*/
|
||||
export function triggerActionForFile(filename: string, actionId: string) {
|
||||
getActionButtonForFile(filename)
|
||||
.as('actionButton')
|
||||
.scrollIntoView()
|
||||
cy.get('@actionButton')
|
||||
getActionButtonForFile(filename)
|
||||
.click({ force: true }) // force to avoid issues with overlaying file list header
|
||||
getActionEntryForFile(filename, actionId)
|
||||
.find('button')
|
||||
|
|
@ -286,8 +287,19 @@ export function navigateToFolder(dirPath: string) {
|
|||
*/
|
||||
export function closeSidebar() {
|
||||
// {force: true} as it might be hidden behind toasts
|
||||
cy.get('[data-cy-sidebar] .app-sidebar__close').click({ force: true })
|
||||
cy.get('[data-cy-sidebar]').should('not.be.visible')
|
||||
cy.get('[data-cy-sidebar] .app-sidebar__close')
|
||||
.click({ force: true })
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.should('not.be.visible')
|
||||
// eslint-disable-next-line cypress/no-unnecessary-waiting -- wait for the animation to finish
|
||||
cy.wait(500)
|
||||
cy.url()
|
||||
.should('not.contain', 'opendetails')
|
||||
// close all toasts
|
||||
cy.get('.toast-success')
|
||||
.if()
|
||||
.findAllByRole('button')
|
||||
.click({ force: true, multiple: true })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -113,6 +113,10 @@ describe('files: Favorites', { testIsolation: true }, () => {
|
|||
cy.intercept('POST', '**/apps/files/api/v1/files/new%20folder').as('addToFavorites')
|
||||
// open sidebar
|
||||
triggerActionForFile('new folder', 'details')
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.should('be.visible')
|
||||
|
||||
// open sidebar actions
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.findByRole('button', { name: 'Actions' })
|
||||
.click()
|
||||
|
|
@ -121,8 +125,9 @@ describe('files: Favorites', { testIsolation: true }, () => {
|
|||
.findByRole('menuitem', { name: 'Favorite' })
|
||||
.should('be.visible')
|
||||
.click()
|
||||
|
||||
cy.wait('@addToFavorites')
|
||||
|
||||
// close sidebar
|
||||
closeSidebar()
|
||||
|
||||
// See favorites star
|
||||
|
|
@ -131,9 +136,14 @@ describe('files: Favorites', { testIsolation: true }, () => {
|
|||
.should('be.visible')
|
||||
|
||||
cy.reload()
|
||||
getRowForFile('new folder')
|
||||
.should('be.visible')
|
||||
|
||||
// can unfavorite
|
||||
triggerActionForFile('new folder', 'details')
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.should('be.visible')
|
||||
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.findByRole('button', { name: 'Actions' })
|
||||
.click()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { triggerActionForFile } from '../files/FilesUtils.ts'
|
||||
import { closeSidebar, triggerActionForFile } from '../files/FilesUtils.ts'
|
||||
|
||||
export interface ShareSetting {
|
||||
read: boolean
|
||||
|
|
@ -18,6 +18,7 @@ export interface ShareSetting {
|
|||
|
||||
export function createShare(fileName: string, username: string, shareSettings: Partial<ShareSetting> = {}) {
|
||||
openSharingPanel(fileName)
|
||||
cy.intercept('POST', '**/ocs/v2.php/apps/files_sharing/api/v1/shares').as('createShare')
|
||||
|
||||
cy.get('#app-sidebar-vue').within(() => {
|
||||
cy.intercept({ times: 1, method: 'GET', url: '**/apps/files_sharing/api/v1/sharees?*' }).as('userSearch')
|
||||
|
|
@ -30,6 +31,9 @@ export function createShare(fileName: string, username: string, shareSettings: P
|
|||
|
||||
// HACK: Save the share and then update it, as permissions changes are currently not saved for new share.
|
||||
cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' })
|
||||
cy.wait('@createShare')
|
||||
closeSidebar()
|
||||
|
||||
updateShare(fileName, 0, shareSettings)
|
||||
}
|
||||
|
||||
|
|
@ -55,10 +59,16 @@ export function updateShare(fileName: string, index: number, shareSettings: Part
|
|||
cy.get('[data-cy-files-sharing-share-permissions-checkbox="download"]').find('input').as('downloadCheckbox')
|
||||
if (shareSettings.download) {
|
||||
// Force:true because the checkbox is hidden by the pretty UI.
|
||||
cy.get('@downloadCheckbox').check({ force: true, scrollBehavior: 'nearest' })
|
||||
cy.get('@downloadCheckbox')
|
||||
.check({ force: true, scrollBehavior: 'nearest' })
|
||||
cy.get('@downloadCheckbox')
|
||||
.should('be.checked')
|
||||
} else {
|
||||
// Force:true because the checkbox is hidden by the pretty UI.
|
||||
cy.get('@downloadCheckbox').uncheck({ force: true, scrollBehavior: 'nearest' })
|
||||
cy.get('@downloadCheckbox')
|
||||
.uncheck({ force: true, scrollBehavior: 'nearest' })
|
||||
cy.get('@downloadCheckbox')
|
||||
.should('not.be.checked')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,14 +132,16 @@ export function updateShare(fileName: string, index: number, shareSettings: Part
|
|||
|
||||
cy.wait('@updateShare')
|
||||
})
|
||||
// close all toasts
|
||||
cy.get('.toast-success').findAllByRole('button').click({ force: true, multiple: true })
|
||||
closeSidebar()
|
||||
}
|
||||
|
||||
export function openSharingPanel(fileName: string) {
|
||||
triggerActionForFile(fileName, 'details')
|
||||
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.as('sidebar')
|
||||
.should('be.visible')
|
||||
cy.get('@sidebar')
|
||||
.find('[aria-controls="tab-sharing"]')
|
||||
.click()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ describe('Limit to sharing to people in the same group', () => {
|
|||
cy.createRandomUser()
|
||||
.then((user) => {
|
||||
alice = user
|
||||
cy.createRandomUser()
|
||||
})
|
||||
cy.createRandomUser()
|
||||
.then((user) => {
|
||||
bob = user
|
||||
|
||||
|
|
@ -49,9 +49,12 @@ describe('Limit to sharing to people in the same group', () => {
|
|||
cy.login(alice)
|
||||
cy.visit('/apps/files')
|
||||
createShare(randomFileName1, bob.userId)
|
||||
cy.logout()
|
||||
|
||||
cy.login(bob)
|
||||
cy.visit('/apps/files')
|
||||
createShare(randomFileName2, alice.userId)
|
||||
cy.logout()
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ export function openVersionsPanel(fileName: string) {
|
|||
|
||||
triggerActionForFile(basename(fileName), 'details')
|
||||
cy.get('[data-cy-sidebar]')
|
||||
.as('sidebar')
|
||||
.should('be.visible')
|
||||
cy.get('@sidebar')
|
||||
.find('[aria-controls="tab-files_versions"]')
|
||||
.click()
|
||||
|
||||
|
|
@ -86,7 +89,6 @@ export function setupTestSharedFileFromUser(owner: User, randomFileName: string,
|
|||
cy.login(owner)
|
||||
cy.visit('/apps/files')
|
||||
createShare(randomFileName, recipient.userId, shareOptions)
|
||||
cy.logout()
|
||||
|
||||
cy.login(recipient)
|
||||
cy.visit('/apps/files')
|
||||
|
|
|
|||
|
|
@ -6,95 +6,56 @@
|
|||
import type { User } from '@nextcloud/e2e-test-server/cypress'
|
||||
|
||||
import { randomString } from '../../support/utils/randomString.ts'
|
||||
import { getRowForFile, navigateToFolder } from '../files/FilesUtils.ts'
|
||||
import { navigateToFolder } from '../files/FilesUtils.ts'
|
||||
import { deleteVersion, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils.ts'
|
||||
|
||||
describe('Versions restoration', () => {
|
||||
describe('Versions deletion', () => {
|
||||
const folderName = 'shared_folder'
|
||||
const randomFileName = randomString(10) + '.txt'
|
||||
const randomFilePath = `/${folderName}/${randomFileName}`
|
||||
let user: User
|
||||
let versionCount = 0
|
||||
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
cy.createRandomUser()
|
||||
.then((_user) => {
|
||||
user = _user
|
||||
cy.mkdir(user, `/${folderName}`)
|
||||
uploadThreeVersions(user, randomFilePath)
|
||||
uploadThreeVersions(user, randomFilePath)
|
||||
versionCount = 6
|
||||
versionCount = 3
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
})
|
||||
})
|
||||
|
||||
it('Delete initial version', () => {
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.should('have.length', versionCount)
|
||||
deleteVersion(--versionCount)
|
||||
cy.get('[data-files-versions-version]')
|
||||
.should('have.length', versionCount)
|
||||
})
|
||||
|
||||
it('Delete versions of shared file with delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, folderName, { delete: true })
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
|
||||
cy.get('[data-files-versions-version]').should('have.length', versionCount)
|
||||
deleteVersion(2)
|
||||
versionCount--
|
||||
deleteVersion(--versionCount)
|
||||
cy.get('[data-files-versions-version]').should('have.length', versionCount)
|
||||
})
|
||||
|
||||
context('Delete versions of shared file', () => {
|
||||
it('Works with delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, folderName, { delete: true })
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
it('Delete versions of shared file without delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, folderName, { delete: false })
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
|
||||
cy.get('[data-files-versions-version]').should('have.length', versionCount)
|
||||
deleteVersion(2)
|
||||
versionCount--
|
||||
cy.get('[data-files-versions-version]').should('have.length', versionCount)
|
||||
})
|
||||
|
||||
it('Does not work without delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, folderName, { delete: false })
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
|
||||
doesNotHaveAction(0, 'delete')
|
||||
doesNotHaveAction(1, 'delete')
|
||||
doesNotHaveAction(2, 'delete')
|
||||
})
|
||||
|
||||
it('Does not work without delete permission through direct API access', () => {
|
||||
let fileId: string | undefined
|
||||
let versionId: string | undefined
|
||||
|
||||
setupTestSharedFileFromUser(user, folderName, { delete: false })
|
||||
.then((recipient) => {
|
||||
navigateToFolder(folderName)
|
||||
openVersionsPanel(randomFilePath)
|
||||
|
||||
getRowForFile(randomFileName)
|
||||
.should('be.visible')
|
||||
.invoke('attr', 'data-cy-files-list-row-fileid')
|
||||
.then(($fileId) => { fileId = $fileId })
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.eq(1)
|
||||
.invoke('attr', 'data-files-versions-version')
|
||||
.then(($versionId) => { versionId = $versionId })
|
||||
|
||||
cy.logout()
|
||||
cy.then(() => {
|
||||
const base = Cypress.config('baseUrl')!.replace(/\/index\.php\/?$/, '')
|
||||
return cy.request({
|
||||
method: 'DELETE',
|
||||
url: `${base}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
|
||||
auth: { user: recipient.userId, pass: recipient.password },
|
||||
headers: {
|
||||
cookie: '',
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
})
|
||||
}).then(({ status }) => {
|
||||
expect(status).to.equal(403)
|
||||
})
|
||||
})
|
||||
})
|
||||
doesNotHaveAction(0, 'delete')
|
||||
doesNotHaveAction(1, 'delete')
|
||||
doesNotHaveAction(2, 'delete')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,91 +6,54 @@
|
|||
import type { User } from '@nextcloud/e2e-test-server/cypress'
|
||||
|
||||
import { randomString } from '../../support/utils/randomString.ts'
|
||||
import { getRowForFile } from '../files/FilesUtils.ts'
|
||||
import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils.ts'
|
||||
|
||||
describe('Versions download', () => {
|
||||
let randomFileName = ''
|
||||
let user: User
|
||||
|
||||
before(() => {
|
||||
randomFileName = randomString(10) + '.txt'
|
||||
|
||||
cy.runOccCommand('config:app:set --value no core shareapi_allow_view_without_download')
|
||||
cy.createRandomUser()
|
||||
.then((_user) => {
|
||||
user = _user
|
||||
uploadThreeVersions(user, randomFileName)
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
openVersionsPanel(randomFileName)
|
||||
})
|
||||
})
|
||||
|
||||
before(() => cy.runOccCommand('config:app:set --value no core shareapi_allow_view_without_download'))
|
||||
after(() => {
|
||||
cy.runOccCommand('config:app:delete core shareapi_allow_view_without_download')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
randomFileName = randomString(10) + '.txt'
|
||||
|
||||
cy.createRandomUser()
|
||||
.then((_user) => {
|
||||
user = _user
|
||||
uploadThreeVersions(user, randomFileName)
|
||||
})
|
||||
})
|
||||
|
||||
it('Download versions and assert their content', () => {
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
assertVersionContent(0, 'v3')
|
||||
assertVersionContent(1, 'v2')
|
||||
assertVersionContent(2, 'v1')
|
||||
})
|
||||
|
||||
context('Download versions of shared file', () => {
|
||||
it('Works with download permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { download: true })
|
||||
openVersionsPanel(randomFileName)
|
||||
it('Download versions of shared file with download permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { download: true })
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
assertVersionContent(0, 'v3')
|
||||
assertVersionContent(1, 'v2')
|
||||
assertVersionContent(2, 'v1')
|
||||
})
|
||||
assertVersionContent(0, 'v3')
|
||||
assertVersionContent(1, 'v2')
|
||||
assertVersionContent(2, 'v1')
|
||||
})
|
||||
|
||||
it('Does not show action without download permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { download: false })
|
||||
openVersionsPanel(randomFileName)
|
||||
it('Does not show action without download permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { download: false })
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="download"]').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="download"]').should('not.exist')
|
||||
|
||||
doesNotHaveAction(1, 'download')
|
||||
doesNotHaveAction(2, 'download')
|
||||
})
|
||||
|
||||
it('Does not work without download permission through direct API access', () => {
|
||||
let fileId: string | undefined
|
||||
let versionId: string | undefined
|
||||
|
||||
setupTestSharedFileFromUser(user, randomFileName, { download: false })
|
||||
.then((recipient) => {
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
getRowForFile(randomFileName)
|
||||
.should('be.visible')
|
||||
.invoke('attr', 'data-cy-files-list-row-fileid')
|
||||
.then(($fileId) => { fileId = $fileId })
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.eq(1)
|
||||
.invoke('attr', 'data-files-versions-version')
|
||||
.then(($versionId) => { versionId = $versionId })
|
||||
|
||||
cy.logout()
|
||||
cy.then(() => {
|
||||
const base = Cypress.config('baseUrl')!.replace(/\/index\.php\/?$/, '')
|
||||
return cy.request({
|
||||
url: `${base}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
|
||||
auth: { user: recipient.userId, pass: recipient.password },
|
||||
headers: {
|
||||
cookie: '',
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
})
|
||||
}).then(({ status }) => {
|
||||
expect(status).to.equal(403)
|
||||
})
|
||||
})
|
||||
})
|
||||
doesNotHaveAction(1, 'download')
|
||||
doesNotHaveAction(2, 'download')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,27 +6,30 @@
|
|||
import type { User } from '@nextcloud/e2e-test-server/cypress'
|
||||
|
||||
import { randomString } from '../../support/utils/randomString.ts'
|
||||
import { getRowForFile } from '../files/FilesUtils.ts'
|
||||
import { navigateToFolder } from '../files/FilesUtils.ts'
|
||||
import { doesNotHaveAction, nameVersion, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils.ts'
|
||||
|
||||
describe('Versions naming', () => {
|
||||
let randomFileName = ''
|
||||
let user: User
|
||||
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
randomFileName = randomString(10) + '.txt'
|
||||
|
||||
cy.createRandomUser()
|
||||
.then((_user) => {
|
||||
user = _user
|
||||
uploadThreeVersions(user, randomFileName)
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
openVersionsPanel(randomFileName)
|
||||
cy.mkdir(_user, '/share')
|
||||
uploadThreeVersions(user, `share/${randomFileName}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('Names the versions', () => {
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
nameVersion(2, 'v1')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('v1')
|
||||
|
|
@ -44,92 +47,45 @@ describe('Versions naming', () => {
|
|||
})
|
||||
})
|
||||
|
||||
context('Name versions of shared file', () => {
|
||||
context('with edit permission', () => {
|
||||
before(() => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { update: true })
|
||||
openVersionsPanel(randomFileName)
|
||||
})
|
||||
it('Name versions of shared file with edit permission', () => {
|
||||
setupTestSharedFileFromUser(user, 'share', { update: true })
|
||||
|
||||
it('Names the versions', () => {
|
||||
nameVersion(2, 'v1 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('v1 - shared')
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
|
||||
})
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
nameVersion(1, 'v2 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(1).contains('v2 - shared')
|
||||
})
|
||||
|
||||
nameVersion(0, 'v3 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(0).contains('v3 - shared (Current version)')
|
||||
})
|
||||
})
|
||||
nameVersion(2, 'v1 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('v1 - shared')
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
|
||||
})
|
||||
|
||||
context('without edit permission', () => {
|
||||
let recipient: User
|
||||
nameVersion(1, 'v2 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(1).contains('v2 - shared')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { update: false })
|
||||
.then(($recipient) => {
|
||||
recipient = $recipient
|
||||
openVersionsPanel(randomFileName)
|
||||
})
|
||||
})
|
||||
|
||||
it('Does not show action', () => {
|
||||
cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="label"]').should('not.exist')
|
||||
|
||||
doesNotHaveAction(1, 'label')
|
||||
doesNotHaveAction(2, 'label')
|
||||
})
|
||||
|
||||
it('Does not work without update permission through direct API access', () => {
|
||||
let fileId: string | undefined
|
||||
let versionId: string | undefined
|
||||
|
||||
getRowForFile(randomFileName)
|
||||
.should('be.visible')
|
||||
.invoke('attr', 'data-cy-files-list-row-fileid')
|
||||
.then(($fileId) => { fileId = $fileId })
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.eq(1)
|
||||
.invoke('attr', 'data-files-versions-version')
|
||||
.then(($versionId) => { versionId = $versionId })
|
||||
|
||||
cy.logout()
|
||||
cy.then(() => {
|
||||
const base = Cypress.config('baseUrl')!.replace(/index\.php\/?/, '')
|
||||
return cy.request({
|
||||
method: 'PROPPATCH',
|
||||
url: `${base}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
|
||||
auth: { user: recipient.userId, pass: recipient.password },
|
||||
headers: {
|
||||
cookie: '',
|
||||
},
|
||||
body: `<?xml version="1.0"?>
|
||||
<d:propertyupdate xmlns:d="DAV:"
|
||||
xmlns:oc="http://owncloud.org/ns"
|
||||
xmlns:nc="http://nextcloud.org/ns"
|
||||
xmlns:ocs="http://open-collaboration-services.org/ns">
|
||||
<d:set>
|
||||
<d:prop>
|
||||
<nc:version-label>not authorized labeling</nc:version-label>
|
||||
</d:prop>
|
||||
</d:set>
|
||||
</d:propertyupdate>`,
|
||||
failOnStatusCode: false,
|
||||
})
|
||||
}).then(({ status }) => {
|
||||
expect(status).to.equal(403)
|
||||
})
|
||||
})
|
||||
nameVersion(0, 'v3 - shared')
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').eq(0).contains('v3 - shared (Current version)')
|
||||
})
|
||||
})
|
||||
|
||||
it('Name versions without edit permission fails', () => {
|
||||
setupTestSharedFileFromUser(user, 'share', { update: false })
|
||||
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.eq(0)
|
||||
.as('firstVersion')
|
||||
.find('.action-item__menutoggle')
|
||||
.should('not.exist')
|
||||
cy.get('@firstVersion')
|
||||
.find('[data-cy-version-action="label"]')
|
||||
.should('not.exist')
|
||||
|
||||
doesNotHaveAction(1, 'label')
|
||||
doesNotHaveAction(2, 'label')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,31 +6,31 @@
|
|||
import type { User } from '@nextcloud/e2e-test-server/cypress'
|
||||
|
||||
import { randomString } from '../../support/utils/randomString.ts'
|
||||
import { getRowForFile } from '../files/FilesUtils.ts'
|
||||
import { navigateToFolder } from '../files/FilesUtils.ts'
|
||||
import { assertVersionContent, doesNotHaveAction, openVersionsPanel, restoreVersion, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils.ts'
|
||||
|
||||
describe('Versions restoration', () => {
|
||||
let randomFileName = ''
|
||||
let user: User
|
||||
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
randomFileName = randomString(10) + '.txt'
|
||||
|
||||
cy.createRandomUser()
|
||||
.then((_user) => {
|
||||
user = _user
|
||||
uploadThreeVersions(user, randomFileName)
|
||||
cy.mkdir(_user, '/share')
|
||||
uploadThreeVersions(user, `share/${randomFileName}`)
|
||||
cy.login(user)
|
||||
cy.visit('/apps/files')
|
||||
openVersionsPanel(randomFileName)
|
||||
})
|
||||
})
|
||||
|
||||
it('Current version does not have restore action', () => {
|
||||
doesNotHaveAction(0, 'restore')
|
||||
})
|
||||
|
||||
it('Restores initial version', () => {
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
// Current version does not have restore action
|
||||
doesNotHaveAction(0, 'restore')
|
||||
restoreVersion(2)
|
||||
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
|
|
@ -38,81 +38,38 @@ describe('Versions restoration', () => {
|
|||
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
it('Downloads versions and assert there content', () => {
|
||||
// Downloads versions and assert there content
|
||||
assertVersionContent(0, 'v1')
|
||||
assertVersionContent(1, 'v3')
|
||||
assertVersionContent(2, 'v2')
|
||||
})
|
||||
|
||||
context('Restore versions of shared file', () => {
|
||||
it('Works with update permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { update: true })
|
||||
openVersionsPanel(randomFileName)
|
||||
it('Restore versions of shared file with update permission', () => {
|
||||
setupTestSharedFileFromUser(user, 'share', { update: true })
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
it('Restores initial version', () => {
|
||||
restoreVersion(2)
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').should('have.length', 3)
|
||||
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
it('Downloads versions and assert there content', () => {
|
||||
assertVersionContent(0, 'v1')
|
||||
assertVersionContent(1, 'v3')
|
||||
assertVersionContent(2, 'v2')
|
||||
})
|
||||
restoreVersion(2)
|
||||
cy.get('#tab-files_versions').within(() => {
|
||||
cy.get('[data-files-versions-version]').should('have.length', 3)
|
||||
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
|
||||
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
|
||||
})
|
||||
assertVersionContent(0, 'v1')
|
||||
assertVersionContent(1, 'v3')
|
||||
assertVersionContent(2, 'v2')
|
||||
})
|
||||
|
||||
it('Does not show action without delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, randomFileName, { update: false })
|
||||
openVersionsPanel(randomFileName)
|
||||
it('Does not show action without delete permission', () => {
|
||||
setupTestSharedFileFromUser(user, 'share', { update: false })
|
||||
navigateToFolder('share')
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="restore"]').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
|
||||
cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="restore"]').should('not.exist')
|
||||
|
||||
doesNotHaveAction(1, 'restore')
|
||||
doesNotHaveAction(2, 'restore')
|
||||
})
|
||||
|
||||
it('Does not work without update permission through direct API access', () => {
|
||||
let fileId: string | undefined
|
||||
let versionId: string | undefined
|
||||
|
||||
setupTestSharedFileFromUser(user, randomFileName, { update: false })
|
||||
.then((recipient) => {
|
||||
openVersionsPanel(randomFileName)
|
||||
|
||||
getRowForFile(randomFileName)
|
||||
.should('be.visible')
|
||||
.invoke('attr', 'data-cy-files-list-row-fileid')
|
||||
.then(($fileId) => { fileId = $fileId })
|
||||
|
||||
cy.get('[data-files-versions-version]')
|
||||
.eq(1)
|
||||
.invoke('attr', 'data-files-versions-version')
|
||||
.then(($versionId) => { versionId = $versionId })
|
||||
|
||||
cy.logout()
|
||||
cy.then(() => {
|
||||
const base = Cypress.config('baseUrl')!.replace(/\/index\.php\/?$/, '')
|
||||
return cy.request({
|
||||
method: 'MOVE',
|
||||
url: `${base}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
|
||||
auth: { user: recipient.userId, pass: recipient.password },
|
||||
headers: {
|
||||
cookie: '',
|
||||
Destination: `${base}}/remote.php/dav/versions/${recipient.userId}/restore/target`,
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
})
|
||||
}).then(({ status }) => {
|
||||
expect(status).to.equal(403)
|
||||
})
|
||||
})
|
||||
})
|
||||
doesNotHaveAction(1, 'restore')
|
||||
doesNotHaveAction(2, 'restore')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue