From 1b957879d4f5e3b9cb397222c7790d1dc8765bf6 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Tue, 17 Jun 2025 20:35:50 +0200 Subject: [PATCH 1/2] Add specs for group update operation --- tests/groups.spec.ts | 9 ++++++++ tests/mocks/groups.tsx | 52 +++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/groups.spec.ts b/tests/groups.spec.ts index 87ab922..90297cb 100644 --- a/tests/groups.spec.ts +++ b/tests/groups.spec.ts @@ -62,4 +62,13 @@ test('should allow CRUD on groups', async ({ page }) => { await expect(page.getByRole('row').nth(1).getByRole('cell').nth(6)).toHaveText('0'); await expect(page.getByRole('row').nth(1).getByRole('cell').nth(7)).toHaveText('0'); await expect(page.getByRole('row').nth(1).locator('svg:visible')).toHaveCount(3); + + // Modify the newly added group + await page.getByRole('row').nth(1).locator('svg').nth(2).click(); // Click edit icon + await expect(dialog).toBeVisible(); + await expect(dialog.getByLabel('Name')).toHaveValue("Pam's friends"); + await dialog.getByLabel('Name').fill('Pam\'s best friends'); + await dialog.getByRole('button', { name: 'Update' }).click(); + + await expect(page.getByRole('row').nth(1).getByRole('cell').nth(0)).toContainText('Pam\'s best friends'); }); \ No newline at end of file diff --git a/tests/mocks/groups.tsx b/tests/mocks/groups.tsx index 317761e..eca9908 100644 --- a/tests/mocks/groups.tsx +++ b/tests/mocks/groups.tsx @@ -39,22 +39,48 @@ export default async function mockGroupsAPI({ page }: { page: Page }): Promise { + if (route.request().method() === 'PUT') { + const json = { + "id": "4d55bc34-6f42-4e2e-82a1-71ae32da2466", + "name": "Pam's best friends", + "icon": "pi pi-desktop", + "parent_id": null, + "color": "#0000ff", + "attendance": { + "total": 0, + "considered": 0, + "invited": 0, + "confirmed": 0, + "declined": 0, + "tentative": 0 + } + } + + await route.fulfill({ json }); + } else if (route.request().method() === 'DELETE') { + const json = {} + + await route.fulfill({ json }); + } + }); } \ No newline at end of file -- 2.47.1 From bcc86f2c3baff3345373a45f3e3398c2dee250fc Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Tue, 17 Jun 2025 20:39:40 +0200 Subject: [PATCH 2/2] Add specs when group is deleted (+ add confirmation dialog) --- app/ui/groups/table.tsx | 7 ++++++- tests/groups.spec.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/ui/groups/table.tsx b/app/ui/groups/table.tsx index d22909c..4b0bc60 100644 --- a/app/ui/groups/table.tsx +++ b/app/ui/groups/table.tsx @@ -21,7 +21,12 @@ export default function GroupsTable({ groups, onUpdate, onEdit, onEditAffinities const actions = (group: Group) => (
- { api.destroy(serializer, group, onUpdate) }} /> + { + if (window.confirm(`Are you sure you want to delete guest "${group.name}"?`)) { + api.destroy(serializer, group, onUpdate) + } + }} + /> onEdit(group)} /> onEditAffinities(group)} />
diff --git a/tests/groups.spec.ts b/tests/groups.spec.ts index 90297cb..a22cab4 100644 --- a/tests/groups.spec.ts +++ b/tests/groups.spec.ts @@ -52,6 +52,8 @@ test('should allow CRUD on groups', async ({ page }) => { await dialog.getByLabel('Name').fill("Pam's friends"); await dialog.getByRole('button', { name: 'Create' }).click(); + await expect(page.getByRole('row')).toHaveCount(4); // 1 header row + 3 data rows + await expect(dialog).not.toBeVisible(); await expect(page.getByRole('row').nth(1).getByRole('cell').nth(0)).toContainText('Pam\'s friends'); @@ -71,4 +73,10 @@ test('should allow CRUD on groups', async ({ page }) => { await dialog.getByRole('button', { name: 'Update' }).click(); await expect(page.getByRole('row').nth(1).getByRole('cell').nth(0)).toContainText('Pam\'s best friends'); + + // Delete the newly added group + page.on('dialog', dialog => dialog.accept()); + + await page.getByRole('row').nth(1).locator('svg').nth(1).click(); // Click delete icon + await expect(page.getByRole('row')).toHaveCount(3); // 1 header row + 2 data rows }); \ No newline at end of file -- 2.47.1