From e925dbbd0da3a9ee1e58e7bf954a60ec11dcb93e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 2 Sep 2025 18:51:04 +0200 Subject: [PATCH] test: add cypress tests for the systemtags files view Signed-off-by: Ferdinand Thiessen --- cypress/e2e/systemtags/files-view.cy.ts | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 cypress/e2e/systemtags/files-view.cy.ts diff --git a/cypress/e2e/systemtags/files-view.cy.ts b/cypress/e2e/systemtags/files-view.cy.ts new file mode 100644 index 00000000000..3e5630d4544 --- /dev/null +++ b/cypress/e2e/systemtags/files-view.cy.ts @@ -0,0 +1,72 @@ +/*! + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import type { User } from '@nextcloud/cypress' + +import { randomBytes } from 'crypto' +import { closeSidebar, getRowForFile, getRowForFileId, triggerActionForFile } from '../files/FilesUtils.ts' + +describe('Systemtags: Files view', { testIsolation: true }, () => { + let user: User + + beforeEach(() => cy.createRandomUser().then(($user) => { + user = $user + + cy.mkdir(user, '/folder') + cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt') + cy.login(user) + cy.visit('/apps/files') + })) + + it('See first assigned tag in the file list', () => { + const tag = randomBytes(8).toString('base64') + let tagId + + // Tag the file + tagNode(tag, 'folder') + .then((id) => { tagId = id }) + + // open the tags view + cy.visit('/apps/files/tags').then(() => { + // see the tag + getRowForFileId(tagId).should('be.visible') + getRowForFile('folder').should('not.exist') + getRowForFile('file.txt').should('not.exist') + + // see that the tag has its content + getRowForFileId(tagId).find('[data-cy-files-list-row-name-link]').click() + getRowForFile('folder').should('be.visible') + getRowForFile('file.txt').should('not.exist') + }) + }) +}) + +function getCollaborativeTagsInput(): Cypress.Chainable> { + return cy.get('[data-cy-sidebar]') + .findByRole('combobox', { name: /collaborative tags/i }) + .should('be.visible') + .should('not.have.attr', 'disabled', { timeout: 5000 }) +} + +function tagNode(tag: string, node: string): Cypress.Chainable { + getRowForFile(node).should('be.visible') + + triggerActionForFile(node, 'details') + cy.get('[data-cy-sidebar]') + .should('be.visible') + .findByRole('button', { name: 'Actions' }) + .should('be.visible') + .click() + cy.findByRole('menuitem', { name: 'Tags' }) + .should('be.visible') + .click() + cy.intercept('PUT', '**/remote.php/dav/systemtags-relations/files/**').as('assignTag') + getCollaborativeTagsInput() + .type(`{selectAll}${tag}{enter}`) + cy.wait('@assignTag') + closeSidebar() + return cy.get('@assignTag') + .then(({ request }) => request.body.id) +}