fix: trim whitespace-only input in settings definition forms#16413
fix: trim whitespace-only input in settings definition forms#16413Valyrian-Code wants to merge 8 commits into
Conversation
The required free-text fields in the Observation, Specimen, and Activity definition forms used z.string().min(1), which accepts a value of only spaces — allowing definitions to be saved with an effectively blank title/description/usage. This matches the repo convention already used elsewhere (e.g. FacilityForm, ChargeItemDefinitionForm slug). Add .trim() to those required text fields so whitespace-only input is treated as empty and surfaces the existing "Field is required" error. Adds a Playwright regression test to each form's existing spec (verified fail-before / pass-after).
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
WalkthroughThree facility definition forms (Activity, Observation, Specimen) now trim whitespace from required string fields using Zod's .trim() before applying minimum-length validation. Playwright tests and a shared helper verify that whitespace-only input is rejected with visible validation errors. ChangesWhitespace input validation for facility definition forms
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds stricter validation to prevent whitespace-only values in facility settings forms, and introduces end-to-end coverage to ensure whitespace-only titles are rejected.
Changes:
- Trim required text fields in Zod schemas so whitespace-only input fails
.min(1)validation. - Add Playwright tests asserting whitespace-only titles are rejected across multiple definition forms.
- Add missing test import for
getFieldErrorMessagewhere needed.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/facility/settings/specimenDefinitions/specimenDefinitionCreate.spec.ts | Adds an E2E test that verifies whitespace-only titles are rejected. |
| tests/facility/settings/observationDefinition/observationDefinition.spec.ts | Adds getFieldErrorMessage import and an E2E test for whitespace-only title rejection. |
| tests/facility/settings/activityDefinition/activityDefinitionCreate.spec.ts | Adds an E2E test that verifies whitespace-only titles are rejected. |
| src/pages/Facility/settings/specimen-definitions/SpecimenDefinitionForm.tsx | Trims title and description before required validation. |
| src/pages/Facility/settings/observationDefinition/ObservationDefinitionForm.tsx | Trims title and description before required validation. |
| src/pages/Facility/settings/activityDefinition/ActivityDefinitionForm.tsx | Trims title, description, and usage before required validation. |
Greptile SummaryThis PR fixes a validation gap where required text fields in three facility-settings definition forms accepted whitespace-only strings by adding
Confidence Score: 4/5Safe to merge; the schema changes are minimal, targeted, and consistent with existing codebase patterns. The core fix is correct and well-scoped. The only gap is that the new Playwright tests only exercise the The three test files could benefit from additional whitespace assertions on Important Files Changed
Reviews (1): Last reviewed commit: "fix: trim whitespace-only input in setti..." | Re-trigger Greptile |
Addresses review feedback on the whitespace-trim coverage: - The schema trims description (all three forms) and usage (activity), but the tests only asserted the title field. Each reworked test now fills every trimmed required text field with whitespace and asserts the field-level error, so a regression on any single field is caught. - Extracts the duplicated fill-whitespace/submit/assert logic into a shared `expectWhitespaceRejected(fields, submit)` helper in tests/helper/error.ts, removing the copy/paste across the three specs.
…tors Addresses follow-up review feedback: - expectWhitespaceRejected now asserts the field error *text* (default /required/i, overridable via an expectedError arg) instead of mere visibility, so it lives up to its docstring. - Target each form's actual required-field labels. A regex like /^Description\b/ was ambiguous in the specimen form, which also has a nested optional "Description" (container) field; the "Description *" label selects the required field specifically.
Addressed both issues:
|
|
@nihal467 this looks fine |
Addresses follow-up review feedback: - expectWhitespaceRejected now asserts the error is visible (toBeVisible) in addition to its text, so a present-but-hidden message can't pass. - Add .trim() to slug_value in the Observation, Specimen and Activity definition forms so a whitespace-only slug no longer satisfies .min(5), and to specimen's derived_from_uri so a pasted URL with surrounding spaces isn't rejected by .url(). Consistent with the title/description trimming. (Activity's derived_from_uri is a plain nullable string with no .url() check, so it's left as-is.)
🚀 Preview Deployment Ready!🔗 Preview URL: https://pr-16413.care-preview-a7w.pages.dev 📱 Mobile Access: This preview will be automatically updated when you push new commits to this PR. |
🎭 Playwright Test ResultsStatus: ✅ Passed
📊 Detailed results are available in the playwright-final-report artifact. Run: #9396 |
derived_from_uri is an optional URL field; trimming it before .url() makes whitespace-only input fail validation on an optional field (empty string is not undefined). That's a separate concern from this PR's required-text whitespace handling, so revert to the original .string().url().optional() and keep the PR focused on required fields.
|
Thanks for the review. On the Copilot comments:
Also linked the tracking issue (#16427) per @nihal467's request. |
Fixes #16427
Proposed Changes
The required free-text fields in three facility-settings "definition" forms use
z.string().min(1), which accepts a value made up entirely of spaces. A whitespace-only value (e.g." ") passes validation, letting a definition be saved with an effectively blank title/description/usage.This continues the same fix as the recent Charge Item Definition title trim, and matches the repo convention already used elsewhere (e.g.
FacilityForm,ValueSetForm,slug_valuein these same schemas, which all.trim()).Forms fixed (required text fields only — selects/enums/slugs untouched):
title,descriptiontitle,descriptiontitle,description,usagemin(1)the whitespace title is accepted; with.trim()it is rejected).Reproduce
Tagging: @ohcnetwork/care-fe-code-reviewers
Merge Checklist
field_requiredkey; no new strings.)Summary by CodeRabbit