|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de> |
| 3 | + * |
| 4 | + * @author Ferdinand Thiessen <opensource@fthiessen.de> |
| 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 | +const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${filename}"]`) |
| 24 | +const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]') |
| 25 | +const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]') |
| 26 | +const triggerActionForFile = (filename: string, actionId: string) => { |
| 27 | + getActionButtonForFile(filename).click() |
| 28 | + cy.get(`[data-cy-files-list-row-action="${actionId}"] > button`).should('exist').click() |
| 29 | +} |
| 30 | + |
| 31 | +describe('Files: Move or copy files', { testIsolation: true }, () => { |
| 32 | + let currentUser |
| 33 | + beforeEach(() => { |
| 34 | + cy.createRandomUser().then((user) => { |
| 35 | + currentUser = user |
| 36 | + cy.login(user) |
| 37 | + }) |
| 38 | + }) |
| 39 | + afterEach(() => { |
| 40 | + // nice to have cleanup |
| 41 | + cy.deleteUser(currentUser) |
| 42 | + }) |
| 43 | + |
| 44 | + it('Can copy a file to new folder', () => { |
| 45 | + cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt') |
| 46 | + .mkdir(currentUser, '/new-folder') |
| 47 | + cy.login(currentUser) |
| 48 | + cy.visit('/apps/files') |
| 49 | + |
| 50 | + getRowForFile('original.txt').should('be.visible') |
| 51 | + triggerActionForFile('original.txt', 'move-copy') |
| 52 | + |
| 53 | + // select new folder |
| 54 | + cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click() |
| 55 | + // click copy |
| 56 | + cy.get('.file-picker').contains('button', 'Copy to new-folder').should('be.visible').click() |
| 57 | + |
| 58 | + getRowForFile('new-folder').find('[data-cy-files-list-row-name-link]').click() |
| 59 | + |
| 60 | + cy.url().should('contain', 'dir=/new-folder') |
| 61 | + getRowForFile('original.txt').should('be.visible') |
| 62 | + getRowForFile('new-folder').should('not.exist') |
| 63 | + }) |
| 64 | + |
| 65 | + it('Can move a file to new folder', () => { |
| 66 | + cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt') |
| 67 | + .mkdir(currentUser, '/new-folder') |
| 68 | + cy.login(currentUser) |
| 69 | + cy.visit('/apps/files') |
| 70 | + |
| 71 | + getRowForFile('original.txt').should('be.visible') |
| 72 | + triggerActionForFile('original.txt', 'move-copy') |
| 73 | + |
| 74 | + // select new folder |
| 75 | + cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click() |
| 76 | + // click copy |
| 77 | + cy.get('.file-picker').contains('button', 'Move to new-folder').should('be.visible').click() |
| 78 | + |
| 79 | + // wait until visible again |
| 80 | + getRowForFile('new-folder').should('be.visible') |
| 81 | + // original should be moved -> not exist anymore |
| 82 | + getRowForFile('original.txt').should('not.exist') |
| 83 | + getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click() |
| 84 | + |
| 85 | + cy.url().should('contain', 'dir=/new-folder') |
| 86 | + getRowForFile('original.txt').should('be.visible') |
| 87 | + getRowForFile('new-folder').should('not.exist') |
| 88 | + }) |
| 89 | + |
| 90 | + it('Can move a file to its parent folder', () => { |
| 91 | + cy.mkdir(currentUser, '/new-folder') |
| 92 | + cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt') |
| 93 | + cy.login(currentUser) |
| 94 | + cy.visit('/apps/files') |
| 95 | + |
| 96 | + getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click() |
| 97 | + cy.url().should('contain', 'dir=/new-folder') |
| 98 | + |
| 99 | + getRowForFile('original.txt').should('be.visible') |
| 100 | + triggerActionForFile('original.txt', 'move-copy') |
| 101 | + |
| 102 | + // select new folder |
| 103 | + cy.get('.file-picker a[title="Home"]').should('be.visible').click() |
| 104 | + // click move |
| 105 | + cy.get('.file-picker').contains('button', 'Move').should('be.visible').click() |
| 106 | + |
| 107 | + // wait until visible again |
| 108 | + cy.get('main').contains('No files in here').should('be.visible') |
| 109 | + // original should be moved -> not exist anymore |
| 110 | + getRowForFile('original.txt').should('not.exist') |
| 111 | + |
| 112 | + cy.visit('/apps/files') |
| 113 | + getRowForFile('new-folder').should('be.visible') |
| 114 | + getRowForFile('original.txt').should('be.visible') |
| 115 | + }) |
| 116 | +}) |
0 commit comments