Skip to content

Commit 09c2af4

Browse files
codemistVinnl
andauthored
MNTOR-5062 - Prevent bento items from opening a second redirect as a pop (#6205)
* replace programmatic link triggers with real <a> clicks * add unit tests * fix keyboard navigation for links in menu * Use react-aria-prescribed method for link-menuitems (#6212) See https://react-spectrum.adobe.com/react-aria/useMenu.html#links --------- Co-authored-by: Vincent <[email protected]>
1 parent 9ca6142 commit 09c2af4

File tree

3 files changed

+168
-121
lines changed

3 files changed

+168
-121
lines changed

src/app/components/client/toolbar/AppPicker.module.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
}
7575
}
7676

77-
ul {
77+
.menuWrapper {
7878
display: grid;
7979
grid-template-columns: repeat(3, 1fr);
8080
gap: tokens.$spacing-md;
@@ -83,6 +83,8 @@
8383
}
8484

8585
.menuItemWrapper {
86+
text-decoration: none;
87+
8688
&[data-key="mozilla"] {
8789
grid-column: 1 / 4;
8890
}

src/app/components/client/toolbar/AppPicker.test.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ import { userEvent } from "@testing-library/user-event";
88
import { composeStory } from "@storybook/react";
99
import Meta, { AppPickerDefault } from "./AppPicker.stories";
1010
import { axe } from "jest-axe";
11+
import { gaEvent } from "../../../functions/client/gaEvent";
12+
1113
jest.mock("../../../hooks/useTelemetry");
1214

15+
jest.mock("../../../functions/client/gaEvent", () => ({
16+
gaEvent: jest.fn(),
17+
}));
18+
1319
it("passes the axe accessibility test suite", async () => {
1420
const ComposedAppPicker = composeStory(AppPickerDefault, Meta);
1521
const { container } = render(<ComposedAppPicker />);
@@ -38,3 +44,83 @@ it("opens and closes the app picker", async () => {
3844
screen.queryByRole("menu", { name: "⁨Mozilla⁩ apps and services" }),
3945
).not.toBeInTheDocument();
4046
});
47+
48+
it("fires a GA event when an app link is clicked", async () => {
49+
const user = userEvent.setup();
50+
const ComposedAppPicker = composeStory(AppPickerDefault, Meta);
51+
render(<ComposedAppPicker />);
52+
53+
const trigger = screen.getByRole("button", {
54+
name: "⁨Mozilla⁩ apps and services",
55+
});
56+
await user.click(trigger);
57+
58+
const vpnLink = screen.getByRole("menuitem", { name: /vpn/i });
59+
await user.click(vpnLink);
60+
61+
expect(gaEvent).toHaveBeenCalledWith({
62+
category: "bento",
63+
action: "bento-app-link-click",
64+
label: "vpn",
65+
});
66+
});
67+
68+
it("fires a GA event when the 'By Mozilla' link is clicked", async () => {
69+
const user = userEvent.setup();
70+
const ComposedAppPicker = composeStory(AppPickerDefault, Meta);
71+
render(<ComposedAppPicker />);
72+
73+
const trigger = screen.getByRole("button", {
74+
name: "⁨Mozilla⁩ apps and services",
75+
});
76+
await user.click(trigger);
77+
78+
const mozillaLink = screen.getByRole("menuitem", {
79+
name: "Made by ⁨Mozilla⁩",
80+
});
81+
await user.click(mozillaLink);
82+
83+
expect(gaEvent).toHaveBeenCalledWith({
84+
category: "bento",
85+
action: "bento-app-link-click",
86+
label: "Mozilla",
87+
});
88+
});
89+
90+
it("activates a link with Enter or Space via keyboard navigation", async () => {
91+
const user = userEvent.setup();
92+
const ComposedAppPicker = composeStory(AppPickerDefault, Meta);
93+
render(<ComposedAppPicker />);
94+
95+
const trigger = screen.getByRole("button", {
96+
name: "⁨Mozilla⁩ apps and services",
97+
});
98+
await user.click(trigger);
99+
100+
// Navigate to the VPN item using the keyboard
101+
await user.keyboard("{ArrowDown}");
102+
103+
const vpnLink = screen.getByRole("menuitem", { name: /vpn/i });
104+
expect(vpnLink).toHaveFocus();
105+
106+
// press Enter
107+
await user.keyboard("{Enter}");
108+
expect(gaEvent).toHaveBeenCalledWith({
109+
category: "bento",
110+
action: "bento-app-link-click",
111+
label: "vpn",
112+
});
113+
114+
await user.click(trigger);
115+
116+
// Navigate to VPN item again
117+
await user.keyboard("{ArrowDown}");
118+
119+
// press Space
120+
await user.keyboard(" ");
121+
expect(gaEvent).toHaveBeenCalledWith({
122+
category: "bento",
123+
action: "bento-app-link-click",
124+
label: "vpn",
125+
});
126+
});

0 commit comments

Comments
 (0)