aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files/favorites.cy.ts
blob: d873e6963e6b07f755a91f93f2528604e327b9b7 (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
/*!
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import type { User } from '@nextcloud/cypress'
import { getActionButtonForFile, getRowForFile, triggerActionForFile } from './FilesUtils'

describe('files: Favorites', { testIsolation: true }, () => {
	let user: User

	beforeEach(() => {
		cy.createRandomUser().then(($user) => {
			user = $user
			cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
			cy.mkdir(user, '/new folder')
			cy.login(user)
			cy.visit('/apps/files')
		})
	})

	it('Mark file as favorite', () => {
		// See file exists
		getRowForFile('file.txt')
			.should('exist')

		cy.intercept('POST', '**/apps/files/api/v1/files/file.txt').as('addToFavorites')
		// Click actions
		getActionButtonForFile('file.txt').click({ force: true })
		// See action is called 'Add to favorites'
		cy.get('[data-cy-files-list-row-action="favorite"] > button').last()
			.should('exist')
			.and('have.text', 'Add to favorites')
			.click({ force: true })
		cy.wait('@addToFavorites')
		// See favorites star
		getRowForFile('file.txt')
			.findByRole('img', { name: 'Favorite' })
			.should('exist')
	})

	it('Un-mark file as favorite', () => {
		// See file exists
		getRowForFile('file.txt')
			.should('exist')

		cy.intercept('POST', '**/apps/files/api/v1/files/file.txt').as('addToFavorites')
		// toggle favorite
		triggerActionForFile('file.txt', 'favorite')
		cy.wait('@addToFavorites')

		// See favorites star
		getRowForFile('file.txt')
			.findByRole('img', { name: 'Favorite' })
			.should('be.visible')

		// Remove favorite
		// click action button
		getActionButtonForFile('file.txt').click({ force: true })
		// See action is called 'Remove from favorites'
		cy.get('[data-cy-files-list-row-action="favorite"] > button').last()
			.should('exist')
			.and('have.text', 'Remove from favorites')
			.click({ force: true })
		cy.wait('@addToFavorites')
		// See no favorites star anymore
		getRowForFile('file.txt')
			.findByRole('img', { name: 'Favorite' })
			.should('not.exist')
	})

	it('See favorite folders in navigation', () => {
		cy.intercept('POST', '**/apps/files/api/v1/files/new%20folder').as('addToFavorites')

		// see navigation has no entry
		cy.get('[data-cy-files-navigation-item="favorites"]')
			.should('be.visible')
			.contains('new folder')
			.should('not.exist')

		// toggle favorite
		triggerActionForFile('new folder', 'favorite')
		cy.wait('@addToFavorites')

		// See in navigation
		cy.get('[data-cy-files-navigation-item="favorites"]')
			.should('be.visible')
			.contains('new folder')
			.should('exist')

		// toggle favorite
		triggerActionForFile('new folder', 'favorite')
		cy.wait('@addToFavorites')

		// See no longer in navigation
		cy.get('[data-cy-files-navigation-item="favorites"]')
			.should('be.visible')
			.contains('new folder')
			.should('not.exist')
	})

	it('Mark file as favorite using the sidebar', () => {
		// See file exists
		getRowForFile('new folder')
			.should('exist')
		// see navigation has no entry
		cy.get('[data-cy-files-navigation-item="favorites"]')
			.should('be.visible')
			.contains('new folder')
			.should('not.exist')

		cy.intercept('PROPPATCH', '**/remote.php/dav/files/*/new%20folder').as('addToFavorites')
		// open sidebar
		triggerActionForFile('new folder', 'details')
		// open actions
		cy.get('[data-cy-sidebar]')
			.findByRole('button', { name: 'Actions' })
			.click()
		// trigger menu button
		cy.findAllByRole('menu')
			.findByRole('menuitem', { name: 'Add to favorites' })
			.should('be.visible')
			.click()
		cy.wait('@addToFavorites')

		// See favorites star
		getRowForFile('new folder')
			.findByRole('img', { name: 'Favorite' })
			.should('be.visible')

		// See folder in navigation
		cy.get('[data-cy-files-navigation-item="favorites"]')
			.should('be.visible')
			.contains('new folder')
			.should('exist')
	})
})