Skip to content

Commit 73b48d0

Browse files
committed
feat: add e2e test
1 parent 01492c8 commit 73b48d0

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.afterEach("Cleanup session", async ({ page }) => {
4+
// Because the test isolation that will open a new session for every test executed, and that exceeds Mendix's license limit of 5 sessions, so we need to force logout after each test.
5+
await page.evaluate(() => window.mx.session.logout());
6+
});
7+
8+
test.beforeEach(async ({ page }) => {
9+
await page.goto("/");
10+
});
11+
12+
test.describe("SkipLink:", function () {
13+
test("skip link is present in DOM but initially hidden", async ({ page }) => {
14+
// Skip link should be in the DOM but not visible
15+
const skipLink = page.locator(".skip-link").first();
16+
await expect(skipLink).toBeAttached();
17+
18+
// Check initial styling (hidden)
19+
const transform = await skipLink.evaluate(el => getComputedStyle(el).transform);
20+
expect(transform).toContain("translateY(-120%)") || expect(transform).toContain("matrix");
21+
});
22+
23+
test("skip link becomes visible when focused via keyboard", async ({ page }) => {
24+
// Tab to focus the skip link (should be first focusable element)
25+
await page.keyboard.press("Tab");
26+
27+
const skipLink = page.locator(".skip-link").first();
28+
await expect(skipLink).toBeFocused();
29+
30+
// Check that it becomes visible when focused
31+
const transform = await skipLink.evaluate(el => getComputedStyle(el).transform);
32+
expect(transform).toContain("translateY(0px)") || expect(transform).toBe("none");
33+
});
34+
35+
test("skip link navigates to main content when activated", async ({ page }) => {
36+
// Create a main content element to test focus behavior
37+
await page.evaluate(() => {
38+
const main = document.createElement("main");
39+
main.id = "main-content";
40+
main.textContent = "Main content area";
41+
document.body.appendChild(main);
42+
});
43+
44+
// Tab to focus the skip link
45+
await page.keyboard.press("Tab");
46+
47+
const skipLink = page.locator(".skip-link").first();
48+
await expect(skipLink).toBeFocused();
49+
50+
// Activate the skip link
51+
await page.keyboard.press("Enter");
52+
53+
// Check that main content is now focused
54+
const mainContent = page.locator("#main-content");
55+
await expect(mainContent).toBeFocused();
56+
});
57+
58+
test("skip link has correct attributes and text", async ({ page }) => {
59+
const skipLink = page.locator(".skip-link").first();
60+
61+
// Check default text
62+
await expect(skipLink).toHaveText("Skip to main content");
63+
64+
// Check href attribute
65+
await expect(skipLink).toHaveAttribute("href", "#main-content");
66+
67+
// Check tabindex
68+
await expect(skipLink).toHaveAttribute("tabindex", "0");
69+
70+
// Check CSS class
71+
await expect(skipLink).toHaveClass("skip-link");
72+
});
73+
74+
test("visual comparison", async ({ page }) => {
75+
// Tab to make skip link visible for screenshot
76+
await page.keyboard.press("Tab");
77+
78+
const skipLink = page.locator(".skip-link").first();
79+
await expect(skipLink).toBeFocused();
80+
81+
// Visual comparison of focused skip link
82+
await expect(skipLink).toHaveScreenshot("skiplink-focused.png");
83+
});
84+
});

0 commit comments

Comments
 (0)