aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files_sharing/public-share/view_view-only.cy.ts
blob: 4a8aa6b89a39176a304962a8d28099475745bdfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*!
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import { getActionsForFile, getRowForFile, navigateToFolder } from '../../files/FilesUtils.ts'
import { openSharingPanel } from '../FilesSharingUtils.ts'

describe('files_sharing: Public share - View only', { testIsolation: true }, () => {

	let shareUrl: string
	const shareName = 'shared'

	before(() => {
		cy.createRandomUser().then(($user) => {
			cy.mkdir($user, `/${shareName}`)
			cy.mkdir($user, `/${shareName}/subfolder`)
			cy.uploadContent($user, new Blob(['content']), 'text/plain', `/${shareName}/foo.txt`)
			cy.uploadContent($user, new Blob(['content']), 'text/plain', `/${shareName}/subfolder/bar.txt`)
			cy.login($user)
			// open the files app
			cy.visit('/apps/files')
			// open the sidebar
			openSharingPanel(shareName)
			// create the share
			cy.intercept('POST', '**/ocs/v2.php/apps/files_sharing/api/v1/shares').as('createShare')
			cy.findByRole('button', { name: 'Create a new share link' })
				.click()
			// extract the link
			cy.wait('@createShare').should(({ response }) => {
				const { ocs } = response?.body ?? {}
				shareUrl = ocs?.data.url
				expect(shareUrl).to.match(/^http:\/\//)
			})

			// Update the share to be a view-only-no-download share
			cy.findByRole('list', { name: 'Link shares' })
				.findAllByRole('listitem')
				.first()
				.findByRole('button', { name: /Actions/i })
				.click()
			cy.findByRole('menuitem', { name: /Customize link/i })
				.should('be.visible')
				.click()
			cy.get('[data-cy-files-sharing-share-permissions-bundle]')
				.should('be.visible')
			cy.get('[data-cy-files-sharing-share-permissions-bundle="read-only"]')
				.click()
			// save the update
			cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('updateShare')
			cy.findByRole('button', { name: 'Update share' })
				.click()
			cy.wait('@updateShare')
		})
	})

	beforeEach(() => {
		cy.logout()
		cy.visit(shareUrl)
	})

	it('Can see the files list', () => {
		// foo exists
		getRowForFile('foo.txt')
			.should('be.visible')
	})

	it('Can navigate to subfolder', () => {
		getRowForFile('subfolder')
			.should('be.visible')

		navigateToFolder('subfolder')

		getRowForFile('bar.txt')
			.should('be.visible')
	})

	it('Cannot upload files', () => {
		// wait for file list to be ready
		getRowForFile('foo.txt')
			.should('be.visible')

		cy.contains('button', 'New')
			.should('be.visible')
			.and('be.disabled')
	})

	it('Only download action is actions available', () => {
		getActionsForFile('foo.txt')
			.should('be.visible')
			.click()

		// Only the download action
		cy.findByRole('menuitem', { name: 'Download' })
			.should('be.visible')
		cy.findAllByRole('menuitem')
			.should('have.length', 1)

		// Can download
		cy.findByRole('menuitem', { name: 'Download' }).click()
		// check a file is downloaded
		const downloadsFolder = Cypress.config('downloadsFolder')
		cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
			.should('exist')
			.and('have.length.gt', 5)
			.and('contain', 'content')
	})
})