Skip to content

Conversation

@junaidiqbalmoj
Copy link
Contributor

@junaidiqbalmoj junaidiqbalmoj commented Dec 3, 2025

Jira link

https://tools.hmcts.net/jira/browse/VIBE-175

Change description

Create Media Application Error Messages Fix

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced form validation with more specific and helpful error messages for each field, including checks for blank entries, whitespace issues, and format validation
    • Improved error messaging clarity for email format, file size requirements, and terms acceptance
    • Added granular validation feedback for full name, email, employer, and file uploads in English and Welsh

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

Walkthrough

This pull request introduces granular form validation error messages for the create-media-account feature, replacing generic error keys with specific ones for blank fields, whitespace issues, and format validation. Updates include new locale strings in English and Welsh, enhanced validation logic with helper functions, and comprehensive test coverage for the expanded validation scenarios.

Changes

Cohort / File(s) Summary
Locale definitions
libs/public-pages/src/pages/create-media-account/en.ts, cy.ts
Added granular error keys for full name, email, employer, and file validation (blank, whitespace, double whitespace, format). Updated message text for errorFileSize, errorEmailInvalid, and errorTermsRequired. Removed generic keys like errorFullNameRequired and errorEmployerRequired.
Locale tests
libs/public-pages/src/pages/create-media-account/index.njk.test.ts
Updated assertions to verify new error keys and their corresponding messages across both English and Welsh locales. Expanded test coverage for the broader validation surface.
Core validation logic
libs/public-pages/src/pages/validation.ts
Introduced helper predicates for whitespace detection. Refactored full name, email, employer, and file validation to emit specific error keys for blank, whitespace, and format failures. Added MAX_FILE_SIZE constant and file extension validation.
Validation tests
libs/public-pages/src/pages/validation.test.ts
Expanded test cases to cover whitespace edge cases, boundary conditions, and new error scenarios. Updated expected error keys from generic (e.g., errorFullNameRequired) to granular (e.g., errorFullNameBlank, errorFullNameWhiteSpace).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • validation.ts: New helper functions and refactored validation logic across four form fields warrant careful scrutiny of error-key logic paths and boundary conditions
  • Locale files (en.ts, cy.ts): Verify all new error keys are correctly defined and Welsh translations are accurate
  • Tests: Cross-check new validation test cases align with updated validation logic, especially whitespace and format edge cases

Poem

🐰 With whiskers twitching, I hop with glee,
Your validations now precise and spry!
Blank fields caught, spaces trimmed tight,
Each error message burns ever so bright.
From generic to granular, details shine—
A form that's sturdy, every line divine! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring error messages in the Create Media Application from generic to granular validation errors.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vibe-175-bug-fixes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2025

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
libs/public-pages/src/pages/validation.test.ts (2)

46-65: Incorrect error message for length validation.

The test expects errorFullNameBlank ("Full name field must be populated") when the name exceeds 100 characters. This message is misleading since the field is populated - it's just too long. The validation should return a distinct error like errorFullNameTooLong with a message indicating the length constraint.

Same issue applies to the invalid characters test on line 84.

-    expect(errors[0].text).toBe(en.errorFullNameBlank);
+    // Consider adding a distinct error key for length validation:
+    // expect(errors[0].text).toBe(en.errorFullNameTooLong);

255-274: Similar issue: using blank error for length constraint.

Like the full name case, errorEmployerBlank is used when employer exceeds 120 characters. This is semantically incorrect - the field is populated, just too long.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8c8258 and be10181.

📒 Files selected for processing (5)
  • libs/public-pages/src/pages/create-media-account/cy.ts (1 hunks)
  • libs/public-pages/src/pages/create-media-account/en.ts (1 hunks)
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts (3 hunks)
  • libs/public-pages/src/pages/validation.test.ts (7 hunks)
  • libs/public-pages/src/pages/validation.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: TypeScript variables must use camelCase (e.g., userId, caseDetails, documentId). Booleans must use is/has/can prefix (e.g., isActive, hasAccess, canEdit).
