Skip to content

Commit 2d9dbf1

Browse files
author
RobJellinghaus
committed
Supplier cleanup works!
1 parent 441554b commit 2d9dbf1

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

tests/suppliers.spec.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,56 @@ test.describe('Supplier Tests', () => {
1010
await page.click('a:has-text("Suppliers")');
1111
await page.waitForLoadState('networkidle');
1212

13+
// Wait for React Suspense to resolve and suppliers to load
14+
await page.waitForSelector('h1:has-text("Suppliers")', { timeout: 5000 });
15+
16+
// Wait for either suppliers to load or empty state to appear
17+
try {
18+
await page.waitForFunction(() => {
19+
const deleteLinks = Array.from(document.querySelectorAll('a')).filter(a => a.textContent?.includes('delete'));
20+
const hasSuppliers = deleteLinks.length > 0;
21+
const hasEmptyState = document.textContent?.includes('No suppliers found. Create one to get started!');
22+
return hasSuppliers || hasEmptyState;
23+
}, { timeout: 5000 });
24+
} catch (e) {
25+
console.log('Timeout waiting for suppliers to load or empty state to appear');
26+
}
27+
28+
// Debug: Check what's actually on the page
29+
const pageContent = await page.locator('body').innerHTML();
30+
console.log('Page content length:', pageContent.length);
31+
const deleteButtons = await page.locator('a:has-text("delete")').all();
32+
console.log('Found delete buttons:', deleteButtons.length);
33+
const suppliers = await page.locator('.Form').all();
34+
console.log('Found Form elements:', suppliers.length);
35+
1336
// Delete any existing suppliers
1437
let deleteCount = 0;
15-
while (((await page.locator('a:has-text("delete")').all()).length) > 0 && deleteCount < 10) {
38+
while (((await page.locator('a:has-text("delete")').all()).length) > 0) {
1639
console.log('Found existing supplier, deleting...');
17-
await page.locator('a:has-text("delete")').first().click();
1840

19-
// Accept the confirmation dialog
20-
page.on('dialog', dialog => dialog.accept());
41+
// Set up dialog handler BEFORE clicking
42+
const dialogPromise = new Promise<void>((resolve) => {
43+
const handler = (dialog) => {
44+
dialog.accept();
45+
page.off('dialog', handler); // Remove handler after use
46+
resolve();
47+
};
48+
page.on('dialog', handler);
49+
});
50+
51+
await page.locator('a:has-text("delete")').first().click();
52+
await dialogPromise; // Wait for dialog to be handled
2153

2254
await page.waitForLoadState('networkidle');
2355
await new Promise(resolve => setTimeout(resolve, 100));
2456
deleteCount++;
2557
}
2658

2759
console.log(`Cleaned up ${deleteCount} existing suppliers`);
60+
61+
// Verify empty state is shown
62+
await expect(page.locator('text=No suppliers found. Create one to get started!')).toBeVisible();
2863
});
2964

3065
test('should display suppliers page', async ({ page }) => {

0 commit comments

Comments
 (0)