@@ -8,8 +8,14 @@ import { userEvent } from "@testing-library/user-event";
88import { composeStory } from "@storybook/react" ;
99import Meta , { AppPickerDefault } from "./AppPicker.stories" ;
1010import { axe } from "jest-axe" ;
11+ import { gaEvent } from "../../../functions/client/gaEvent" ;
12+
1113jest . mock ( "../../../hooks/useTelemetry" ) ;
1214
15+ jest . mock ( "../../../functions/client/gaEvent" , ( ) => ( {
16+ gaEvent : jest . fn ( ) ,
17+ } ) ) ;
18+
1319it ( "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 () => {
38 44 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 : / v p n / 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 : / v p n / 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