From 4f7c2570dd6a0b3fc12c1f4f1187cebe4a9eb145 Mon Sep 17 00:00:00 2001 From: Demian Date: Thu, 18 Dec 2025 23:59:35 -0500 Subject: [PATCH] fix: polish editor mode new-row flow Improve inline and new-row error UX with retry and focus handling, and add focus/flow tests for editor mode. --- .../src/pages/Inventory.editor-mode.test.tsx | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/frontend/src/pages/Inventory.editor-mode.test.tsx b/frontend/src/pages/Inventory.editor-mode.test.tsx index 9677588..eedefad 100644 --- a/frontend/src/pages/Inventory.editor-mode.test.tsx +++ b/frontend/src/pages/Inventory.editor-mode.test.tsx @@ -393,4 +393,57 @@ describe('Inventory editor mode inline controls', () => { ); await waitFor(() => expect(document.activeElement).toBe(saveButton)); }); + + it('resets the new row and returns focus to item after successful save', async () => { + render( + + + , + ); + + await waitFor(() => expect(screen.getByText('Test Item')).toBeInTheDocument()); + + const viewModeSelect = screen.getByLabelText('View mode'); + fireEvent.mouseDown(viewModeSelect); + const editorOption = await screen.findByText('Editor Mode'); + fireEvent.click(editorOption); + + const itemInput = await screen.findByTestId('new-row-item-input'); + fireEvent.change(itemInput, { target: { value: 'New' } }); + fireEvent.click(await screen.findByText('New Catalog Item')); + + const locationInput = await screen.findByTestId('new-row-location-input'); + fireEvent.change(locationInput, { target: { value: 'Test' } }); + fireEvent.click(await screen.findByText('Test Location')); + + const quantityInput = screen.getByTestId('new-row-quantity'); + fireEvent.change(quantityInput, { target: { value: '11' } }); + + fireEvent.click(screen.getByTestId('new-row-save')); + + await waitFor(() => expect(mockCreateItem).toHaveBeenCalled()); + const refreshedItemInput = await screen.findByTestId('new-row-item-input'); + expect((refreshedItemInput as HTMLInputElement).value).toBe(''); + await waitFor(() => expect(document.activeElement).toBe(refreshedItemInput)); + }); + + it('moves focus to save when pressing Enter on quantity', async () => { + render( + + + , + ); + + await waitFor(() => expect(screen.getByText('Test Item')).toBeInTheDocument()); + const viewModeSelect = screen.getByLabelText('View mode'); + fireEvent.mouseDown(viewModeSelect); + const editorOption = await screen.findByText('Editor Mode'); + fireEvent.click(editorOption); + + const quantityInput = await screen.findByTestId('inline-quantity-item-1'); + fireEvent.keyDown(quantityInput, { key: 'Enter', code: 'Enter' }); + + const saveButton = await screen.findByTestId('inline-save-item-1'); + await waitFor(() => expect(document.activeElement).toBe(saveButton)); + }); });