Classes and interfaces must use PascalCase (e.g., UserService, CaseRepository). DO NOT use I prefix for interfaces.
Constants must use SCREAMING_SNAKE_CASE (e.g., MAX_FILE_SIZE, DEFAULT_TIMEOUT).
Module ordering: constants outside function scope at the top, exported functions next, other functions ordered by usage, interfaces and types at the bottom.
TypeScript strict mode must be enabled. No any type without justification. Use explicit types for all variables and function parameters.
Always add .js extension to relative imports (e.g., import { foo } from "./bar.js"), even when importing TypeScript files. This is required for ESM with Node.js 'nodenext' module resolution.
Use workspace aliases (@hmcts/*) for imports between packages instead of relative paths.
Only export functions that are intended to be used outside the module. Do not export functions solely for testing purposes.
Only add comments when they provide meaningful explanation of why something is done, not what is done. Code should be self-documenting.
Favor functional style. Don't use classes unless you have shared state.
Data should be immutable by default. Use const and avoid mutations to ensure predictable state.
Functions should have no side effects. Avoid modifying external state or relying on mutable data.

Files:

  • libs/public-pages/src/pages/validation.ts
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
**/src/pages/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

**/src/pages/**/*.ts: Pages are registered through explicit imports in apps/web/src/app.ts. Routes are created based on file names within the pages/ directory (e.g., my-page.ts becomes /my-page, nested routes via subdirectories).
Page controller files must export GET and/or POST functions that accept Express Request and Response, render using res.render(), and handle form submissions.

Files:

  • libs/public-pages/src/pages/validation.ts
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
**/src/pages/**/*.{ts,njk}

📄 CodeRabbit inference engine (CLAUDE.md)

**/src/pages/**/*.{ts,njk}: Every page must support both English and Welsh. Controllers must provide both en and cy objects with page content.
Welsh translations are required for all user-facing text. Do not skip Welsh support.

Files:

  • libs/public-pages/src/pages/validation.ts
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
**/*.{ts,tsx,js,mjs}

📄 CodeRabbit inference engine (CLAUDE.md)

DO NOT use CommonJS. Use import/export, never require()/module.exports. Only ES modules are allowed.

Files:

  • libs/public-pages/src/pages/validation.ts
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.ts: Do not create generic types.ts files. Colocate types with the appropriate code file where they are used.
Do not create generic files like utils.ts. Be specific with naming (e.g., object-properties.ts, date-formatting.ts).

Files:

  • libs/public-pages/src/pages/validation.ts
  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Unit/integration test files must be co-located with source files as *.test.ts and use Vitest with describe, it, and expect.

Files:

  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/validation.test.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: junaidiqbalmoj
Repo: hmcts/cath-service PR: 137
File: e2e-tests/tests/create-media-account.spec.ts:51-64
Timestamp: 2025-11-27T14:18:22.932Z
Learning: For the create-media-account form in libs/public-pages, the English email validation error message (errorEmailInvalid) should be: "There is a problem - Enter a valid email address, e.g. nameexample.com" to match the Welsh translation and clearly indicate the format requirement rather than suggesting the field is empty.
📚 Learning: 2025-11-27T14:18:22.932Z
Learnt from: junaidiqbalmoj
Repo: hmcts/cath-service PR: 137
File: e2e-tests/tests/create-media-account.spec.ts:51-64
Timestamp: 2025-11-27T14:18:22.932Z
Learning: For the create-media-account form in libs/public-pages, the English email validation error message (errorEmailInvalid) should be: "There is a problem - Enter a valid email address, e.g. nameexample.com" to match the Welsh translation and clearly indicate the format requirement rather than suggesting the field is empty.

Applied to files:

  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
  • libs/public-pages/src/pages/validation.test.ts
  • libs/public-pages/src/pages/create-media-account/en.ts
📚 Learning: 2025-12-03T13:55:34.702Z
Learnt from: CR
Repo: hmcts/cath-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-03T13:55:34.702Z
Learning: Applies to **/src/pages/**/*.{ts,njk} : Welsh translations are required for all user-facing text. Do not skip Welsh support.

Applied to files:

  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
📚 Learning: 2025-12-03T13:55:34.702Z
Learnt from: CR
Repo: hmcts/cath-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-03T13:55:34.702Z
Learning: Applies to **/src/pages/**/*.{ts,njk} : Every page must support both English and Welsh. Controllers must provide both `en` and `cy` objects with page content.

Applied to files:

  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/create-media-account/cy.ts
📚 Learning: 2025-12-03T13:55:34.702Z
Learnt from: CR
Repo: hmcts/cath-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-03T13:55:34.702Z
Learning: Applies to e2e-tests/**/*.spec.ts : E2E test files must be in `e2e-tests/` directory named `*.spec.ts`, use Playwright, include complete user journeys with validations, Welsh translations, accessibility checks, and keyboard navigation all within a single test.

Applied to files:

  • libs/public-pages/src/pages/create-media-account/index.njk.test.ts
  • libs/public-pages/src/pages/validation.test.ts
🧬 Code graph analysis (1)
libs/public-pages/src/pages/create-media-account/index.njk.test.ts (2)
libs/public-pages/src/pages/create-media-account/en.ts (1)
  • en (1-36)
libs/public-pages/src/pages/create-media-account/cy.ts (1)
  • cy (1-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: SonarQube Analysis
  • GitHub Check: E2E Tests
🔇 Additional comments (11)
libs/public-pages/src/pages/validation.test.ts (3)

87-148: Well-structured whitespace validation tests.

The new test cases for full name whitespace scenarios (leading space, double spaces, missing surname space) are comprehensive and properly validate both the error message and the target field href.


171-232: Good coverage for email validation edge cases.

The new tests properly cover email whitespace scenarios (leading space, double spaces) and blank email handling with appropriate error messages and field references.


318-344: File validation tests look good.

The distinction between errorFileBlank (missing file) and errorFileType (wrong file format) appropriately separates these error conditions.

libs/public-pages/src/pages/validation.ts (3)

15-21: Clean helper predicates.

The hasDoubleWhiteSpace and startsWithWhiteSpace functions are well-implemented, pure functions with clear semantics.


62-83: Email validation logic is well-structured.

The validation chain properly separates blank, whitespace, and format errors with distinct messages for each condition.


119-126: File extension validation looks correct.

The extension extraction handles edge cases appropriately - files without extensions or with unusual names will fail validation as expected since they won't match the allowed extensions list.

libs/public-pages/src/pages/create-media-account/index.njk.test.ts (3)

64-80: Comprehensive English error message assertions.

The updated assertions cover the full range of granular validation error messages, ensuring the English locale contains all expected error keys with correct text.


127-143: Welsh translations properly verified.

The Welsh error message assertions ensure bilingual support is complete, with all new granular error keys having corresponding Welsh translations.


146-189: Locale consistency validation is thorough.

The test verifies that both English and Welsh locales have identical key sets, which is essential for preventing missing translation issues at runtime. As per coding guidelines, every page must support both English and Welsh.

libs/public-pages/src/pages/create-media-account/cy.ts (1)

21-35: Welsh translations are complete and consistent.

All new granular error keys have corresponding Welsh translations. The key naming matches the English locale (en.ts), ensuring consistency across both languages as required by coding guidelines.

libs/public-pages/src/pages/create-media-account/en.ts (1)

21-35: Granular error messages improve user experience.

The new error keys provide specific, actionable feedback for each validation failure. The email invalid message correctly uses the format guidance ("like [email protected]") as expected. Based on learnings, this matches the expected format for the create-media-account form.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🎭 Playwright E2E Test Results

145 tests   145 ✅  9m 49s ⏱️
 22 suites    0 💤
  1 files      0 ❌

Results for commit be10181.

@junaidiqbalmoj junaidiqbalmoj changed the title VIBE-175 Create Media Application Error Messages Fix VIBE-175 Bug Fix in Create Media Application About Error Messages Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants