Skip to content
Merged
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
7 changes: 7 additions & 0 deletions app/pages/project/disks/DisksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export function DisksPage() {
queryClient.invalidateQueries('snapshotList')
addToast({ content: 'Snapshot successfully created' })
},
onError(err) {
addToast({
title: 'Failed to create snapshot',
content: err.message,
variant: 'error',
})
},
})

const makeActions = (disk: Disk): MenuAction[] => [
Expand Down
39 changes: 38 additions & 1 deletion app/test/e2e/disk-create.e2e.ts → app/test/e2e/disks.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,44 @@
*
* Copyright Oxide Computer Company
*/
import { expectVisible, test } from './utils'
import { clickRowAction, expect, expectRowVisible, expectVisible, test } from './utils'

test('List disks and snapshot', async ({ page }) => {
await page.goto('/projects/mock-project/disks')

const table = page.getByRole('table')
await expect(table.getByRole('row')).toHaveCount(12) // 11 + header

// check one attached and one not attached
await expectRowVisible(table, {
'Attached To': 'db1',
Disk: 'disk-1',
Size: '2 GiB',
status: 'attached',
})
await expectRowVisible(table, {
'Attached To': '',
Disk: 'disk-3',
Size: '6 GiB',
status: 'detached',
})

await clickRowAction(page, 'disk-1 db1', 'Snapshot')
await expect(page.getByText("Creating snapshot of disk 'disk-1'").nth(0)).toBeVisible()
await expect(page.getByText('Snapshot successfully created').nth(0)).toBeVisible()
})

test('Disk snapshot error', async ({ page }) => {
await page.goto('/projects/mock-project/disks')

// special disk that triggers snapshot error
await clickRowAction(page, 'disk-snapshot-error', 'Snapshot')
await expect(
page.getByText("Creating snapshot of disk 'disk-snapshot-error'").nth(0)
).toBeVisible()
await expect(page.getByText('Failed to create snapshot').nth(0)).toBeVisible()
await expect(page.getByText('Cannot snapshot disk').nth(0)).toBeVisible()
})

test.describe('Disk create', () => {
test.beforeEach(async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion libs/api-mocks/disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const disks: Json<Disk>[] = [
},
{
id: '3f23c80f-c523-4d86-8292-2ca3f807bb12',
name: 'disk-11',
name: 'disk-snapshot-error',
description: '',
project_id: project.id,
time_created: new Date().toISOString(),
Expand Down
4 changes: 4 additions & 0 deletions libs/api-mocks/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ export const handlers = makeHandlers({
snapshotCreate({ body, query }) {
const project = lookup.project(query)

if (body.disk === 'disk-snapshot-error') {
throw 'Cannot snapshot disk'
}

errIfExists(db.snapshots, { name: body.name })

const disk = lookup.disk({ ...query, disk: body.disk })
Expand Down