Skip to content

Commit e925dbb

Browse files
committed
test: add cypress tests for the systemtags files view
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 74804b6 commit e925dbb

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { User } from '@nextcloud/cypress'
7+
8+
import { randomBytes } from 'crypto'
9+
import { closeSidebar, getRowForFile, getRowForFileId, triggerActionForFile } from '../files/FilesUtils.ts'
10+
11+
describe('Systemtags: Files view', { testIsolation: true }, () => {
12+
let user: User
13+
14+
beforeEach(() => cy.createRandomUser().then(($user) => {
15+
user = $user
16+
17+
cy.mkdir(user, '/folder')
18+
cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
19+
cy.login(user)
20+
cy.visit('/apps/files')
21+
}))
22+
23+
it('See first assigned tag in the file list', () => {
24+
const tag = randomBytes(8).toString('base64')
25+
let tagId
26+
27+
// Tag the file
28+
tagNode(tag, 'folder')
29+
.then((id) => { tagId = id })
30+
31+
// open the tags view
32+
cy.visit('/apps/files/tags').then(() => {
33+
// see the tag
34+
getRowForFileId(tagId).should('be.visible')
35+
getRowForFile('folder').should('not.exist')
36+
getRowForFile('file.txt').should('not.exist')
37+
38+
// see that the tag has its content
39+
getRowForFileId(tagId).find('[data-cy-files-list-row-name-link]').click()
40+
getRowForFile('folder').should('be.visible')
41+
getRowForFile('file.txt').should('not.exist')
42+
})
43+
})
44+
})
45+
46+
function getCollaborativeTagsInput(): Cypress.Chainable<JQuery<HTMLElement>> {
47+
return cy.get('[data-cy-sidebar]')
48+
.findByRole('combobox', { name: /collaborative tags/i })
49+
.should('be.visible')
50+
.should('not.have.attr', 'disabled', { timeout: 5000 })
51+
}
52+
53+
function tagNode(tag: string, node: string): Cypress.Chainable<number> {
54+
getRowForFile(node).should('be.visible')
55+
56+
triggerActionForFile(node, 'details')
57+
cy.get('[data-cy-sidebar]')
58+
.should('be.visible')
59+
.findByRole('button', { name: 'Actions' })
60+
.should('be.visible')
61+
.click()
62+
cy.findByRole('menuitem', { name: 'Tags' })
63+
.should('be.visible')
64+
.click()
65+
cy.intercept('PUT', '**/remote.php/dav/systemtags-relations/files/**').as('assignTag')
66+
getCollaborativeTagsInput()
67+
.type(`{selectAll}${tag}{enter}`)
68+
cy.wait('@assignTag')
69+
closeSidebar()
70+
return cy.get('@assignTag')
71+
.then(({ request }) => request.body.id)
72+
}

0 commit comments

Comments
 (0)