Skip to content

Commit

Permalink
Refactor navigation tests to use expect toPass for bounding box check…
Browse files Browse the repository at this point in the history
…s instead of timeout
  • Loading branch information
clari182 committed Dec 19, 2024
1 parent ef1846d commit ed13262
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions site/gatsby-site/playwright/e2e/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ test.describe('Navigation', () => {
const aboutLink = await page.locator('#main-footer .tw-footer-link').filter({ hasText: /^About$/ });
if (await aboutLink.count() > 0) {
await aboutLink.click();

await page.locator('.rightSideTitle:has-text("CONTENTS")').waitFor({ state: 'visible' });
const listItems = await page.locator('.rightSideBarUL li');
expect(await listItems.count()).toBeGreaterThanOrEqual(1);

await listItems.nth(1).click();
await page.waitForTimeout(700);

const subject = await page.locator('h2:has-text(\'Why "AI Incidents"?\')');
const boundingBox = await subject.boundingBox();
expect(boundingBox?.y).toBeCloseTo(0, 30);
await expect(async () => {

const subject = await page.locator('h2:has-text(\'Why "AI Incidents"?\')');
const boundingBox = await subject.boundingBox();
expect(boundingBox?.y).toBeCloseTo(0, 30);
}).toPass();
}
});

Expand All @@ -73,11 +75,12 @@ test.describe('Navigation', () => {
expect(await listItems.count()).toBeGreaterThanOrEqual(1);

await listItems.nth(1).click();
await page.waitForTimeout(700);

const subject = await page.locator('h2:has-text("🗄 Trending in the AIID")');
const boundingBox = await subject.boundingBox();
expect(boundingBox?.y).toBeCloseTo(0, 30);
await expect(async () => {
const subject = await page.locator('h2:has-text("🗄 Trending in the AIID")');
const boundingBox = await subject.boundingBox();
expect(boundingBox?.y).toBeCloseTo(0, 30);
}).toPass();
}
});
});

0 comments on commit ed13262

Please sign in to comment.