Expand unit and e2e coverage
This commit is contained in:
@@ -32,4 +32,25 @@ test.describe('Active pick list', () => {
|
||||
await expect(page.getByText(additionalProduct).first()).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Save and Return' })).toBeEnabled();
|
||||
});
|
||||
|
||||
test('allows adding and editing products from the manage products screen', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
|
||||
await page.getByRole('link', { name: 'Manage Products' }).click();
|
||||
|
||||
await page.getByLabel('Name').click();
|
||||
await page.getByLabel('Name').fill('Playwright Cola');
|
||||
await page.getByLabel('Category').click();
|
||||
await page.getByRole('option', { name: 'Drinks' }).click();
|
||||
await page.getByRole('button', { name: 'Save Product' }).click();
|
||||
|
||||
await expect(page.getByText('Product added.')).toBeVisible();
|
||||
await expect(page.getByText('Playwright Cola')).toBeVisible();
|
||||
|
||||
await page.getByRole('button', { name: 'Edit Playwright Cola' }).click();
|
||||
await page.getByLabel('Name').nth(1).fill('Playwright Cola Zero');
|
||||
await page.getByRole('button', { name: 'Save product' }).click();
|
||||
|
||||
await expect(page.getByText('Playwright Cola Zero')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,5 +76,28 @@ describe('fetchProductFromOFF', () => {
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null immediately when the barcode is empty', async () => {
|
||||
const result = await fetchProductFromOFF('');
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when the browser is offline', async () => {
|
||||
const originalNavigator = navigator;
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: { onLine: false },
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const result = await fetchProductFromOFF('123456');
|
||||
|
||||
expect(result).toBeNull();
|
||||
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: originalNavigator,
|
||||
configurable: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -165,6 +165,33 @@ describe('ManageProductsScreen barcode lookup', () => {
|
||||
expect(mockDb.products.add).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('informs the user when barcode lookup happens offline', async () => {
|
||||
const originalNavigator = navigator;
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: { onLine: false },
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
try {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<ManageProductsScreen />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /scan barcode/i }));
|
||||
await user.click(screen.getByRole('button', { name: /mock scan/i }));
|
||||
|
||||
expect(await screen.findByText(/you are offline\. enter details manually\./i)).toBeVisible();
|
||||
} finally {
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
value: originalNavigator,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('prevents updating a product to use an existing barcode', async () => {
|
||||
mockUseProducts.mockReturnValue([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user