Skip to content

Commit 361a867

Browse files
committed
add data-testids to interactive elements
1 parent f074fb3 commit 361a867

File tree

9 files changed

+31
-7
lines changed

9 files changed

+31
-7
lines changed

src/components/Footer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ const Footer = ({ lastDeployLocaleTimestamp }: FooterProps) => {
323323
variant="outline"
324324
isSecondary
325325
onClick={() => scrollIntoView("body")}
326+
data-testid="footer-go-to-top"
326327
>
327328
<ChevronUp /> <Translation id="go-to-top" />
328329
</Button>

src/components/LanguagePicker/MobileCloseBar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export const MobileCloseBar = ({ handleClick }: MobileCloseBarProps) => {
1313

1414
return (
1515
<div className="sticky top-0 flex justify-end bg-background md:hidden">
16-
<Button className="self-end p-4" variant="ghost" onClick={handleClick}>
16+
<Button
17+
className="self-end p-4"
18+
variant="ghost"
19+
onClick={handleClick}
20+
data-testid="mobile-language-picker-close"
21+
>
1722
{t("close")}
1823
</Button>
1924
</div>

src/components/LanguagePicker/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ const LanguagePickerMenu = ({ languages, onClose, onSelect }) => {
174174

175175
<CommandInput
176176
placeholder={t("page-languages-filter-placeholder")}
177+
data-testid="language-filter-input"
177178
className="h-9"
178179
kbdShortcut="\"
179180
/>
@@ -188,6 +189,7 @@ const LanguagePickerMenu = ({ languages, onClose, onSelect }) => {
188189
key={"item-" + displayInfo.localeOption}
189190
displayInfo={displayInfo}
190191
onSelect={onSelect}
192+
data-testid={`language-option-${displayInfo.localeOption}`}
191193
/>
192194
))}
193195
</CommandGroup>

src/components/Nav/Mobile/HamburgerButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const HamburgerButton = forwardRef<HTMLButtonElement, HamburgerProps>(
3131
<Button
3232
ref={ref}
3333
id={HAMBURGER_BUTTON_ID}
34+
data-testid="mobile-menu-hamburger"
3435
aria-label={t("aria-toggle-menu-button")}
3536
className={cn("px-2 py-0 text-body", className)}
3637
variant="ghost"

src/components/Nav/Mobile/LvlAccordion.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as AccordionPrimitive from "@radix-ui/react-accordion"
44

55
import { cn } from "@/lib/utils/cn"
66
import { trackCustomEvent } from "@/lib/utils/matomo"
7+
import { slugify } from "@/lib/utils/url"
78
import { cleanPath } from "@/lib/utils/url"
89

910
import { Button } from "../../ui/buttons/Button"
@@ -131,6 +132,7 @@ const LvlAccordion = ({
131132
<AccordionTrigger
132133
heading={`h${lvl + 1}` as "h2" | "h3" | "h4" | "h5"}
133134
className={cn("text-body", nestedAccordionSpacingMap[lvl])}
135+
data-testid={`accordion-toggle-${slugify(label)}`}
134136
onClick={() => {
135137
trackCustomEvent({
136138
eventCategory: "Mobile navigation menu",

src/components/Nav/Mobile/MenuBody.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useLocale } from "next-intl"
33

44
import { cn } from "@/lib/utils/cn"
55
import { trackCustomEvent } from "@/lib/utils/matomo"
6+
import { slugify } from "@/lib/utils/url"
67

78
import { SECTION_LABELS } from "@/lib/constants"
89

@@ -46,6 +47,7 @@ const MenuBody = ({ linkSections, onToggle }: MenuBodyProps) => {
4647
>
4748
<AccordionTrigger
4849
className="text-body"
50+
data-testid={`menu-section-toggle-${slugify(label)}`}
4951
onClick={() => {
5052
trackCustomEvent({
5153
eventCategory: "Mobile navigation menu",

src/components/Nav/Mobile/MenuFooter.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const MenuFooter = ({
2929
<div className="grid w-full grid-cols-3 items-center justify-center">
3030
<FooterButton
3131
icon={Search}
32+
data-testid="mobile-menu-search-button"
3233
onClick={() => {
3334
// Workaround to ensure the input for the search modal can have focus
3435
onToggle()
@@ -38,12 +39,20 @@ const MenuFooter = ({
3839
<FooterItemText>{t("search")}</FooterItemText>
3940
</FooterButton>
4041

41-
<FooterButton icon={ThemeIcon} onClick={toggleColorMode}>
42+
<FooterButton
43+
icon={ThemeIcon}
44+
data-testid="mobile-menu-theme-toggle"
45+
onClick={toggleColorMode}
46+
>
4247
<FooterItemText>{t(themeLabelKey)}</FooterItemText>
4348
</FooterButton>
4449

4550
<LanguagePicker dialog handleClose={onToggle}>
46-
<FooterButton icon={Languages} name={MOBILE_LANGUAGE_BUTTON_NAME}>
51+
<FooterButton
52+
icon={Languages}
53+
data-testid="mobile-menu-language-picker"
54+
name={MOBILE_LANGUAGE_BUTTON_NAME}
55+
>
4756
<FooterItemText>{t("languages")}</FooterItemText>
4857
</FooterButton>
4958
</LanguagePicker>

src/components/Nav/Mobile/MenuHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const MenuHeader = () => {
1010
<SheetTitle className="p-0 text-md uppercase text-body-medium">
1111
{t("site-title")}
1212
</SheetTitle>
13-
<SheetClose className="w-fit text-md">{t("close")}</SheetClose>
13+
<SheetClose className="w-fit text-md" data-testid="mobile-menu-close">
14+
{t("close")}
15+
</SheetClose>
1416
</div>
1517
)
1618
}

src/components/ui/swiper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ const SwiperNavigation = React.forwardRef<
108108
React.HTMLAttributes<HTMLDivElement>
109109
>((props, ref) => (
110110
<SwiperNavContainer ref={ref} {...props}>
111-
<SwiperPrevButton />
112-
<SwiperPaginationDots />
113-
<SwiperNextButton />
111+
<SwiperPrevButton data-testid="swiper-prev-button" />
112+
<SwiperPaginationDots data-testid="swiper-pagination-dots" />
113+
<SwiperNextButton data-testid="swiper-next-button" />
114114
</SwiperNavContainer>
115115
))
116116
SwiperNavigation.displayName = "SwiperNavigation"

0 commit comments

Comments
 (0)