aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/settings/users_modify.cy.ts
blob: f128375e8685028159b7425909018b7ae5389143 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { User } from '@nextcloud/cypress'
import { getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
import { clearState } from '../../support/commonUtils'

const admin = new User('admin', 'admin')

describe('Settings: Change user properties', function() {
	let user: User

	beforeEach(function() {
		clearState()
		cy.createRandomUser().then(($user) => { user = $user })
		cy.login(admin)
	})

	it('Can change the display name', function() {
		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).within(() => {
			// set the display name
			cy.get('[data-cy-user-list-input-displayname]').should('exist').and('have.value', user.userId)
			cy.get('[data-cy-user-list-input-displayname]').clear()
			cy.get('[data-cy-user-list-input-displayname]').type('John Doe')
			cy.get('[data-cy-user-list-input-displayname]').should('have.value', 'John Doe')
			cy.get('[data-cy-user-list-input-displayname] ~ button').click()

			// Make sure no confirmation modal is shown
			handlePasswordConfirmation(admin.password)

			// see that the display name cell is done loading
			waitLoading('[data-cy-user-list-input-displayname]')
		})

		// Success message is shown
		cy.get('.toastify.toast-success').contains(/Display.+name.+was.+successfully.+changed/i).should('exist')
	})

	it('Can change the password', function() {
		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).within(() => {
			// see that the password of user is ""
			cy.get('[data-cy-user-list-input-password]').should('exist').and('have.value', '')
			// set the password for user to 123456
			cy.get('[data-cy-user-list-input-password]').type('123456')
			// When I set the password for user to 123456
			cy.get('[data-cy-user-list-input-password]').should('have.value', '123456')
			cy.get('[data-cy-user-list-input-password] ~ button').click()

			// Make sure no confirmation modal is shown
			handlePasswordConfirmation(admin.password)

			// see that the password cell for user is done loading
			waitLoading('[data-cy-user-list-input-password]')
			// password input is emptied on change
			cy.get('[data-cy-user-list-input-password]').should('have.value', '')
		})

		// Success message is shown
		cy.get('.toastify.toast-success').contains(/Password.+successfully.+changed/i).should('exist')
	})

	it('Can change the email address', function() {
		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).find('[data-cy-user-list-cell-email]').within(() => {
			// see that the email of user is ""
			cy.get('input').should('exist').and('have.value', '')
			// set the email for user to mymail@example.com
			cy.get('input').type('mymail@example.com')
			// When I set the password for user to mymail@example.com
			cy.get('input').should('have.value', 'mymail@example.com')
			cy.get('input ~ button').click()

			// Make sure no confirmation modal is shown
			handlePasswordConfirmation(admin.password)

			// see that the password cell for user is done loading
			waitLoading('[data-cy-user-list-input-email]')
		})

		// Success message is shown
		cy.get('.toastify.toast-success').contains(/Email.+successfully.+changed/i).should('exist')
	})

	it('Can change the user quota to a predefined one', function() {
		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').scrollIntoView()
		getUserListRow(user.userId).find('[data-cy-user-list-cell-quota] [data-cy-user-list-input-quota]').within(() => {
			// see that the quota of user is unlimited
			cy.get('.vs__selected').should('exist').and('contain.text', 'Unlimited')
			// Open the quota selector
			cy.get('[role="combobox"]').click({ force: true })
			// see that there are default options for the quota
			cy.get('li').then(($options) => {
				expect($options).to.have.length(5)
				cy.wrap($options).contains('Default quota')
				cy.wrap($options).contains('Unlimited')
				cy.wrap($options).contains('1 GB')
				cy.wrap($options).contains('10 GB')
				// select 5 GB
				cy.wrap($options).contains('5 GB').click({ force: true })

				// Make sure no confirmation modal is shown
				handlePasswordConfirmation(admin.password)
			})
			// see that the quota of user is 5 GB
			cy.get('.vs__selected').should('exist').and('contain.text', '5 GB')
		})

		// see that the changes are loading
		waitLoading('[data-cy-user-list-input-quota]')

		// finish editing the user
		toggleEditButton(user, false)

		// I see that the quota was set on the backend
		cy.runOccCommand(`user:info --output=json '${user.userId}'`).then(($result) => {
			expect($result.code).to.equal(0)
			const info = JSON.parse($result.stdout)
			expect(info?.quota).to.equal('5 GB')
		})
	})

	it('Can change the user quota to a custom value', function() {
		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').scrollIntoView()
		getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').within(() => {
			// see that the quota of user is unlimited
			cy.get('.vs__selected').should('exist').and('contain.text', 'Unlimited')
			// set the quota to 4 MB
			cy.get('[data-cy-user-list-input-quota] input').type('4 MB{enter}')

			// Make sure no confirmation modal is shown
			handlePasswordConfirmation(admin.password)

			// see that the quota of user is 4 MB
			// TODO: Enable this after the file size handling is fixed
			// cy.get('.vs__selected').should('exist').and('contain.text', '4 MB')

			// see that the changes are loading
			waitLoading('[data-cy-user-list-input-quota]')
		})

		// finish editing the user
		toggleEditButton(user, false)

		// I see that the quota was set on the backend
		cy.runOccCommand(`user:info --output=json '${user.userId}'`).then(($result) => {
			expect($result.code).to.equal(0)
			// TODO: Enable this after the file size handling is fixed!!!!!!
			// const info = JSON.parse($result.stdout)
			// expect(info?.quota).to.equal('4 MB')
		})
	})

	it('Can set manager of a user', function() {
		// create the manager
		let manager: User
		cy.createRandomUser().then(($user) => { manager = $user })

		// open the User settings as admin
		cy.login(admin)
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId)
			.find('[data-cy-user-list-cell-manager]')
			.scrollIntoView()

		getUserListRow(user.userId).find('[data-cy-user-list-cell-manager]').within(() => {
			// see that the user has no manager
			cy.get('.vs__selected').should('not.exist')
			// Open the dropdown menu
			cy.get('[role="combobox"]').click({ force: true })
			// select the manager
			cy.contains('li', manager.userId).click({ force: true })

			// Handle password confirmation on time out
			handlePasswordConfirmation(admin.password)

			// see that the user has a manager set
			cy.get('.vs__selected').should('exist').and('contain.text', manager.userId)
		})

		// see that the changes are loading
		waitLoading('[data-cy-user-list-input-manager]')

		// finish editing the user
		toggleEditButton(user, false)

		// validate the manager is set
		cy.getUserData(user).then(($result) => expect($result.body).to.contain(`<manager>${manager.userId}</manager>`))
	})

	it('Can make user a subadmin of a group', function() {
		// create a group
		const groupName = 'userstestgroup'
		cy.runOccCommand(`group:add '${groupName}'`)

		// open the User settings as admin
		cy.visit('/settings/users')

		// toggle edit button into edit mode
		toggleEditButton(user, true)

		getUserListRow(user.userId).find('[data-cy-user-list-cell-subadmins]').scrollIntoView()
		getUserListRow(user.userId).find('[data-cy-user-list-cell-subadmins]').within(() => {
			// see that the user is no subadmin
			cy.get('.vs__selected').should('not.exist')
			// Open the dropdown menu
			cy.get('[role="combobox"]').click({ force: true })
			// select the group
			cy.contains('li', groupName).click({ force: true })

			// handle password confirmation on time out
			handlePasswordConfirmation(admin.password)

			// see that the user is subadmin of the group
			cy.get('.vs__selected').should('exist').and('contain.text', groupName)
		})

		waitLoading('[data-cy-user-list-input-subadmins]')

		// finish editing the user
		toggleEditButton(user, false)

		// I see that the quota was set on the backend
		cy.getUserData(user).then(($response) => {
			expect($response.status).to.equal(200)
			const dom = (new DOMParser()).parseFromString($response.body, 'text/xml')
			expect(dom.querySelector('subadmin element')?.textContent).to.contain(groupName)
		})
	})
})