From ef5a9cf00d0842e8e359ddf99a3f492421f09220 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 22 Aug 2024 21:49:06 +0200 Subject: fix(files): Ensure renaming state is correctly reset Problem: Is a node is renamed and the new name is out of the current visible list of nodes the component will be recycled, this means the props will change, so when the `onRename` functions is about to reset the state the `this.source` will point to a different node. To fix this, but also to separate business logic from visual representation, the logic is moved into the renaming store and the component is only responsible for rendering. Signed-off-by: Ferdinand Thiessen --- cypress/e2e/files/files-renaming.cy.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'cypress') diff --git a/cypress/e2e/files/files-renaming.cy.ts b/cypress/e2e/files/files-renaming.cy.ts index 9ac96a398b8..77f23a00459 100644 --- a/cypress/e2e/files/files-renaming.cy.ts +++ b/cypress/e2e/files/files-renaming.cy.ts @@ -4,7 +4,7 @@ */ import type { User } from '@nextcloud/cypress' -import { getRowForFile, haveValidity, triggerActionForFile } from './FilesUtils' +import { getRowForFile, haveValidity, renameFile, triggerActionForFile } from './FilesUtils' describe('files: Rename nodes', { testIsolation: true }, () => { let user: User @@ -115,4 +115,32 @@ describe('files: Rename nodes', { testIsolation: true }, () => { .findByRole('img', { name: 'File is loading' }) .should('not.exist') }) + + /** + * This is a regression test of: https://github.com/nextcloud/server/issues/47438 + * The issue was that the renaming state was not reset when the new name moved the file out of the view of the current files list + * due to virtual scrolling the renaming state was not changed then by the UI events (as the component was taken out of DOM before any event handling). + */ + it('correctly resets renaming state', () => { + for (let i = 1; i <= 20; i++) { + cy.uploadContent(user, new Blob([]), 'text/plain', `/file${i}.txt`) + } + cy.viewport(1200, 500) // 500px is smaller then 20 * 50 which is the place that the files take up + cy.login(user) + cy.visit('/apps/files') + + getRowForFile('file.txt').should('be.visible') + // Z so it is shown last + renameFile('file.txt', 'zzz.txt') + // not visible any longer + getRowForFile('zzz.txt').should('not.be.visible') + // scroll file list to bottom + cy.get('[data-cy-files-list]').scrollTo('bottom') + cy.screenshot() + // The file is no longer in rename state + getRowForFile('zzz.txt') + .should('be.visible') + .findByRole('textbox', { name: 'Filename' }) + .should('not.exist') + }) }) -- cgit v1.2.3