aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files_sharing/public-share/header-avatar.cy.ts
blob: c7227062293dd5df58b6bed07abfbc8663fd22a5 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*!
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import type { ShareContext } from './PublicShareUtils.ts'
import { createLinkShare, setupData } from './PublicShareUtils.ts'

/**
 * This tests ensures that on public shares the header avatar menu correctly works
 */
describe('files_sharing: Public share - header avatar menu', { testIsolation: true }, () => {
	let context: ShareContext
	let firstPublicShareUrl = ''
	let secondPublicShareUrl = ''

	before(() => {
		cy.createRandomUser()
			.then((user) => {
				context = {
					user,
					url: undefined,
				}
				setupData(context.user, 'public1')
				setupData(context.user, 'public2')
				createLinkShare(context, 'public1').then((shareUrl) => {
					firstPublicShareUrl = shareUrl
					cy.log(`Created first share with URL: ${shareUrl}`)
				})
				createLinkShare(context, 'public2').then((shareUrl) => {
					secondPublicShareUrl = shareUrl
					cy.log(`Created second share with URL: ${shareUrl}`)
				})
			})
	})

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

	it('See the undefined avatar menu', () => {
		cy.get('header')
			.findByRole('navigation', { name: /User menu/i })
			.should('be.visible')
			.findByRole('button', { name: /User menu/i })
			.should('be.visible')
			.click()
		cy.get('#header-menu-public-page-user-menu')
			.as('headerMenu')

		// Note that current guest user is not identified
		cy.get('@headerMenu')
			.should('be.visible')
			.findByRole('note')
			.should('be.visible')
			.should('contain', 'not identified')

		// Button to set guest name
		cy.get('@headerMenu')
			.findByRole('link', { name: /Set public name/i })
			.should('be.visible')
	})

	it('Can set public name', () => {
		cy.get('header')
			.findByRole('navigation', { name: /User menu/i })
			.should('be.visible')
			.findByRole('button', { name: /User menu/i })
			.should('be.visible')
			.as('userMenuButton')

		// Open the user menu
		cy.get('@userMenuButton').click()
		cy.get('#header-menu-public-page-user-menu')
			.as('headerMenu')

		cy.get('@headerMenu')
			.findByRole('link', { name: /Set public name/i })
			.should('be.visible')
			.click()

		// Check the dialog is visible
		cy.findByRole('dialog', { name: /Guest identification/i })
			.should('be.visible')
			.as('guestIdentificationDialog')

		// Check the note is visible
		cy.get('@guestIdentificationDialog')
			.findByRole('note')
			.should('contain', 'not identified')

		// Check the input is visible
		cy.get('@guestIdentificationDialog')
			.findByRole('textbox', { name: /Name/i })
			.should('be.visible')
			.type('{selectAll}John Doe{enter}')

		// Check that the dialog is closed
		cy.get('@guestIdentificationDialog')
			.should('not.exist')

		// Check that the avatar changed
		cy.get('@userMenuButton')
			.find('img')
			.invoke('attr', 'src')
			.should('include', 'avatar/guest/John%20Doe')
	})

	it('Guest name us persistent and can be changed', () => {
		cy.get('header')
			.findByRole('navigation', { name: /User menu/i })
			.should('be.visible')
			.findByRole('button', { name: /User menu/i })
			.should('be.visible')
			.as('userMenuButton')

		// Open the user menu
		cy.get('@userMenuButton').click()
		cy.get('#header-menu-public-page-user-menu')
			.as('headerMenu')

		cy.get('@headerMenu')
			.findByRole('link', { name: /Set public name/i })
			.should('be.visible')
			.click()

		// Check the dialog is visible
		cy.findByRole('dialog', { name: /Guest identification/i })
			.should('be.visible')
			.as('guestIdentificationDialog')

		// Set the name
		cy.get('@guestIdentificationDialog')
			.findByRole('textbox', { name: /Name/i })
			.should('be.visible')
			.type('{selectAll}Jane Doe{enter}')

		// Check that the dialog is closed
		cy.get('@guestIdentificationDialog')
			.should('not.exist')

		// Create another share
		cy.visit(secondPublicShareUrl)

		cy.get('header')
			.findByRole('navigation', { name: /User menu/i })
			.should('be.visible')
			.findByRole('button', { name: /User menu/i })
			.should('be.visible')
			.as('userMenuButton')

		// Open the user menu
		cy.get('@userMenuButton').click()
		cy.get('#header-menu-public-page-user-menu')
			.as('headerMenu')

		// See the note with the current name
		cy.get('@headerMenu')
			.findByRole('note')
			.should('contain', 'You will be identified as Jane Doe')

		cy.get('@headerMenu')
			.findByRole('link', { name: /Change public name/i })
			.should('be.visible')
			.click()

		// Check the dialog is visible
		cy.findByRole('dialog', { name: /Guest identification/i })
			.should('be.visible')
			.as('guestIdentificationDialog')

		// Check that the note states the current name
		// cy.get('@guestIdentificationDialog')
		// 	.findByRole('note')
		// 	.should('contain', 'are currently identified as Jane Doe')

		// Change the name
		cy.get('@guestIdentificationDialog')
			.findByRole('textbox', { name: /Name/i })
			.should('be.visible')
			.type('{selectAll}Foo Bar{enter}')

		// Check that the dialog is closed
		cy.get('@guestIdentificationDialog')
			.should('not.exist')

		// Check that the avatar changed with the second name
		cy.get('@userMenuButton')
			.find('img')
			.invoke('attr', 'src')
			.should('include', 'avatar/guest/Foo%20Bar')
	})
})