Skip to content

Commit

Permalink
[#1965] fix duplicate testIds for reference errors and hints
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Oct 18, 2024
1 parent 5372420 commit 537ebbc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ changes.
### Fixed

- Fix unwanted horizontal page scroll on Governance Actions page [Issue 1897](https://github.com/IntersectMBO/govtool/issues/1897)
- Fix duplicate testIds for reference errors and hints in DRep metadata form [Issue 1965](https://github.com/IntersectMBO/govtool/issues/1965)

### Changed

Expand Down
5 changes: 4 additions & 1 deletion govtool/frontend/src/components/atoms/FormErrorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { Typography } from "@mui/material";
import { FormErrorMessageProps } from "./types";

export const FormErrorMessage = ({
dataTestId,
errorMessage,
errorStyles,
}: FormErrorMessageProps) =>
errorMessage && (
<Typography
color="red"
data-testid={`${errorMessage.replace(/\s+/g, "-").toLowerCase()}-error`}
data-testid={
dataTestId ?? `${errorMessage.replace(/\s+/g, "-").toLowerCase()}-error`
}
fontSize={12}
fontWeight={400}
sx={{ mt: 0.25 }}
Expand Down
5 changes: 4 additions & 1 deletion govtool/frontend/src/components/atoms/FormHelpfulText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Typography } from "@mui/material";
import { FormHelpfulTextProps } from "./types";

export const FormHelpfulText = ({
dataTestId,
helpfulText,
helpfulTextStyle,
sx,
}: FormHelpfulTextProps) =>
helpfulText && (
<Typography
color="#9792B5"
data-testid={`${helpfulText.replace(/\s+/g, "-").toLowerCase()}-error`}
data-testid={
dataTestId ?? `${helpfulText.replace(/\s+/g, "-").toLowerCase()}-error`
}
fontSize={12}
fontWeight={400}
sx={{ mt: 0.5, ...sx }}
Expand Down
2 changes: 2 additions & 0 deletions govtool/frontend/src/components/atoms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export type CheckboxProps = Omit<MUICheckboxProps, "onChange" | "value"> & {
};

export type FormErrorMessageProps = {
dataTestId?: string;
errorMessage?: string;
errorStyles?: MUITypographyProps;
};

export type FormHelpfulTextProps = {
dataTestId?: string;
helpfulText?: string;
helpfulTextStyle?: MUITypographyProps;
sx?: SxProps;
Expand Down
6 changes: 6 additions & 0 deletions govtool/frontend/src/components/molecules/DRepDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ const ReferencesSection = ({
name={`${fieldName}.${index}.label`}
helpfulText={t("forms.dRepData.referenceDescriptionHelpfulText")}
dataTestId={`${type}-reference-description-${index + 1}-input`}
errorDataTestId={`${type}-reference-description-${index + 1}-error`}
helpfulTextDataTestId={`${type}-reference-description-${
index + 1
}-hint`}
rules={Rules.LINK_DESCRIPTION}
/>
<ControlledField.Input
Expand All @@ -252,6 +256,8 @@ const ReferencesSection = ({
layoutStyles={{ mb: 3 }}
name={`${fieldName}.${index}.uri`}
dataTestId={`${type}-reference-url-${index + 1}-input`}
errorDataTestId={`${type}-reference-url-${index + 1}-error`}
helpfulTextDataTestId={`${type}-reference-url-${index + 1}-hint`}
rules={Rules.LINK_URL}
/>
</Fragment>
Expand Down
4 changes: 4 additions & 0 deletions govtool/frontend/src/components/molecules/Field/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { InputFieldProps } from "./types";
export const Input = forwardRef<HTMLInputElement, InputFieldProps>(
(
{
errorDataTestId,
errorMessage,
errorStyles,
helpfulTextDataTestId,
helpfulText,
helpfulTextStyle,
label,
Expand Down Expand Up @@ -71,10 +73,12 @@ export const Input = forwardRef<HTMLInputElement, InputFieldProps>(
ref={inputRef}
/>
<FormHelpfulText
dataTestId={helpfulTextDataTestId}
helpfulText={helpfulText}
helpfulTextStyle={helpfulTextStyle}
/>
<FormErrorMessage
dataTestId={errorDataTestId}
errorMessage={errorMessage}
errorStyles={errorStyles}
/>
Expand Down
2 changes: 2 additions & 0 deletions govtool/frontend/src/components/molecules/Field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
} from "@atoms";

export type InputFieldProps = InputProps & {
errorDataTestId?: string;
errorMessage?: string;
errorStyles?: MUITypographyProps;
helpfulTextDataTestId?: string;
helpfulText?: string;
helpfulTextStyle?: MUITypographyProps;
label?: string;
Expand Down

0 comments on commit 537ebbc

Please sign in to comment.