summaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files.cy.ts
blob: 381d83912b81c2793c430908f04c90c6361c5d08 (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
/**
 * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import type { User } from "@nextcloud/cypress"

const startCopyMove = (file: string) => {
	cy.get(`.files-fileList tr[data-file="${file}"`)
		.find('.fileactions [data-action="menu"]')
		.click()
	cy.get('.fileActionsMenu .action-movecopy').click()
}

describe('Login with a new user and open the files app', function() {
	before(function() {
		cy.createRandomUser().then((user) => {
			cy.login(user)
		})
	})

	Cypress.on('uncaught:exception', (err) => {
		// This can happen because of blink engine & skeleton animation, its not a bug just engine related.
		if (err.message.includes('ResizeObserver loop limit exceeded')) {
		  return false
		}
	})

	it('See the default file welcome.txt in the files list', function() {
		cy.visit('/apps/files')
		cy.get('.files-fileList tr').should('contain', 'welcome.txt')
	})

	it('See the file list sorting order is saved', function() {
		cy.intercept('PUT', /api\/v1\/views\/files\/sorting_direction$/).as('sorting_direction')

		cy.visit('/apps/files')
		// default to sorting by name
		cy.get('.files-filestable th.column-name .sort-indicator').should('be.visible')
		// change to size
		cy.get('.files-filestable th').contains('Size').click()
		// size sorting should be active
		cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
		cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
		cy.wait('@sorting_direction')

		// Re-visit
		cy.visit('/apps/files')
		// now sorting by name should be disabled and sorting by size should be enabled
		cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
		cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
	})
})

describe('Testing the copy move action (FilePicker)', () => {
	let currentUser: User
	beforeEach(function() {
		cy.createRandomUser().then((user) => {
			currentUser = user
			cy.login(user)
		})
	})

	afterEach(function() {
		cy.deleteUser(currentUser)
	})

	it('Copy a file in its same folder', () => {
		cy.visit('/apps/files')
		// When I start the move or copy operation for "welcome.txt"
		startCopyMove('welcome.txt')
		// And I copy to the last selected folder in the file picker
		cy.get('.dialog__actions button').contains('Copy').click()
		// Then I see that the file list contains a file named "welcome.txt"
		cy.get('.files-fileList tr').should('contain', 'welcome.txt')
		// And I see that the file list contains a file named "welcome (copy).txt"
		cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
	})

	it('copy a file twice in its same folder', () => {
		cy.visit('/apps/files')
		// When I start the move or copy operation for "welcome.txt"
		startCopyMove('welcome.txt')
		// And I copy to the last selected folder in the file picker
		cy.get('.dialog__actions button').contains('Copy').click()
		// When I start the move or copy operation for "welcome.txt"
		startCopyMove('welcome.txt')
		// And I copy to the last selected folder in the file picker
		cy.get('.dialog__actions button').contains('Copy').click()
		// Then I see that the file list contains a file named "welcome.txt"
		cy.get('.files-fileList tr').should('contain', 'welcome.txt')
		// And I see that the file list contains a file named "welcome (copy).txt"
		cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
		// And I see that the file list contains a file named "welcome (copy 2).txt"
		cy.get('.files-fileList tr').should('contain', 'welcome (copy 2).txt')
	})

	it('copy a copy of a file in its same folder', () => {
		cy.visit('/apps/files')
		// When I start the move or copy operation for "welcome.txt"
		startCopyMove('welcome.txt')
		// And I copy to the last selected folder in the file picker
		cy.get('.dialog__actions button').contains('Copy').click()
		// When I start the move or copy operation for "welcome (copy).txt"
		startCopyMove('welcome (copy).txt')
		// And I copy to the last selected folder in the file picker
		cy.get('.dialog__actions button').contains('Copy').click()
		// Then I see that the file list contains a file named "welcome.txt"
		cy.get('.files-fileList tr').should('contain', 'welcome.txt')
		// And I see that the file list contains a file named "welcome (copy).txt"
		cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
		// And I see that the file list contains a file named "welcome (copy 2).txt"
		cy.get('.files-fileList tr').should('contain', 'welcome (copy 2).txt')
	})
})