Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions cypress/e2e/files/filesUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]>
*
* @author Ferdinand Thiessen <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`)

export const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]')

export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]')

export const triggerActionForFile = (filename: string, actionId: string) => {
getActionButtonForFile(filename).click()
cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`).should('exist').click()
}

export const moveFile = (fileName: string, dirName: string) => {
getRowForFile(fileName).should('be.visible')
triggerActionForFile(fileName, 'move-copy')

cy.get('.file-picker').within(() => {
// intercept the copy so we can wait for it
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')

if (dirName === '/') {
// select home folder
cy.get('button[title="Home"]').should('be.visible').click()
// click move
cy.contains('button', 'Move').should('be.visible').click()
} else if (dirName === '.') {
// click move
cy.contains('button', 'Copy').should('be.visible').click()
} else {
// select the folder
cy.get(`[data-filename="${dirName}"]`).should('be.visible').click()
// click move
cy.contains('button', `Move to ${dirName}`).should('be.visible').click()
}

cy.wait('@moveFile')
})
}

export const navigateToFolder = (folderName: string) => {
getRowForFile(folderName).should('be.visible').find('[data-cy-files-list-row-name-link]').click()
}
99 changes: 99 additions & 0 deletions cypress/e2e/files_versions/filesVersionsUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable jsdoc/require-jsdoc */
/**
* @copyright Copyright (c) 2022 Louis Chemineau <[email protected]>
*
* @author Louis Chemineau <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import type { User } from '@nextcloud/cypress'
import path from 'path'

export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur
// within less than one second of each other.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
.wait(1100)
.uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
.wait(1100)
.uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
cy.login(user)
}

export function openVersionsPanel(fileName: string) {
// Detect the versions list fetch
cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions')

// Open the versions tab
cy.window().then(win => {
win.OCA.Files.Sidebar.setActiveTab('version_vue')
win.OCA.Files.Sidebar.open(`/${fileName}`)
})

// Wait for the versions list to be fetched
cy.wait('@getVersions')
cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 })
}

export function toggleVersionMenu(index: number) {
cy.get('#tab-version_vue [data-files-versions-version]')
.eq(index)
.find('button')
.click()
}

export function triggerVersionAction(index: number, actionName: string) {
toggleVersionMenu(index)
cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).filter(':visible').click()
}

export function nameVersion(index: number, name: string) {
cy.intercept('PROPPATCH', '**/dav/versions/*/versions/**').as('labelVersion')
triggerVersionAction(index, 'label')
cy.get(':focused').type(`${name}{enter}`)
cy.wait('@labelVersion')
}

export function restoreVersion(index: number) {
cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion')
triggerVersionAction(index, 'restore')
cy.wait('@restoreVersion')
}

export function deleteVersion(index: number) {
cy.intercept('DELETE', '**/dav/versions/*/versions/**').as('deleteVersion')
triggerVersionAction(index, 'delete')
cy.wait('@deleteVersion')
}

export function doesNotHaveAction(index: number, actionName: string) {
toggleVersionMenu(index)
cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).should('not.exist')
toggleVersionMenu(index)
}

export function assertVersionContent(filename: string, index: number, expectedContent: string) {
const downloadsFolder = Cypress.config('downloadsFolder')

triggerVersionAction(index, 'download')

return cy.readFile(path.join(downloadsFolder, filename))
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
}
65 changes: 65 additions & 0 deletions cypress/e2e/files_versions/version_creation.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <[email protected]>
*
* @author Louis Chmn <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import type { User } from '@nextcloud/cypress'

import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'

describe('Versions creation', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
})

it('Opens the versions panel and sees the versions', () => {
cy.get('#tab-version_vue').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')
})
})
})
63 changes: 63 additions & 0 deletions cypress/e2e/files_versions/version_deletion.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @copyright Copyright (c) 2024 Louis Chmn <[email protected]>
*
* @author Louis Chmn <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import type { User } from '@nextcloud/cypress'

import { openVersionsPanel, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'

describe('Versions restoration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
})

it('Delete initial version', () => {
cy.get('[data-files-versions-version]').should('have.length', 3)
deleteVersion(2)
cy.get('[data-files-versions-version]').should('have.length', 2)
})
})
63 changes: 63 additions & 0 deletions cypress/e2e/files_versions/version_download.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <[email protected]>
*
* @author Louis Chmn <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'

describe('Versions download', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
})

it('Download versions and assert their content', () => {
assertVersionContent(randomFileName, 0, 'v3')
assertVersionContent(randomFileName, 1, 'v2')
assertVersionContent(randomFileName, 2, 'v1')
})
})
Loading