Skip to content

Commit 21b96c0

Browse files
committed
feat(cypress): Add tests for files sidebar
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 91ac7df commit 21b96c0

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
})

cypress/support/commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
/* eslint-disable n/no-unpublished-import */
5+
// eslint-disable-next-line n/no-extraneous-import
6+
import type { AxiosResponse } from 'axios'
7+
68
import axios from '@nextcloud/axios'
79
import { addCommands, User } from '@nextcloud/cypress'
810
import { basename } from 'path'
@@ -16,10 +18,12 @@ addCommands()
1618
declare global {
1719
// eslint-disable-next-line @typescript-eslint/no-namespace
1820
namespace Cypress {
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
1922
interface Chainable<Subject = any> {
2023
/**
2124
* Enable or disable a given user
2225
*/
26+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2327
enableUser(user: User, enable?: boolean): Cypress.Chainable<Cypress.Response<any>>,
2428

2529
/**

0 commit comments

Comments
 (0)