Merge branch 'main' into codex/fix-duplicate-barcode-addition-in-product-table
This commit is contained in:
6 files changed
+192
-13
No files matched your search
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user