|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2024 Louis Chmn <[email protected]> |
| 3 | + * |
| 4 | + * @author Louis Chmn <[email protected]> |
| 5 | + * |
| 6 | + * @license AGPL-3.0-or-later |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +import type { User } from '@nextcloud/cypress' |
| 24 | + |
| 25 | +import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils' |
| 26 | +import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' |
| 27 | +import { clickOnBreadcumbs, closeSidebar, copyFile, moveFile, navigateToFolder } from '../files/filesUtils' |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + * @param filePath |
| 32 | + */ |
| 33 | +function assertVersionsContent(filePath: string) { |
| 34 | + const path = filePath.split('/').slice(0, -1).join('/') |
| 35 | + |
| 36 | + clickOnBreadcumbs('All files') |
| 37 | + |
| 38 | + if (path !== '') { |
| 39 | + navigateToFolder(path) |
| 40 | + } |
| 41 | + |
| 42 | + openVersionsPanel(filePath) |
| 43 | + |
| 44 | + cy.get('[data-files-versions-version]').should('have.length', 3) |
| 45 | + cy.get('[data-files-versions-version]').eq(2).contains('v1') |
| 46 | + assertVersionContent(0, 'v3') |
| 47 | + assertVersionContent(1, 'v2') |
| 48 | + assertVersionContent(2, 'v1') |
| 49 | + closeSidebar() |
| 50 | +} |
| 51 | + |
| 52 | +describe('Versions cross storage move', () => { |
| 53 | + let randomGroupName: string |
| 54 | + let randomGroupFolderName: string |
| 55 | + let randomFileName: string |
| 56 | + let randomCopiedFileName: string |
| 57 | + let user: User |
| 58 | + |
| 59 | + before(() => { |
| 60 | + randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 61 | + randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 62 | + |
| 63 | + cy.createRandomUser().then(_user => { user = _user }) |
| 64 | + createGroup(randomGroupName) |
| 65 | + |
| 66 | + cy.then(() => { |
| 67 | + addUserToGroup(randomGroupName, user.userId) |
| 68 | + createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE]) |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + beforeEach(() => { |
| 73 | + const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 74 | + randomFileName = randomString + '.txt' |
| 75 | + randomCopiedFileName = randomString + ' (copy).txt' |
| 76 | + uploadThreeVersions(user, `${randomGroupFolderName}/${randomFileName}`) |
| 77 | + |
| 78 | + cy.login(user) |
| 79 | + cy.visit('/apps/files') |
| 80 | + navigateToFolder(randomGroupFolderName) |
| 81 | + openVersionsPanel(`${randomGroupFolderName}/${randomFileName}`) |
| 82 | + nameVersion(2, 'v1') |
| 83 | + closeSidebar() |
| 84 | + }) |
| 85 | + |
| 86 | + it('Correctly moves versions to the user\'s FS when the user moves the file out of the groupfolder', () => { |
| 87 | + moveFile(randomFileName, '/') |
| 88 | + |
| 89 | + assertVersionsContent(randomFileName) |
| 90 | + |
| 91 | + moveFile(randomFileName, randomGroupFolderName) |
| 92 | + |
| 93 | + assertVersionsContent(`${randomGroupFolderName}/${randomFileName}`) |
| 94 | + }) |
| 95 | + |
| 96 | + it('Correctly copies versions to the user\'s FS when the user copies the file out of the groupfolder', () => { |
| 97 | + copyFile(randomFileName, '/') |
| 98 | + |
| 99 | + assertVersionsContent(randomFileName) |
| 100 | + |
| 101 | + copyFile(randomFileName, randomGroupFolderName) |
| 102 | + |
| 103 | + assertVersionsContent(`${randomGroupFolderName}/${randomCopiedFileName}`) |
| 104 | + }) |
| 105 | + |
| 106 | + context('When a file is in a subfolder', () => { |
| 107 | + let randomSubFolderName |
| 108 | + let randomCopiedSubFolderName |
| 109 | + let randomSubSubFolderName |
| 110 | + |
| 111 | + beforeEach(() => { |
| 112 | + const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 113 | + randomSubFolderName = randomString |
| 114 | + randomCopiedSubFolderName = randomString + ' (copy)' |
| 115 | + |
| 116 | + randomSubSubFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 117 | + clickOnBreadcumbs('All files') |
| 118 | + cy.mkdir(user, `/${randomGroupFolderName}/${randomSubFolderName}`) |
| 119 | + cy.mkdir(user, `/${randomGroupFolderName}/${randomSubFolderName}/${randomSubSubFolderName}`) |
| 120 | + cy.login(user) |
| 121 | + navigateToFolder(randomGroupFolderName) |
| 122 | + }) |
| 123 | + |
| 124 | + it('Correctly moves versions when user moves the containing folder out of the groupfolder', () => { |
| 125 | + moveFile(randomFileName, `${randomSubFolderName}/${randomSubSubFolderName}`) |
| 126 | + moveFile(randomSubFolderName, '/') |
| 127 | + |
| 128 | + assertVersionsContent(`${randomSubFolderName}/${randomSubSubFolderName}/${randomFileName}`) |
| 129 | + |
| 130 | + clickOnBreadcumbs('All files') |
| 131 | + moveFile(randomSubFolderName, randomGroupFolderName) |
| 132 | + |
| 133 | + assertVersionsContent(`${randomGroupFolderName}/${randomSubFolderName}/${randomSubSubFolderName}/${randomFileName}`) |
| 134 | + }) |
| 135 | + |
| 136 | + // TODO: re-enable this test when the copy event from groupfolder to the home storage contains the file list. |
| 137 | + xit('Correctly copies versions when user copies the containing folder out of the groupfolder', () => { |
| 138 | + moveFile(randomFileName, `${randomSubFolderName}/${randomSubSubFolderName}`) |
| 139 | + copyFile(randomSubFolderName, '/') |
| 140 | + |
| 141 | + assertVersionsContent(`${randomSubFolderName}/${randomSubSubFolderName}/${randomFileName}`) |
| 142 | + |
| 143 | + clickOnBreadcumbs('All files') |
| 144 | + copyFile(randomSubFolderName, randomGroupFolderName) |
| 145 | + |
| 146 | + assertVersionsContent(`${randomGroupFolderName}/${randomCopiedSubFolderName}/${randomSubSubFolderName}/${randomFileName}`) |
| 147 | + }) |
| 148 | + }) |
| 149 | +}) |
0 commit comments