Skip to content
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
3 changes: 2 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"maximum": "Must be at most {maximum}",
"time": "Wrong time format.",
"wrong_format": "Wrong format.",
"add_on_required": "Select at least one add-on"
"add_on_required": "Select at least one add-on",
"additional_items": "Unable to save due to missing required additional info — click the ⚙ icon to review"
},
"price_tiers": {
"early_bird_rate": "Early Bird Rate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,60 @@ describe("EditCartForm", () => {
});
});

describe("Item Field Error Message", () => {
test("shows error message below Save when a required Item field is empty after submit", async () => {
const formWithRequiredItemField = {
...mockCartForm,
items: [
{
...mockCartForm.items[0],
meta_fields: [
{
type_id: 2,
type: "Text",
class_field: "Item",
current_value: "",
is_required: true
}
]
}
]
};

renderWithStore({}, { cartForm: formWithRequiredItemField });

await waitFor(() => {
expect(screen.getByText(/general.save/)).toBeInTheDocument();
});

await userEvent.click(screen.getByText(/general.save/));

await waitFor(() => {
expect(
screen.getByText("validation.additional_items")
).toBeInTheDocument();
});
});

test("does not show error message when no Item fields have validation errors", async () => {
renderWithStore();

await waitFor(() => {
expect(screen.getByText(/general.save/)).toBeInTheDocument();
});

await userEvent.click(screen.getByText(/general.save/));

await waitFor(() => {
expect(mockUpdateCartForm).toHaveBeenCalled();
});

expect(
screen.queryByText("validation.additional_items")
).not.toBeInTheDocument();
});
});

describe("Edge Cases", () => {
test("handles empty items array", async () => {
const emptyForm = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ const EditForm = ({
// wait for formik to re-initialize with form items
if (!form || Object.keys(formik.values).length === 0) return null;

const hasItemFieldErrors = Object.keys(formik.errors).some(
(key) => key.includes("-c-Item-") && formik.touched[key]
);

return (
<>
<Typography variant="h5" sx={{ mt: 4, mb: 2 }}>
Expand Down Expand Up @@ -319,6 +323,18 @@ const EditForm = ({
{T.translate("general.save")}
</Button>
</Box>
{hasItemFieldErrors && (
<Box component="div" sx={{ mt: 1 }}>
<Typography
variant="caption"
color="error"
display="block"
sx={{ mt: 0.25, textAlign: "right" }}
>
{T.translate("validation.additional_items")}
</Typography>
</Box>
)}
</Box>
<NotesModal
item={notesItem}
Expand Down
Loading