Skip to content

Commit

Permalink
refactor(renterd): remove default bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 25, 2024
1 parent 054a763 commit 6ef4cb5
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-ligers-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The bucket list now has an empty state.
5 changes: 5 additions & 0 deletions .changeset/gentle-grapes-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The cmdk menu now has an two separate files search options, one for across all buckets and one for the current bucket.
5 changes: 5 additions & 0 deletions .changeset/honest-books-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

It is now possible to delete a bucket named 'default'.
5 changes: 5 additions & 0 deletions .changeset/proud-rules-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The file search feature can now search across all buckets.
2 changes: 1 addition & 1 deletion apps/renterd-e2e/src/fixtures/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { deleteDirectory, deleteFile } from './files'

export async function createBucket(page: Page, name: string) {
await navigateToBuckets({ page })
await page.getByText('Create bucket').click()
await page.getByText('Create bucket').first().click()
await fillTextInputByName(page, 'name', name)
await page.locator('input[name=name]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
Expand Down
10 changes: 10 additions & 0 deletions apps/renterd-e2e/src/fixtures/cmdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Page, expect } from '@playwright/test'

export async function openCmdkMenu(page: Page) {
const isMac = process.platform === 'darwin'
const modifier = isMac ? 'Meta' : 'Control'
await page.keyboard.press(`${modifier}+k`)
const dialog = page.getByRole('dialog')
await expect(dialog.locator('div[cmdk-root]')).toBeVisible()
return dialog
}
13 changes: 10 additions & 3 deletions apps/renterd-e2e/src/fixtures/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ export async function openDirectory(page: Page, path: string) {
}

export async function navigateToParentDirectory(page: Page) {
await page.getByRole('cell', { name: '..' }).click()
const isEmpty = await page
.getByText('The current directory does not contain any files yet')
.isVisible()
if (isEmpty) {
await page.getByRole('button', { name: 'Back' }).click()
} else {
await page.getByRole('cell', { name: '..' }).click()
}
}

export async function crateDirectory(page: Page, name: string) {
export async function createDirectory(page: Page, name: string) {
await expect(page.getByLabel('Create directory')).toBeVisible()
await page.getByLabel('Create directory').click()
await fillTextInputByName(page, 'name', name)
Expand All @@ -86,7 +93,7 @@ export async function createDirectoryIfNotExists(page: Page, name: string) {
.getByTestId(name)
.isVisible()
if (!exists) {
await crateDirectory(page, name)
await createDirectory(page, name)
}
}

Expand Down
15 changes: 9 additions & 6 deletions apps/renterd-e2e/src/specs/buckets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
bucketInList,
createBucket,
deleteBucket,
deleteBucketIfExists,
openBucketContextMenu,
} from '../fixtures/buckets'
import { afterTest, beforeTest } from '../fixtures/beforeTest'
Expand All @@ -18,19 +17,23 @@ test.afterEach(async () => {
})

test('can change a buckets policy', async ({ page }) => {
const bucketName = 'bucket1'
await navigateToBuckets({ page })
await openBucketContextMenu(page, 'default')
await expect(page.getByText('Create a bucket to get started.')).toBeVisible()
await createBucket(page, bucketName)
await openBucketContextMenu(page, bucketName)
await page.getByRole('menuitem', { name: 'Change policy' }).click()
await page.getByRole('heading', { name: 'Change Policy: default' }).click()
await page.getByRole('combobox').selectOption('public')
await page.getByRole('button', { name: 'Update policy' }).click()
await expect(page.getByText('Bucket policy has been updated')).toBeVisible()
await bucketInList(page, 'default')
await bucketInList(page, bucketName)
})

test('can create and delete a bucket', async ({ page }) => {
const bucketName = 'my-new-bucket'
await navigateToBuckets({ page })
await deleteBucketIfExists(page, 'my-new-bucket')
await createBucket(page, 'my-new-bucket')
await deleteBucket(page, 'my-new-bucket')
await expect(page.getByText('Create a bucket to get started.')).toBeVisible()
await createBucket(page, bucketName)
await deleteBucket(page, bucketName)
})
58 changes: 37 additions & 21 deletions apps/renterd-e2e/src/specs/files.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { test, expect } from '@playwright/test'
import { navigateToBuckets } from '../fixtures/navigate'
import {
createBucket,
deleteBucketIfExists,
openBucket,
} from '../fixtures/buckets'
import { createBucket, deleteBucket, openBucket } from '../fixtures/buckets'
import path from 'path'
import {
createDirectoryIfNotExists,
deleteDirectoryIfExists,
deleteFileIfExists,
deleteDirectory,
deleteFile,
dragAndDropFile,
fileInList,
fileNotInList,
getFileRowById,
navigateToParentDirectory,
openDirectory,
openFileContextMenu,
createDirectory,
} from '../fixtures/files'
import { fillTextInputByName } from '../fixtures/textInput'
import { clearToasts } from '../fixtures/clearToasts'
Expand All @@ -32,28 +28,49 @@ test.afterEach(async () => {
await afterTest()
})

test('can create directory and delete a directory', async ({ page }) => {
test.setTimeout(80_000)
const bucketName = 'files-test'
const dirName = 'test-dir'
const dirPath = `${bucketName}/${dirName}/`

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 navigateToParentDirectory(page)
await deleteDirectory(page, dirPath)
await fileNotInList(page, dirPath)
})

test('can create directory, upload file, rename file, navigate, delete a file, delete a directory', async ({
page,
}) => {
test.setTimeout(80_000)
const bucketName = 'files-test'
const dirName = `test-dir-${Date.now()}`
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 deleteBucketIfExists(page, bucketName)
await createBucket(page, bucketName)
await openBucket(page, bucketName)
await expect(
page.getByText('bucket does not contain any files')
).toBeVisible()

// Create directory.
await createDirectoryIfNotExists(page, dirName)
await createDirectory(page, dirName)
await fileInList(page, dirPath)
await openDirectory(page, dirPath)
await expect(
Expand All @@ -74,13 +91,13 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
// Rename file.
await openFileContextMenu(page, originalFilePath)
await page.getByRole('menuitem', { name: 'Rename file' }).click()
await fillTextInputByName(page, 'name', 'renamed.txt')
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 deleteFileIfExists(page, newFilePath)
await deleteFile(page, newFilePath)
await fileNotInList(page, newFilePath)
await clearToasts({ page })

Expand All @@ -97,20 +114,20 @@ test('can create directory, upload file, rename file, navigate, delete a file, d
// Clean up the directory.
await navigateToParentDirectory(page)
await fileInList(page, dirPath)
await deleteDirectoryIfExists(page, dirPath)
await deleteDirectory(page, dirPath)
await fileNotInList(page, dirPath)

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

test('shows a new intermediate directory when uploading nested files', async ({
page,
}) => {
test.setTimeout(80_000)
const bucketName = 'files-test'
const containerDir = `test-dir-${Date.now()}`
const containerDir = 'test-dir'
const containerDirPath = `${bucketName}/${containerDir}/`
const systemDir = 'nested-sample'
const systemFile = 'sample.txt'
Expand All @@ -119,15 +136,14 @@ test('shows a new intermediate directory when uploading nested files', async ({
const filePath = `${dirPath}${systemFile}`

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

// Create a container directory for the test.
await createDirectoryIfNotExists(page, containerDir)
await createDirectory(page, containerDir)
await fileInList(page, containerDirPath)
await openDirectory(page, containerDirPath)
await expect(
Expand Down Expand Up @@ -163,10 +179,10 @@ test('shows a new intermediate directory when uploading nested files', async ({
// Clean up the container directory.
await navigateToParentDirectory(page)
await fileInList(page, containerDirPath)
await deleteDirectoryIfExists(page, containerDirPath)
await deleteDirectory(page, containerDirPath)
await fileNotInList(page, containerDirPath)

// Clean up the bucket.
// Delete the bucket once its empty.
await navigateToBuckets({ page })
await deleteBucketIfExists(page, bucketName)
await deleteBucket(page, bucketName)
})
124 changes: 124 additions & 0 deletions apps/renterd-e2e/src/specs/search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { expect, test } from '@playwright/test'
import { navigateToBuckets } from '../fixtures/navigate'
import { createBucket, openBucket } from '../fixtures/buckets'
import { createDirectory } from '../fixtures/files'
import { afterTest, beforeTest } from '../fixtures/beforeTest'
import { fillTextInputByName } from '../fixtures/textInput'
import { openCmdkMenu } from '../fixtures/cmdk'

test.beforeEach(async ({ page }) => {
await beforeTest(page, {
hostdCount: 3,
})
})

test.afterEach(async () => {
await afterTest()
})

test('can search for a file within a bucket via the actions menu', async ({
page,
}) => {
test.setTimeout(80_000)
await navigateToBuckets({ page })
await createBucket(page, 'bucket-1')
await openBucket(page, 'bucket-1')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await navigateToBuckets({ page })
await createBucket(page, 'bucket-2')
await openBucket(page, 'bucket-2')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await page.getByLabel('search files').click()
const dialog = page.getByRole('dialog')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(2)
await expect(dialog.getByText('bucket-2')).toBeVisible()
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toBeVisible()
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-2')
).toBeVisible()
await fillTextInputByName(page, 'search files', 'foobar-1')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(1)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toBeVisible()
})

test('can search for a file within a bucket via the cmdk menu', async ({
page,
}) => {
test.setTimeout(80_000)
await navigateToBuckets({ page })
await createBucket(page, 'bucket-1')
await openBucket(page, 'bucket-1')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await navigateToBuckets({ page })
await createBucket(page, 'bucket-2')
await openBucket(page, 'bucket-2')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await page.getByLabel('search files').click()
const dialog = await openCmdkMenu(page)
await fillTextInputByName(page, 'cmdk-input', 'search files in bucket')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(1)
await dialog
.locator('div[cmdk-item]')
.getByText('search files in bucket')
.click()
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(2)
await expect(dialog.getByText('bucket-2')).toBeVisible()
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toBeVisible()
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-2')
).toBeVisible()
await fillTextInputByName(page, 'cmdk-input', 'foobar-1')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(1)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toBeVisible()
})

test('can search for a file across all buckets', async ({ page }) => {
test.setTimeout(80_000)
await navigateToBuckets({ page })
await createBucket(page, 'bucket-1')
await openBucket(page, 'bucket-1')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await navigateToBuckets({ page })
await createBucket(page, 'bucket-2')
await openBucket(page, 'bucket-2')
await createDirectory(page, 'foobar-1')
await createDirectory(page, 'foobar-2')
await page.focus('body')
const dialog = await openCmdkMenu(page)
await fillTextInputByName(page, 'cmdk-input', 'search all files')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(1)
await dialog.locator('div[cmdk-item]').getByText('search all files').click()
await expect(
dialog.locator('div[cmdk-item]').getByText('bucket-1')
).toHaveCount(2)
await expect(
dialog.locator('div[cmdk-item]').getByText('bucket-2')
).toHaveCount(2)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toHaveCount(2)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-2')
).toHaveCount(2)
await fillTextInputByName(page, 'cmdk-input', 'foobar-1')
await expect(dialog.locator('div[cmdk-item]')).toHaveCount(2)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-1')
).toHaveCount(2)
await expect(
dialog.locator('div[cmdk-item]').getByText('foobar-2')
).toHaveCount(0)
})
Loading

0 comments on commit 6ef4cb5

Please sign in to comment.