Skip to content

Commit

Permalink
test(renterd): directory rename and delete behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Oct 2, 2024
1 parent 9ddc44b commit f0a12f3
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
130 changes: 130 additions & 0 deletions apps/renterd-e2e/src/specs/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
openDirectory,
openFileContextMenu,
createDirectory,
openDirectoryContextMenu,
} from '../fixtures/files'
import { fillTextInputByName } from '../fixtures/textInput'
import { clearToasts } from '../fixtures/clearToasts'
Expand Down Expand Up @@ -125,6 +126,135 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
await deleteBucket(page, bucketName)
})

test('can delete a directory with contents', async ({ page }) => {
test.setTimeout(120_000)
const bucketName = 'files-test'
const dirName = 'test-dir'
const originalFileName = 'sample.txt'
const newFileName = 'renamed.txt'
const dirPath = `${bucketName}/${dirName}/`
const originalFilePath = `${bucketName}/${dirName}/${originalFileName}`
const newFilePath = `${bucketName}/${dirName}/${newFileName}`

await navigateToBuckets({ page })
await createBucket(page, bucketName)
await openBucket(page, bucketName)
await expect(
page.getByText('bucket does not contain any files')
).toBeVisible()

// Create directory.
await createDirectory(page, dirName)
await fileInList(page, dirPath)
await openDirectory(page, dirPath)
await expect(
page.getByText('The current directory does not contain any files yet')
).toBeVisible()
await clearToasts({ page })

// Upload.
await dragAndDropFile(
page,
`[data-testid=filesDropzone]`,
path.join(__dirname, originalFileName),
originalFileName
)
await expect(page.getByText('100%')).toBeVisible()
await fileInList(page, originalFilePath)

// Rename file.
await openFileContextMenu(page, originalFilePath)
await page.getByRole('menuitem', { name: 'Rename file' }).click()
await fillTextInputByName(page, 'name', newFileName)
await page.locator('input[name=name]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
await fileInList(page, newFilePath)

// Delete file.
await deleteFile(page, newFilePath)
await fileNotInList(page, newFilePath)
await clearToasts({ page })

// Upload the file again.
await dragAndDropFile(
page,
`[data-testid=filesDropzone]`,
path.join(__dirname, originalFileName),
originalFileName
)
await expect(page.getByText('100%')).toBeVisible()
await fileInList(page, originalFilePath)

// Clean up the directory.
await navigateToParentDirectory(page)
await fileInList(page, dirPath)
await deleteDirectory(page, dirPath)
await fileNotInList(page, dirPath)

// Clean up the bucket.
await navigateToBuckets({ page })
await deleteBucket(page, bucketName)
})

test('can rename and then delete a directory with contents', async ({
page,
}) => {
test.setTimeout(120_000)
const bucketName = 'files-test'
const dirName = 'a'
const newDirName = 'b'
const fileName = 'sample.txt'
const dirPath = `${bucketName}/${dirName}/`
const newDirPath = `${bucketName}/${newDirName}/`
const originalFilePath = `${bucketName}/${dirName}/${fileName}`
const newFilePath = `${bucketName}/${newDirName}/${fileName}`

// Create bucket and directory.
await navigateToBuckets({ page })
await createBucket(page, bucketName)
await openBucket(page, bucketName)
await createDirectory(page, dirName)
await fileInList(page, dirPath)
await openDirectory(page, dirPath)
await expect(
page.getByText('The current directory does not contain any files yet')
).toBeVisible()
await clearToasts({ page })

// Upload a file.
await dragAndDropFile(
page,
`[data-testid=filesDropzone]`,
path.join(__dirname, fileName),
fileName
)
await expect(page.getByText('100%')).toBeVisible()
await fileInList(page, originalFilePath)

// Rename directory.
await navigateToParentDirectory(page)
await openDirectoryContextMenu(page, dirPath)
await page.getByRole('menuitem', { name: 'Rename directory' }).click()
await fillTextInputByName(page, 'name', newDirName)
await page.locator('input[name=name]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
await fileInList(page, newDirPath)

// File still inside renamed directory.
await openDirectory(page, newDirPath)
await fileInList(page, newFilePath)
await navigateToParentDirectory(page)

// Delete directory.
await deleteDirectory(page, newDirPath)
await fileNotInList(page, newDirPath)

// Confirm no files or directories remain.
await expect(
page.getByText('The current directory does not contain any files yet')
).toBeVisible()
})

test('shows a new intermediate directory when uploading nested files', async ({
page,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/dialogs/FileRenameDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function FileRenameDialog({ trigger, open, onOpenChange }: Props) {
const response = await objectRename.post({
payload: {
bucket,
to,
to: to.slice(1),
from,
mode,
force: false,
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/lib/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

type Id = string | number

// Parameters for moving a directory or file to drag destination
// Parameters for moving a directory or file to drag destination.
export function getMoveFileRenameParams(
e: { active: { id: Id }; collisions: { id: Id }[] | null },
activeDirectory: FullPathSegments
Expand All @@ -39,7 +39,7 @@ export function getMoveFileRenameParams(
} as const
}

// Parameters for renaming the name of a file or directory
// Parameters for renaming the name of a file or directory.
export function getRenameFileRenameParams(path: FullPath, newName: string) {
let to = join(getParentDirectoryPath(path), newName)
const isDir = isDirectory(path)
Expand Down

0 comments on commit f0a12f3

Please sign in to comment.