Skip to content

Commit 37473c3

Browse files
committed
fix: nav menu tests
1 parent a71ed70 commit 37473c3

File tree

3 files changed

+99
-10
lines changed

3 files changed

+99
-10
lines changed

e2e/models/navigation-menu.model.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class NavigationMenuModel extends Model {
2727
return this.page.locator(`[data-scope="navigation-menu"][data-part="viewport"]`)
2828
}
2929

30-
getLink(value: string, text: string) {
30+
getLink(value: string) {
31+
return this.page.locator(`[data-scope="navigation-menu"][data-part="link"][data-value="${value}"]`)
32+
}
33+
34+
getContentLink(value: string, text: string) {
3135
return this.getContent(value).locator("a", { hasText: text })
3236
}
3337

@@ -52,6 +56,14 @@ export class NavigationMenuModel extends Model {
5256
}
5357

5458
async dontSeeContent(value: string) {
55-
await expect(this.getContent(value)).not.toBeVisible()
59+
await expect(this.getContent(value)).toBeHidden()
60+
}
61+
62+
async seeContentLinkIsFocused(value: string, text: string) {
63+
await expect(this.getContentLink(value, text)).toBeFocused()
64+
}
65+
66+
async seeLinkIsFocused(value: string) {
67+
await expect(this.getLink(value)).toBeFocused()
5668
}
5769
}

e2e/navigation-menu.e2e.ts

+77
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,81 @@ test.describe("navigation-menu", () => {
1717
await I.hoverTrigger("products")
1818
await I.seeContent("products")
1919
})
20+
21+
test("should open on click", async () => {
22+
await I.clickTrigger("products")
23+
await I.seeContent("products")
24+
})
25+
26+
test("should close when clicking outside", async () => {
27+
await I.clickTrigger("products")
28+
await I.seeContent("products")
29+
await I.clickOutside()
30+
await I.dontSeeContent("products")
31+
})
32+
33+
test("should close when pressing escape", async () => {
34+
await I.clickTrigger("products")
35+
await I.seeContent("products")
36+
await I.pressKey("Escape")
37+
await I.dontSeeContent("products")
38+
})
39+
40+
test("trigger switch, using hover", async () => {
41+
await I.hoverTrigger("products")
42+
await I.seeContent("products")
43+
await I.hoverTrigger("company")
44+
await I.seeContent("company")
45+
await I.dontSeeContent("products")
46+
})
47+
48+
test("trigger switch, using the keyboard", async () => {
49+
await I.focusTrigger("products")
50+
await I.pressKey("Enter")
51+
await I.seeContent("products")
52+
await I.pressKey("Enter")
53+
await I.dontSeeContent("products")
54+
55+
await I.pressKey("Tab")
56+
await I.pressKey("Enter")
57+
await I.seeContent("company")
58+
await I.dontSeeContent("products")
59+
})
60+
61+
test("hover + focus should toggle content", async () => {
62+
await I.hoverTrigger("products")
63+
await I.seeContent("products")
64+
await I.clickTrigger("products")
65+
await I.dontSeeContent("products")
66+
67+
// hover again (nothing should happen)
68+
await I.hoverTrigger("products")
69+
await I.dontSeeContent("products")
70+
})
71+
72+
test("focus link on tab", async () => {
73+
await I.focusTrigger("products")
74+
await I.pressKey("Enter")
75+
await I.pressKey("Tab")
76+
await I.seeContentLinkIsFocused("products", "Analytics Platform")
77+
})
78+
79+
test("tab navigation", async () => {
80+
await I.focusTrigger("products")
81+
await I.pressKey("Enter")
82+
await I.pressKey("Tab", 7)
83+
84+
await I.seeTriggerIsFocused("company")
85+
await I.pressKey("Enter")
86+
await I.seeContent("company")
87+
await I.dontSeeContent("products")
88+
89+
await I.pressKey("Tab", 5)
90+
await I.seeLinkIsFocused("pricing")
91+
92+
// focus outside
93+
await I.pressKey("Tab")
94+
await I.dontSeeContent("company")
95+
await I.dontSeeContent("products")
96+
})
2097
})

examples/next-ts/pages/navigation-menu.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ export default function Page() {
4444
{renderLinks({
4545
value: "products",
4646
items: [
47-
"Fusce pellentesque",
48-
"Aliquam porttitor",
49-
"Pellentesque",
50-
"Fusce pellentesque",
51-
"Aliquam porttitor",
52-
"Pellentesque",
47+
"Analytics Platform",
48+
"Customer Engagement",
49+
"Marketing Automation",
50+
"Data Integration",
51+
"Enterprise Solutions",
52+
"API Documentation",
5353
],
5454
})}
5555
</Presence>
@@ -66,7 +66,7 @@ export default function Page() {
6666
</Presence>
6767
{renderLinks({
6868
value: "company",
69-
items: ["Fusce pellentesque", "Aliquam porttitor", "Pellentesque"],
69+
items: ["About Us", "Leadership Team", "Careers", "Press Releases"],
7070
})}
7171
</Presence>
7272
</div>
@@ -82,7 +82,7 @@ export default function Page() {
8282
</Presence>
8383
{renderLinks({
8484
value: "developers",
85-
items: ["Donec quis dui", "Vestibulum", "Fusce pellentesque", "Aliquam porttitor"],
85+
items: ["Investors", "Partners", "Corporate Responsibility"],
8686
})}
8787
</Presence>
8888
</div>

0 commit comments

Comments
 (0)