fix(files): do not show extension warning for folders renaming

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
skjnldsv 2025-02-19 15:34:45 +01:00
parent ff86bacaad
commit 99579f0bbc
2 changed files with 67 additions and 4 deletions

View file

@ -7,7 +7,7 @@ import type { RenamingStore } from '../types'
import axios, { isAxiosError } from '@nextcloud/axios'
import { emit, subscribe } from '@nextcloud/event-bus'
import { NodeStatus } from '@nextcloud/files'
import { FileType, NodeStatus } from '@nextcloud/files'
import { DialogBuilder } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
import { basename, dirname, extname } from 'path'
@ -103,10 +103,10 @@ export const useRenamingStore = function(...args) {
const oldName = this.renamingNode.basename
const oldEncodedSource = this.renamingNode.encodedSource
// Check for extension change
// Check for extension change for files
const oldExtension = extname(oldName)
const newExtension = extname(newName)
if (oldExtension !== newExtension) {
if (oldExtension !== newExtension && this.renamingNode.type === FileType.File) {
const proceed = await showWarningDialog(oldExtension, newExtension)
if (!proceed) {
return false

View file

@ -4,7 +4,7 @@
*/
import type { User } from '@nextcloud/cypress'
import { calculateViewportHeight, getRowForFile, haveValidity, renameFile, triggerActionForFile } from './FilesUtils'
import { calculateViewportHeight, createFolder, getRowForFile, haveValidity, renameFile, triggerActionForFile } from './FilesUtils'
describe('files: Rename nodes', { testIsolation: true }, () => {
let user: User
@ -193,4 +193,67 @@ describe('files: Rename nodes', { testIsolation: true }, () => {
.findByRole('textbox', { name: 'Filename' })
.should('not.exist')
})
it('shows warning on extension change', () => {
getRowForFile('file.txt').should('be.visible')
triggerActionForFile('file.txt', 'rename')
getRowForFile('file.txt')
.findByRole('textbox', { name: 'Filename' })
.should('be.visible')
.type('{selectAll}file.md')
.should(haveValidity(''))
.type('{enter}')
// See warning dialog
cy.findByRole('dialog', { name: 'Change file extension' })
.should('be.visible')
.findByRole('button', { name: /use/i })
.click()
// See it is renamed
getRowForFile('file.md').should('be.visible')
})
it('shows warning on extension change and allow cancellation', () => {
getRowForFile('file.txt').should('be.visible')
triggerActionForFile('file.txt', 'rename')
getRowForFile('file.txt')
.findByRole('textbox', { name: 'Filename' })
.should('be.visible')
.type('{selectAll}file.md')
.should(haveValidity(''))
.type('{enter}')
// See warning dialog
cy.findByRole('dialog', { name: 'Change file extension' })
.should('be.visible')
.findByRole('button', { name: /keep/i })
.click()
// See it is not renamed
getRowForFile('file.txt').should('be.visible')
getRowForFile('file.md').should('not.exist')
})
it('does not show warning on folder renaming with a dot', () => {
createFolder('folder.2024')
getRowForFile('folder.2024').should('be.visible')
triggerActionForFile('folder.2024', 'rename')
getRowForFile('folder.2024')
.findByRole('textbox', { name: 'Folder name' })
.should('be.visible')
.type('{selectAll}folder.2025')
.should(haveValidity(''))
.type('{enter}')
// See warning dialog
cy.get('[role=dialog]').should('not.exist')
// See it is not renamed
getRowForFile('folder.2025').should('be.visible')
})
})