Skip to content

Commit ff4350f

Browse files
authored
Add data-testid, aria-label to general buttons, dialogs (#3299)
1 parent bfc9230 commit ff4350f

21 files changed

+125
-26
lines changed

src/components/AppBar/NavigationButtons.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function NavButton(props: NavButtonProps): ReactElement {
7474

7575
return (
7676
<Button
77+
data-testid={props.buttonId}
7778
id={props.buttonId}
7879
onClick={() => navigate(props.targetPath)}
7980
color="inherit"

src/components/Buttons/CloseButton.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { IconButton } from "@mui/material";
33
import { CSSProperties, ReactElement } from "react";
44

55
interface CloseButtonProps {
6+
buttonId?: string;
7+
buttonLabel?: string;
68
close: () => void;
79
}
810

@@ -15,7 +17,9 @@ export default function CloseButton(props: CloseButtonProps): ReactElement {
1517

1618
return (
1719
<IconButton
18-
aria-label="close"
20+
aria-label={props.buttonLabel ?? "Close"}
21+
data-testid={props.buttonId}
22+
id={props.buttonId}
1923
onClick={props.close}
2024
style={closeButtonStyle}
2125
>

src/components/Buttons/DeleteButtonWithDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface DeleteButtonWithDialogProps {
88
buttonId: string;
99
buttonIdCancel?: string;
1010
buttonIdConfirm?: string;
11+
buttonLabel?: string;
1112
delete: () => void | Promise<void>;
1213
disabled?: boolean;
1314
textId: string;
@@ -28,6 +29,7 @@ export default function DeleteButtonWithDialog(
2829
<>
2930
<IconButtonWithTooltip
3031
buttonId={props.buttonId}
32+
buttonLabel={props.buttonLabel ?? "Delete"}
3133
icon={<Delete />}
3234
onClick={props.disabled ? undefined : () => setOpen(true)}
3335
textId={props.tooltipTextId || props.textId}

src/components/Buttons/FileInputButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ReactElement, ReactNode } from "react";
55
interface BrowseProps {
66
updateFile: (file: File) => void;
77
accept?: string;
8+
buttonProps?: ButtonProps & { "data-testid"?: string };
89
children?: ReactNode;
9-
buttonProps?: ButtonProps;
1010
}
1111

1212
// This button links to a set of functions

src/components/Buttons/FlagButton.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { IconButtonWithTooltip } from "components/Buttons";
66
import { DeleteEditTextDialog } from "components/Dialogs";
77

88
interface FlagButtonProps {
9-
flag: Flag;
109
buttonId?: string;
10+
buttonLabel?: string;
11+
flag: Flag;
1112
updateFlag?: (flag: Flag) => void;
1213
}
1314

@@ -41,6 +42,8 @@ export default function FlagButton(props: FlagButtonProps): ReactElement {
4142
return (
4243
<>
4344
<IconButtonWithTooltip
45+
buttonId={props.buttonId}
46+
buttonLabel={props.buttonLabel ?? "Flag"}
4447
icon={
4548
active ? (
4649
<FlagFilled sx={{ color: (t) => t.palette.error.main }} />
@@ -54,7 +57,6 @@ export default function FlagButton(props: FlagButtonProps): ReactElement {
5457
textId={active ? "flags.edit" : "flags.add"}
5558
size="small"
5659
onClick={props.updateFlag ? () => setOpen(true) : undefined}
57-
buttonId={props.buttonId ?? "flag-button"}
5860
side="top"
5961
/>
6062
{props.updateFlag && (
@@ -65,6 +67,8 @@ export default function FlagButton(props: FlagButtonProps): ReactElement {
6567
close={() => setOpen(false)}
6668
updateText={updateFlag}
6769
onDelete={removeFlag}
70+
buttonIdCancel="flag-cancel"
71+
buttonIdClear="flag-clear"
6872
buttonIdDelete="flag-remove"
6973
buttonIdSave="flag-save"
7074
buttonTextIdDelete="flags.remove"

src/components/Buttons/IconButtonWithTooltip.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { MouseEventHandler, ReactElement, ReactNode } from "react";
33
import { useTranslation } from "react-i18next";
44

55
interface IconButtonWithTooltipProps {
6+
buttonId?: string;
7+
buttonLabel?: string;
68
disabled?: boolean;
79
icon: ReactElement;
810
text?: ReactNode;
911
/** `textId` will only be used if `text` is null or undefined. */
1012
textId?: string;
1113
size?: "large" | "medium" | "small";
1214
onClick?: MouseEventHandler<HTMLButtonElement>;
13-
buttonId?: string;
1415
side?: "bottom" | "left" | "right" | "top";
1516
}
1617

@@ -26,6 +27,8 @@ export default function IconButtonWithTooltip(
2627
>
2728
<span>
2829
<IconButton
30+
aria-label={props.buttonLabel}
31+
data-testid={props.buttonId}
2932
onClick={props.onClick}
3033
size={props.size || "medium"}
3134
id={props.buttonId}

src/components/Buttons/NoteButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EditTextDialog } from "components/Dialogs";
66

77
interface NoteButtonProps {
88
buttonId?: string;
9+
buttonLabel?: string;
910
disabled?: boolean;
1011
/** If `noteText` is empty and `updateNote` defined,
1112
* the button will have default add-note hover text. */
@@ -20,7 +21,8 @@ export default function NoteButton(props: NoteButtonProps): ReactElement {
2021
return (
2122
<>
2223
<IconButtonWithTooltip
23-
buttonId={props.buttonId ?? "entry-note-button"}
24+
buttonId={props.buttonId}
25+
buttonLabel={props.buttonLabel ?? "Note"}
2426
disabled={props.disabled}
2527
icon={
2628
props.noteText ? (
@@ -46,6 +48,7 @@ export default function NoteButton(props: NoteButtonProps): ReactElement {
4648
close={() => setNoteOpen(false)}
4749
updateText={props.updateNote ?? (() => {})}
4850
buttonIdCancel="note-edit-cancel"
51+
buttonIdClear="note-edit-clear"
4952
buttonIdConfirm="note-edit-confirm"
5053
textFieldId="note-text-field"
5154
/>

src/components/Buttons/PartOfSpeechButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getGramCatGroupColor } from "utilities/wordUtilities";
1010

1111
interface PartOfSpeechButtonProps {
1212
buttonId?: string;
13+
buttonLabel?: string;
1314
gramInfo: GrammaticalInfo;
1415
onClick?: () => void;
1516
onlyIcon?: boolean;
@@ -38,6 +39,7 @@ export default function PartOfSpeechButton(
3839
const CatGroupButton = (): ReactElement => (
3940
<IconButtonWithTooltip
4041
buttonId={props.buttonId}
42+
buttonLabel={props.buttonLabel ?? "Part of speech"}
4143
icon={<Hexagon fontSize="small" sx={{ color }} />}
4244
onClick={props.onClick}
4345
side="top"

src/components/Buttons/UndoButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface UndoButtonProps {
88
buttonIdEnabled?: string;
99
buttonIdCancel?: string;
1010
buttonIdConfirm?: string;
11+
buttonLabelEnabled?: string;
1112
textIdDialog: string;
1213
textIdDisabled: string;
1314
textIdEnabled: string;
@@ -34,9 +35,11 @@ export default function UndoButton(props: UndoButtonProps): ReactElement {
3435
{isUndoEnabled ? (
3536
<div>
3637
<Button
37-
variant="outlined"
38+
aria-label={props.buttonLabelEnabled ?? "Undo"}
39+
data-testid={props.buttonIdEnabled}
3840
id={props.buttonIdEnabled}
3941
onClick={() => setUndoDialogOpen(true)}
42+
variant="outlined"
4043
>
4144
{t(props.textIdEnabled)}
4245
</Button>

src/components/DataEntry/DataEntryTable/EntryCellComponents/DeleteEntry.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CancelConfirmDialog } from "components/Dialogs";
88
interface DeleteEntryProps {
99
removeEntry: () => void;
1010
buttonId: string;
11+
buttonLabel?: string;
1112
// confirmId is the translation id for the text of the delete confirmation popup;
1213
// if no confirmId is specified, then there is no popup
1314
// and deletion will happen when the button is pressed
@@ -34,6 +35,8 @@ export default function DeleteEntry(props: DeleteEntryProps): ReactElement {
3435
<>
3536
<Tooltip title={t("addWords.deleteRow")} placement="top">
3637
<IconButton
38+
aria-label={props.buttonLabel ?? "Delete entry"}
39+
data-testid={props.buttonId}
3740
disabled={props.disabled}
3841
tabIndex={-1}
3942
size="small"

0 commit comments

Comments
 (0)