Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(renterd): directory rename and delete behaviour #763

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 70 additions & 15 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 @@ -53,9 +54,7 @@ test('can create directory and delete a directory', async ({ page }) => {
await fileInList(page, dirPath2)
})

test('can create directory, upload file, rename file, navigate, delete a file, delete a directory', async ({
page,
}) => {
test('can upload, rename, and delete files', async ({ page }) => {
test.setTimeout(120_000)
const bucketName = 'files-test'
const dirName = 'test-dir'
Expand All @@ -65,14 +64,10 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
const originalFilePath = `${bucketName}/${dirName}/${originalFileName}`
const newFilePath = `${bucketName}/${dirName}/${newFileName}`

// Create bucket and directory.
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)
Expand All @@ -81,7 +76,7 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
).toBeVisible()
await clearToasts({ page })

// Upload.
// Upload a file.
await dragAndDropFile(
page,
`[data-testid=filesDropzone]`,
Expand All @@ -99,20 +94,23 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
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.
// Upload the file again with original name.
await dragAndDropFile(
page,
`[data-testid=filesDropzone]`,
path.join(__dirname, originalFileName),
originalFileName
)
await expect(page.getByText('100%')).toBeVisible()

// Both files exist.
await fileInList(page, originalFilePath)
await fileInList(page, newFilePath)

// Delete one of the files.
await deleteFile(page, newFilePath)
await fileNotInList(page, newFilePath)
await clearToasts({ page })

// Clean up the directory.
await navigateToParentDirectory(page)
Expand All @@ -125,6 +123,63 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
await deleteBucket(page, bucketName)
})

test('can rename and 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
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
Loading