-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(files_versions): Add tests for versions actions
Signed-off-by: Louis Chemineau <[email protected]>
- Loading branch information
Showing
5 changed files
with
381 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable jsdoc/require-jsdoc */ | ||
/** | ||
* @copyright Copyright (c) 2022 Louis Chemineau <[email protected]> | ||
* | ||
|
@@ -22,6 +23,7 @@ | |
|
||
import type { User } from '@nextcloud/cypress' | ||
import path from 'path' | ||
import { createShare, type ShareSetting } from '../files_sharing/filesSharingUtils' | ||
|
||
export const uploadThreeVersions = (user: User, fileName: string) => { | ||
// A new version will not be created if the changes occur | ||
|
@@ -35,7 +37,7 @@ export const uploadThreeVersions = (user: User, fileName: string) => { | |
cy.login(user) | ||
} | ||
|
||
export const openVersionsPanel = (fileName: string) =>{ | ||
export function openVersionsPanel(fileName: string) { | ||
// Detect the versions list fetch | ||
cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions') | ||
|
||
|
@@ -50,35 +52,61 @@ export const openVersionsPanel = (fileName: string) =>{ | |
cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 }) | ||
} | ||
|
||
export const openVersionMenu = (index: number) => { | ||
cy.get('#tab-version_vue').within(() => { | ||
cy.get('[data-files-versions-version]') | ||
.eq(index).within(() => { | ||
cy.get('.action-item__menutoggle').filter(':visible') | ||
.click() | ||
}) | ||
}) | ||
export function toggleVersionMenu(index: number) { | ||
cy.get('#tab-version_vue [data-files-versions-version]') | ||
.eq(index) | ||
.find('button') | ||
.click() | ||
} | ||
|
||
export const clickPopperAction = (actionName: string) => { | ||
cy.get('.v-popper__popper').filter(':visible') | ||
.contains(actionName) | ||
.click() | ||
export function triggerVersionAction(index: number, actionName: string) { | ||
toggleVersionMenu(index) | ||
cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).filter(':visible').click() | ||
} | ||
|
||
export const nameVersion = (index: number, name: string) => { | ||
openVersionMenu(index) | ||
clickPopperAction('Name this version') | ||
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 const assertVersionContent = (filename: string, index: number, expectedContent: string) => { | ||
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') | ||
|
||
openVersionMenu(index) | ||
clickPopperAction('Download version') | ||
triggerVersionAction(index, 'download') | ||
|
||
return cy.readFile(path.join(downloadsFolder, filename)) | ||
.then((versionContent) => expect(versionContent).to.equal(expectedContent)) | ||
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`)) | ||
} | ||
|
||
export function setupTestSharedFileFromUser(owner: User, randomFileName: string, shareOptions: Partial<ShareSetting>) { | ||
return cy.createRandomUser() | ||
.then((recipient) => { | ||
cy.login(owner) | ||
cy.visit('/apps/files') | ||
createShare(randomFileName, recipient.userId, shareOptions) | ||
cy.login(recipient) | ||
cy.visit('/apps/files') | ||
return cy.wrap(recipient) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* @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 { doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions, deleteVersion } from './filesVersionsUtils' | ||
import { navigateToFolder, getRowForFile } from '../files/FilesUtils' | ||
|
||
describe('Versions restoration', () => { | ||
const folderName = 'shared_folder' | ||
const randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' | ||
const randomFilePath = `/${folderName}/${randomFileName}` | ||
let user: User | ||
let versionCount = 0 | ||
|
||
before(() => { | ||
cy.createRandomUser() | ||
.then((_user) => { | ||
user = _user | ||
cy.mkdir(user, `/${folderName}`) | ||
uploadThreeVersions(user, randomFilePath) | ||
uploadThreeVersions(user, randomFilePath) | ||
versionCount = 6 | ||
cy.login(user) | ||
cy.visit('/apps/files') | ||
navigateToFolder(folderName) | ||
openVersionsPanel(randomFileName) | ||
}) | ||
}) | ||
|
||
it('Delete initial version', () => { | ||
cy.get('[data-files-versions-version]').should('have.length', versionCount) | ||
deleteVersion(2) | ||
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(randomFileName) | ||
|
||
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(randomFileName) | ||
|
||
doesNotHaveAction(0, 'delete') | ||
doesNotHaveAction(1, 'delete') | ||
doesNotHaveAction(2, 'delete') | ||
}) | ||
|
||
it('Does not work without delete permission through direct API access', () => { | ||
let hostname: string | ||
let fileId: string|undefined | ||
let versionId: string|undefined | ||
|
||
setupTestSharedFileFromUser(user, folderName, { delete: false }) | ||
.then(recipient => { | ||
navigateToFolder(folderName) | ||
openVersionsPanel(randomFileName) | ||
|
||
cy.url().then(url => { hostname = new URL(url).hostname }) | ||
getRowForFile(randomFileName).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.then(() => { | ||
cy.logout() | ||
cy.request({ | ||
method: 'DELETE', | ||
auth: { user: recipient.userId, pass: recipient.password }, | ||
headers: { | ||
cookie: '', | ||
}, | ||
url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`, | ||
failOnStatusCode: false, | ||
}) | ||
.then(({ status }) => { | ||
expect(status).to.equal(403) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.