Skip to content

Commit 591fe19

Browse files
committed
Tests: Fix issue where consent pops up after click event
1 parent 413c7ed commit 591fe19

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

layouts/partials/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
{{ partial "lucide" (dict "context" . "icon" "chevron-down") }}
4444
</span>
4545
</button>
46-
<div class="dropdown-content" id="dropdown-content" data-testid="header__f5sites_content">
46+
<div class="dropdown-content" id="dropdown-content" data-testid="header__f5sites__content">
4747
<ul>
4848
{{ range $f5Sites }}
4949
<li>

tests/src/header.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test.describe('Smoke test for header', () => {
4646
test('F5 Sites button works', async ({ page }) => {
4747
const f5SitesButton = await page.getByTestId('header__f5sites__button');
4848
await f5SitesButton.click();
49-
const f5SitesContent = await page.getByTestId('header__f5sites_content');
49+
const f5SitesContent = await page.getByTestId('header__f5sites__content');
5050
await expect(f5SitesContent.count()).toBeTruthy();
5151
});
5252
});

tests/src/sidebar.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ test.describe('Smoke test for sidebar', () => {
5656
test('each section page on sidebar renders', async ({ page }) => {
5757
/* Click on each link */
5858
const sidebarPages = await page.getByTestId('sidebar__page').all();
59+
let i = 0;
5960
for (const sidebarPage of sidebarPages) {
60-
await waitFor(async () => await handleConsentPopup(page));
61+
await waitFor(async () => await handleConsentPopup(page, i > 0));
6162
await openPage(page, sidebarPage);
6263
await runSmokeTestOnPage(page);
64+
i += 1;
6365
}
6466
});
6567
});

tests/src/util.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ export async function runSmokeTestOnPage(page) {
1111
}
1212

1313
// THE GDPR Consent button appears when test is run from EU locations. This handles that popup.
14-
export async function handleConsentPopup(page) {
15-
const consentContent = page.locator('#truste-consent-content');
16-
const isConsentContentVisibile = await consentContent.isVisible();
17-
if (isConsentContentVisibile) {
18-
const consentButton = page.locator('#truste-consent-required');
19-
expect(consentButton).toBeVisible();
20-
await consentButton.click();
14+
export async function handleConsentPopup(page, isClickedAlready = false) {
15+
if (isClickedAlready) {
16+
return;
2117
}
18+
const consentContent = page.locator('#truste-consent-content');
19+
await consentContent.waitFor({ state: 'visible' });
20+
const consentButton = page.locator('#truste-consent-required');
21+
expect(consentButton).toBeVisible();
22+
await consentButton.click();
2223
}
2324

2425
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

0 commit comments

Comments
 (0)