aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-07-19 12:20:25 +0200
committerskjnldsv <skjnldsv@protonmail.com>2024-07-19 12:20:25 +0200
commit08af33b5d920db50ff277c1d6426482aac38af50 (patch)
tree7f7238c23dd0d2f5700e669df59002141e22606e
parentcfa2caacf1d78e1cba261f9b44ae5ccf98860edf (diff)
downloadnextcloud-server-08af33b5d920db50ff277c1d6426482aac38af50.tar.gz
nextcloud-server-08af33b5d920db50ff277c1d6426482aac38af50.zip
chore: add file request cypress testing
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r--apps/files/src/components/NewNodeDialog.vue7
-rw-r--r--apps/files/src/utils/newNodeDialog.ts2
-rw-r--r--apps/files_sharing/src/views/PublicAuthPrompt.vue9
-rw-r--r--cypress/e2e/files/FilesUtils.ts15
-rw-r--r--cypress/e2e/files_sharing/FilesSharingUtils.ts (renamed from cypress/e2e/files_sharing/filesSharingUtils.ts)81
-rw-r--r--cypress/e2e/files_sharing/file-request.cy.ts59
-rw-r--r--cypress/e2e/files_versions/filesVersionsUtils.ts2
7 files changed, 168 insertions, 7 deletions
diff --git a/apps/files/src/components/NewNodeDialog.vue b/apps/files/src/components/NewNodeDialog.vue
index 1ac65421dfe..d73e363e39f 100644
--- a/apps/files/src/components/NewNodeDialog.vue
+++ b/apps/files/src/components/NewNodeDialog.vue
@@ -3,13 +3,15 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
- <NcDialog :name="name"
+ <NcDialog data-cy-files-new-node-dialog
+ :name="name"
:open="open"
close-on-click-outside
out-transition
@update:open="onClose">
<template #actions>
- <NcButton type="primary"
+ <NcButton data-cy-files-new-node-dialog-submit
+ type="primary"
:disabled="!isUniqueName"
@click="onCreate">
{{ t('files', 'Create') }}
@@ -17,6 +19,7 @@
</template>
<form @submit.prevent="onCreate">
<NcTextField ref="input"
+ data-cy-files-new-node-dialog-input
:error="!isUniqueName"
:helper-text="errorMessage"
:label="label"
diff --git a/apps/files/src/utils/newNodeDialog.ts b/apps/files/src/utils/newNodeDialog.ts
index 53d4fe4d00f..a81fa9f4e17 100644
--- a/apps/files/src/utils/newNodeDialog.ts
+++ b/apps/files/src/utils/newNodeDialog.ts
@@ -23,7 +23,7 @@ interface ILabels {
* @param defaultName Default name to use
* @param folderContent Nodes with in the current folder to check for unique name
* @param labels Labels to set on the dialog
- * @return string if successfull otherwise null if aborted
+ * @return string if successful otherwise null if aborted
*/
export function newNodeName(defaultName: string, folderContent: Node[], labels: ILabels = {}) {
const contentNames = folderContent.map((node: Node) => node.basename)
diff --git a/apps/files_sharing/src/views/PublicAuthPrompt.vue b/apps/files_sharing/src/views/PublicAuthPrompt.vue
index a929afffefb..2e61bec7434 100644
--- a/apps/files_sharing/src/views/PublicAuthPrompt.vue
+++ b/apps/files_sharing/src/views/PublicAuthPrompt.vue
@@ -5,6 +5,7 @@
<template>
<NcDialog class="public-auth-prompt"
+ data-cy-public-auth-prompt-dialog
dialog-classes="public-auth-prompt__dialog"
:can-close="false"
:name="dialogName">
@@ -26,16 +27,18 @@
@submit.prevent.stop="">
<NcTextField ref="input"
class="public-auth-prompt__input"
+ data-cy-public-auth-prompt-dialog-name
:label="t('files_sharing', 'Enter your name')"
- name="name"
- :required="true"
:minlength="2"
- :value.sync="name" />
+ :required="true"
+ :value.sync="name"
+ name="name" />
</form>
<!-- Submit -->
<template #actions>
<NcButton ref="submit"
+ data-cy-public-auth-prompt-dialog-submit
:disabled="name.trim() === ''"
@click="onSubmit">
{{ t('files_sharing', 'Submit name') }}
diff --git a/cypress/e2e/files/FilesUtils.ts b/cypress/e2e/files/FilesUtils.ts
index ed2a9ac3389..b94ad3941ec 100644
--- a/cypress/e2e/files/FilesUtils.ts
+++ b/cypress/e2e/files/FilesUtils.ts
@@ -121,3 +121,18 @@ export const clickOnBreadcrumbs = (label: string) => {
cy.get('[data-cy-files-content-breadcrumbs]').contains(label).click()
cy.wait('@propfind')
}
+
+export const createFolder = (folderName: string) => {
+ cy.intercept('MKCOL', /\/remote.php\/dav\/files\//).as('createFolder')
+
+ // TODO: replace by proper data-cy selectors
+ cy.get('[data-cy-upload-picker] .action-item__menutoggle').first().click()
+ cy.contains('.upload-picker__menu-entry button', 'New folder').click()
+ cy.get('[data-cy-files-new-node-dialog]').should('be.visible')
+ cy.get('[data-cy-files-new-node-dialog-input]').type(`{selectall}${folderName}`)
+ cy.get('[data-cy-files-new-node-dialog-submit]').click()
+
+ cy.wait('@createFolder')
+
+ getRowForFile(folderName).should('be.visible')
+}
diff --git a/cypress/e2e/files_sharing/filesSharingUtils.ts b/cypress/e2e/files_sharing/FilesSharingUtils.ts
index 2899bf45b14..77f5d38ba8a 100644
--- a/cypress/e2e/files_sharing/filesSharingUtils.ts
+++ b/cypress/e2e/files_sharing/FilesSharingUtils.ts
@@ -5,6 +5,8 @@
/* eslint-disable jsdoc/require-jsdoc */
import { triggerActionForFile } from '../files/FilesUtils'
+import { EntryId as FileRequestEntryID } from '../../../apps/files_sharing/src/new/newFileRequest'
+
export interface ShareSetting {
read: boolean
update: boolean
@@ -96,3 +98,82 @@ export function openSharingPanel(fileName: string) {
.get('[aria-controls="tab-sharing"]')
.click()
}
+
+type FileRequestOptions = {
+ label?: string
+ note?: string
+ password?: string
+ /* YYYY-MM-DD format */
+ expiration?: string
+}
+
+/**
+ * Create a file request for a folder
+ * @param path The path of the folder, leading slash is required
+ * @param options The options for the file request
+ */
+export const createFileRequest = (path: string, options: FileRequestOptions = {}) => {
+ if (!path.startsWith('/')) {
+ throw new Error('Path must start with a slash')
+ }
+
+ // Navigate to the folder
+ cy.visit('/apps/files/files?dir=' + path)
+
+ // Open the file request dialog
+ cy.get('[data-cy-upload-picker] .action-item__menutoggle').first().click()
+ cy.contains('.upload-picker__menu-entry button', 'Create file request').click()
+ cy.get('[data-cy-file-request-dialog]').should('be.visible')
+
+ // Check and fill the first page options
+ cy.get('[data-cy-file-request-dialog-fieldset="label"]').should('be.visible')
+ cy.get('[data-cy-file-request-dialog-fieldset="destination"]').should('be.visible')
+ cy.get('[data-cy-file-request-dialog-fieldset="note"]').should('be.visible')
+
+ cy.get('[data-cy-file-request-dialog-fieldset="destination"] input').should('contain.value', path)
+ if (options.label) {
+ cy.get('[data-cy-file-request-dialog-fieldset="label"] input').type(`{selectall}${options.label}`)
+ }
+ if (options.note) {
+ cy.get('[data-cy-file-request-dialog-fieldset="note"] textarea').type(`{selectall}${options.note}`)
+ }
+
+ // Go to the next page
+ cy.get('[data-cy-file-request-dialog-controls="next"]').click()
+ cy.get('[data-cy-file-request-dialog-fieldset="expiration"] input[type="checkbox"]').should('exist')
+ cy.get('[data-cy-file-request-dialog-fieldset="expiration"] input[type="date"]').should('not.exist')
+ cy.get('[data-cy-file-request-dialog-fieldset="password"] input[type="checkbox"]').should('exist')
+ cy.get('[data-cy-file-request-dialog-fieldset="password"] input[type="password"]').should('not.exist')
+ if (options.expiration) {
+ cy.get('[data-cy-file-request-dialog-fieldset="expiration"] input[type="checkbox"]').check({ force: true })
+ cy.get('[data-cy-file-request-dialog-fieldset="expiration"] input[type="date"]').type(`{selectall}${options.expiration}`)
+ }
+ if (options.password) {
+ cy.get('[data-cy-file-request-dialog-fieldset="password"] input[type="checkbox"]').check({ force: true })
+ cy.get('[data-cy-file-request-dialog-fieldset="password"] input[type="password"]').type(`{selectall}${options.password}`)
+ }
+
+ // Create the file request
+ cy.get('[data-cy-file-request-dialog-controls="next"]').click()
+
+ // Get the file request URL
+ cy.get('[data-cy-file-request-dialog-fieldset="link"]').then(($link) => {
+ const url = $link.val()
+ cy.log(`File request URL: ${url}`)
+ cy.wrap(url).as('fileRequestUrl')
+ })
+
+ // Close
+ cy.get('[data-cy-file-request-dialog-controls="finish"]').click()
+}
+
+export const enterGuestName = (name: string) => {
+ cy.get('[data-cy-public-auth-prompt-dialog]').should('be.visible')
+ cy.get('[data-cy-public-auth-prompt-dialog-name]').should('be.visible')
+ cy.get('[data-cy-public-auth-prompt-dialog-submit]').should('be.visible')
+
+ cy.get('[data-cy-public-auth-prompt-dialog-name]').type(`{selectall}${name}`)
+ cy.get('[data-cy-public-auth-prompt-dialog-submit]').click()
+
+ cy.get('[data-cy-public-auth-prompt-dialog]').should('not.exist')
+}
diff --git a/cypress/e2e/files_sharing/file-request.cy.ts b/cypress/e2e/files_sharing/file-request.cy.ts
new file mode 100644
index 00000000000..793383e9a77
--- /dev/null
+++ b/cypress/e2e/files_sharing/file-request.cy.ts
@@ -0,0 +1,59 @@
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import type { User } from '@nextcloud/cypress'
+import { createFolder, getRowForFile } from '../files/FilesUtils'
+import { createFileRequest, enterGuestName } from './FilesSharingUtils'
+
+describe('Files', { testIsolation: true }, () => {
+ let user: User
+ let url = ''
+ let folderName = 'test-folder'
+
+ it('Login with a user and create a file request', () => {
+ cy.createRandomUser().then((_user) => {
+ user = _user
+ cy.login(user)
+ })
+
+ cy.visit('/apps/files')
+ createFolder(folderName)
+
+ createFileRequest(`/${folderName}`)
+ cy.get('@fileRequestUrl').should('contain', '/s/').then((_url: string) => {
+ cy.logout()
+ url = _url
+ })
+ })
+
+ it('Open the file request as a guest', () => {
+ cy.visit(url)
+ enterGuestName('Guest')
+
+ // Check various elements on the page
+ cy.get('#public-upload .emptycontent').should('be.visible')
+ cy.get('#public-upload h2').contains(`Upload files to ${folderName}`)
+ cy.get('#public-upload input[type="file"]').as('fileInput').should('exist')
+
+ cy.intercept('PUT', '/public.php/dav/files/*/*').as('uploadFile')
+
+ // Upload a file
+ cy.get('@fileInput').selectFile({
+ contents: Cypress.Buffer.from('abcdef'),
+ fileName: 'file.txt',
+ mimeType: 'text/plain',
+ lastModified: Date.now(),
+ }, { force: true })
+
+ cy.wait('@uploadFile').its('response.statusCode').should('eq', 201)
+ })
+
+ it('Check the uploaded file', () => {
+ cy.login(user)
+ cy.visit(`/apps/files/files?dir=/${folderName}`)
+ getRowForFile('Guest').should('be.visible').get('a[data-cy-files-list-row-name-link]').click()
+ getRowForFile('file.txt').should('be.visible')
+ })
+})
diff --git a/cypress/e2e/files_versions/filesVersionsUtils.ts b/cypress/e2e/files_versions/filesVersionsUtils.ts
index a27275e8330..75c76b7e97c 100644
--- a/cypress/e2e/files_versions/filesVersionsUtils.ts
+++ b/cypress/e2e/files_versions/filesVersionsUtils.ts
@@ -4,7 +4,7 @@
*/
/* eslint-disable jsdoc/require-jsdoc */
import type { User } from '@nextcloud/cypress'
-import { createShare, type ShareSetting } from '../files_sharing/filesSharingUtils'
+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