|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2024 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 | +import type { User } from '@nextcloud/cypress' |
| 24 | +import { getRowForFile, navigateToFolder, triggerActionForFile } from './FilesUtils' |
| 25 | + |
| 26 | +describe('Files: Sidebar', { testIsolation: true }, () => { |
| 27 | + let user: User |
| 28 | + let fileId: number = 0 |
| 29 | + |
| 30 | + beforeEach(() => cy.createRandomUser().then(($user) => { |
| 31 | + user = $user |
| 32 | + |
| 33 | + cy.mkdir(user, '/folder') |
| 34 | + cy.uploadContent(user, new Blob([]), 'text/plain', '/file').then((response) => { |
| 35 | + fileId = Number.parseInt(response.headers['oc-fileid'] ?? '0') |
| 36 | + }) |
| 37 | + cy.login(user) |
| 38 | + })) |
| 39 | + |
| 40 | + it('opens the sidebar', () => { |
| 41 | + cy.visit('/apps/files') |
| 42 | + getRowForFile('file').should('be.visible') |
| 43 | + |
| 44 | + triggerActionForFile('file', 'details') |
| 45 | + |
| 46 | + cy.get('[cy-data-sidebar]').should('be.visible') |
| 47 | + }) |
| 48 | + |
| 49 | + it('changes the current fileid', () => { |
| 50 | + cy.visit('/apps/files') |
| 51 | + getRowForFile('file').should('be.visible') |
| 52 | + |
| 53 | + triggerActionForFile('file', 'details') |
| 54 | + |
| 55 | + cy.get('[cy-data-sidebar]').should('be.visible') |
| 56 | + cy.url().should('contain', `apps/files/files/${fileId}`) |
| 57 | + }) |
| 58 | + |
| 59 | + it('closes the sidebar on delete', () => { |
| 60 | + cy.visit('/apps/files') |
| 61 | + getRowForFile('file').should('be.visible') |
| 62 | + |
| 63 | + // open the sidebar |
| 64 | + triggerActionForFile('file', 'details') |
| 65 | + // validate it is open |
| 66 | + cy.get('[cy-data-sidebar]').should('be.visible') |
| 67 | + |
| 68 | + triggerActionForFile('file', 'delete') |
| 69 | + cy.get('[cy-data-sidebar]').should('not.exist') |
| 70 | + }) |
| 71 | + |
| 72 | + it('changes the fileid on delete', () => { |
| 73 | + cy.uploadContent(user, new Blob([]), 'text/plain', '/folder/other').then((response) => { |
| 74 | + const otherFileId = Number.parseInt(response.headers['oc-fileid'] ?? '0') |
| 75 | + cy.login(user) |
| 76 | + cy.visit('/apps/files') |
| 77 | + |
| 78 | + getRowForFile('folder').should('be.visible') |
| 79 | + navigateToFolder('folder') |
| 80 | + getRowForFile('other').should('be.visible') |
| 81 | + |
| 82 | + // open the sidebar |
| 83 | + triggerActionForFile('other', 'details') |
| 84 | + // validate it is open |
| 85 | + cy.get('[cy-data-sidebar]').should('be.visible') |
| 86 | + cy.url().should('contain', `apps/files/files/${otherFileId}`) |
| 87 | + |
| 88 | + triggerActionForFile('other', 'delete') |
| 89 | + cy.get('[cy-data-sidebar]').should('not.exist') |
| 90 | + // Ensure the URL is changed |
| 91 | + cy.url().should('not.contain', `apps/files/files/${otherFileId}`) |
| 92 | + }) |
| 93 | + }) |
| 94 | +}) |
0 commit comments