Merge branch 'main' into codex/fix-duplicate-barcode-addition-in-product-table

This commit is contained in:
beatz174-bit authored and GitHub committed 2025-11-21 19:20:59 +10:00
commit 1eb5847bd9
6 files changed
+192 -13

No files matched your search

+21
View File
@@ -24,6 +24,9 @@ vi.mock('../hooks/dataHooks', () => ({
useCategories: () => mockUseCategories(),
}));
const productDeleteMock = vi.fn();
const pickItemCountMock = vi.fn();
vi.mock('../context/DBProvider', () => ({
useDatabase: () => mockDb,
}));
@@ -161,3 +164,21 @@ describe('ManageProductsScreen barcode lookup', () => {
});
});
describe('ManageProductsScreen deletion safeguards', () => {
it('blocks deletion when pick items reference the product', async () => {
pickItemCountMock.mockResolvedValueOnce(2);
const user = userEvent.setup();
render(
<MemoryRouter>
<ManageProductsScreen />
</MemoryRouter>,
);
await user.click(screen.getByRole('button', { name: /delete chips/i }));
expect(productDeleteMock).not.toHaveBeenCalled();
expect(await screen.findByText(/cannot delete this product while 2 pick item\(s\) reference it/i)).toBeVisible();
});
});