From 86cd6c7bd26b271be4445563abd1ef85a923cd57 Mon Sep 17 00:00:00 2001 From: albert-schilling Date: Wed, 6 Sep 2023 15:21:17 +0200 Subject: [PATCH 1/2] Add insert case --- packages/conform-react/hooks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/conform-react/hooks.ts b/packages/conform-react/hooks.ts index ffb65ed2..974dd8f5 100644 --- a/packages/conform-react/hooks.ts +++ b/packages/conform-react/hooks.ts @@ -738,6 +738,7 @@ export function useFieldList | undefined>( switch (intent.payload.operation) { case 'append': case 'prepend': + case 'insert': case 'replace': errorList = updateList(errorList, { ...intent.payload, From 8de8c16e6007b8400ac5d63d21fd831b59a7541f Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Thu, 7 Sep 2023 18:46:41 +0200 Subject: [PATCH 2/2] test insert with default value --- playground/app/routes/simple-list.tsx | 2 +- tests/integrations/simple-list.spec.ts | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/playground/app/routes/simple-list.tsx b/playground/app/routes/simple-list.tsx index efe79fd7..bcbd4fe1 100644 --- a/playground/app/routes/simple-list.tsx +++ b/playground/app/routes/simple-list.tsx @@ -84,7 +84,7 @@ export default function SimpleList() {
diff --git a/tests/integrations/simple-list.spec.ts b/tests/integrations/simple-list.spec.ts index dff7784a..cbcdd995 100644 --- a/tests/integrations/simple-list.spec.ts +++ b/tests/integrations/simple-list.spec.ts @@ -52,15 +52,15 @@ async function runValidationScenario(page: Page) { // Insert a new row await fieldset.insertTop.click(); await expect(fieldset.items).toHaveCount(1); - await expect(item0.content).toHaveValue(''); + await expect(item0.content).toHaveValue('Top item'); // Type `Another Item` on first row - await item0.content.type('Another item'); + await item0.content.fill('Another item'); // Insert a new row on top await fieldset.insertTop.click(); await expect(fieldset.items).toHaveCount(2); - await expect(item0.content).toHaveValue(''); + await expect(item0.content).toHaveValue('Top item'); await expect(item1.content).toHaveValue('Another item'); // Insert a new row at the bottom @@ -72,14 +72,14 @@ async function runValidationScenario(page: Page) { '', '', ]); - await expect(item0.content).toHaveValue(''); + await expect(item0.content).toHaveValue('Top item'); await expect(item1.content).toHaveValue('Another item'); await expect(item2.content).toHaveValue(''); await playground.submit.click(); await expect(playground.error).toHaveText([ 'Maximum 2 items are allowed', - 'The field is required', + '', '', 'The field is required', ]); @@ -122,7 +122,7 @@ async function runValidationScenario(page: Page) { await playground.submit.click(); await expect(playground.error).toHaveText(['', 'The field is required', '']); - await item0.content.type('Top item'); + await item0.content.type('Last item'); // Trigger revalidation await playground.submit.click(); @@ -132,11 +132,11 @@ async function runValidationScenario(page: Page) { { intent: 'submit', payload: { - items: ['Top item', 'Another item'], + items: ['Last item', 'Another item'], }, error: {}, value: { - items: ['Top item', 'Another item'], + items: ['Last item', 'Another item'], }, }, null, @@ -161,12 +161,14 @@ async function testListDefaultValue(page: Page, shouldReset?: boolean) { await fieldset.insertTop.click(); await expect(fieldset.items).toHaveCount(2); - await expect(item0.content).toHaveValue(''); + await expect(item0.content).toHaveValue('Top item'); await expect(item1.content).toHaveValue('default item 1'); await item1.delete.click(); await expect(fieldset.items).toHaveCount(1); - await expect(item0.content).toHaveValue(''); + await expect(item0.content).toHaveValue('Top item'); + + await item0.content.fill(''); await playground.submit.click(); await expect(fieldset.items).toHaveCount(1);