Skip to content

Add data-testid attributes to Pydantic Forms components #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const ArrayField = ({ pydanticFormField }: PydanticFormElementProps) => {

return (
<div
data-testid={arrayName}
style={{
border: 'thin solid green',
padding: '1rem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export const CheckboxField = ({
value,
name,
disabled,
pydanticFormField,
}: PydanticFormControlledElementProps) => {
return (
<input
data-testid={pydanticFormField.id}
type="checkbox"
checked={value}
onChange={() => onChange(!value)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';

export const DividerField = () => {
return <hr />;
import type { PydanticFormElementProps } from '@/types';

export const DividerField = ({
pydanticFormField,
}: PydanticFormElementProps) => {
return <hr data-testid={pydanticFormField.id} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DropdownField = ({
}: PydanticFormControlledElementProps) => {
return (
<select
data-testid={pydanticFormField.id}
value={value}
onChange={(e) => {
onChange(e.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const FieldWrap = ({ pydanticFormField, children }: FieldWrapProps) => {
required={pydanticFormField.required}
isInvalid={!!isInvalid}
error={errorMsg as string}
data-testid={pydanticFormField.id}
>
<div>{children}</div>
</RowRenderer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ export const HiddenField = ({
pydanticFormField,
}: PydanticFormElementProps) => {
const { rhf } = usePydanticFormContext();
return <input type="hidden" {...rhf.register(pydanticFormField.id)} />;
return (
<input
type="hidden"
data-testid={pydanticFormField.id}
{...rhf.register(pydanticFormField.id)}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export const IntegerField = ({
onChange,
onBlur,
disabled,
pydanticFormField,
}: PydanticFormControlledElementProps) => {
return (
<input
data-testid={pydanticFormField.id}
onBlur={onBlur}
onChange={(t) => {
const value = parseInt(t.currentTarget.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PydanticFormElementProps } from '@/types';

export const LabelField = ({ pydanticFormField }: PydanticFormElementProps) => {
return (
<div>
<div data-testid={pydanticFormField.id}>
<label>{pydanticFormField?.default}</label>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const MultiCheckboxField = ({
return (
<label key={optionId}>
<input
data-testid={id}
type="checkbox"
id={optionId}
name={optionId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const MultiSelectField = ({
return (
<div>
<select
data-testid={pydanticFormField.id}
onBlur={onBlur}
disabled={disabled}
value={multiSelectItems}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const ObjectField = ({

return (
<div
data-testid={pydanticFormField.id}
style={{
border: 'thin dotted grey',
padding: '1rem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const RadioField = ({
{options.map((option, key) => (
<div key={key}>
<input
data-testid={`${id}-${option.value}`}
type="radio"
id={option.value}
name={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const TextAreaField = ({
onChange,
onBlur,
disabled,
pydanticFormField,
}: PydanticFormControlledElementProps) => {
return (
<textarea
data-testid={pydanticFormField.id}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
defaultValue={value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const TextField = ({
onChange,
onBlur,
disabled,
pydanticFormField,
}: PydanticFormControlledElementProps) => (
<input
data-testid={pydanticFormField.id}
onBlur={onBlur}
onChange={(t) => {
onChange(t.currentTarget.value);
Expand Down