Skip to content

Commit 1936e0d

Browse files
authored
Toast on error when snapshotting from disks list (#1948)
* snapshot error toast * test snapshot from disks list
1 parent cfda163 commit 1936e0d

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

app/pages/project/disks/DisksPage.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export function DisksPage() {
9292
queryClient.invalidateQueries('snapshotList')
9393
addToast({ content: 'Snapshot successfully created' })
9494
},
95+
onError(err) {
96+
addToast({
97+
title: 'Failed to create snapshot',
98+
content: err.message,
99+
variant: 'error',
100+
})
101+
},
95102
})
96103

97104
const makeActions = (disk: Disk): MenuAction[] => [
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,44 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
import { expectVisible, test } from './utils'
8+
import { clickRowAction, expect, expectRowVisible, expectVisible, test } from './utils'
9+
10+
test('List disks and snapshot', async ({ page }) => {
11+
await page.goto('/projects/mock-project/disks')
12+
13+
const table = page.getByRole('table')
14+
await expect(table.getByRole('row')).toHaveCount(12) // 11 + header
15+
16+
// check one attached and one not attached
17+
await expectRowVisible(table, {
18+
'Attached To': 'db1',
19+
Disk: 'disk-1',
20+
Size: '2 GiB',
21+
status: 'attached',
22+
})
23+
await expectRowVisible(table, {
24+
'Attached To': '',
25+
Disk: 'disk-3',
26+
Size: '6 GiB',
27+
status: 'detached',
28+
})
29+
30+
await clickRowAction(page, 'disk-1 db1', 'Snapshot')
31+
await expect(page.getByText("Creating snapshot of disk 'disk-1'").nth(0)).toBeVisible()
32+
await expect(page.getByText('Snapshot successfully created').nth(0)).toBeVisible()
33+
})
34+
35+
test('Disk snapshot error', async ({ page }) => {
36+
await page.goto('/projects/mock-project/disks')
37+
38+
// special disk that triggers snapshot error
39+
await clickRowAction(page, 'disk-snapshot-error', 'Snapshot')
40+
await expect(
41+
page.getByText("Creating snapshot of disk 'disk-snapshot-error'").nth(0)
42+
).toBeVisible()
43+
await expect(page.getByText('Failed to create snapshot').nth(0)).toBeVisible()
44+
await expect(page.getByText('Cannot snapshot disk').nth(0)).toBeVisible()
45+
})
946

1047
test.describe('Disk create', () => {
1148
test.beforeEach(async ({ page }) => {

libs/api-mocks/disk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const disks: Json<Disk>[] = [
135135
},
136136
{
137137
id: '3f23c80f-c523-4d86-8292-2ca3f807bb12',
138-
name: 'disk-11',
138+
name: 'disk-snapshot-error',
139139
description: '',
140140
project_id: project.id,
141141
time_created: new Date().toISOString(),

libs/api-mocks/msw/handlers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ export const handlers = makeHandlers({
742742
snapshotCreate({ body, query }) {
743743
const project = lookup.project(query)
744744

745+
if (body.disk === 'disk-snapshot-error') {
746+
throw 'Cannot snapshot disk'
747+
}
748+
745749
errIfExists(db.snapshots, { name: body.name })
746750

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

0 commit comments

Comments
 (0)