Skip to content

[Bugfix:Forum] Handle invalid category date#12675

Closed
Asterisk-Hunter wants to merge 1 commit into
Submitty:mainfrom
Asterisk-Hunter:bugfix/forum-category-date-validation
Closed

[Bugfix:Forum] Handle invalid category date#12675
Asterisk-Hunter wants to merge 1 commit into
Submitty:mainfrom
Asterisk-Hunter:bugfix/forum-category-date-validation

Conversation

@Asterisk-Hunter

Copy link
Copy Markdown
Contributor

Why is this Change Important & Necessary?

Fixes #12327

When editing a forum category's visible date and entering an invalid format, the system throws an unhandled InvalidArgumentException from DateUtils::parseDateTime(). This causes a poor user experience - instead of showing a helpful error message, users see a generic error or stack trace.

This PR also supersedes the abandoned PR #12328 and addresses the reviewer feedback from that PR (using data-testid attributes instead of class selectors in tests, not using force: true in Cypress).

What is the New Behavior?

The system now catches the InvalidArgumentException and returns a friendly error message ("Invalid date format.") to the user via the standard popup notification. The page remains stable and users can correct their input.

What steps should a reviewer take to reproduce or test the bug or new feature?

  1. Log in as instructor
  2. Navigate to Forum > More dropdown > Edit Categories
  3. Click the edit button next to a category's date field
  4. Enter an invalid date format (e.g., "invalid-date" or "abc")
  5. Click the save button
  6. Observe that a popup appears with "Invalid date format" instead of crashing

Automated Testing & Documentation

Added a Cypress test in forums.spec.js that:

  • Navigates to the Edit Categories page using data-testid selectors
  • Enters an invalid date format
  • Verifies the error message appears in the popup

The test follows the feedback from PR #12328:

  • Uses data-testid attributes instead of class selectors
  • Does not use force: true
  • Checks specific element ([data-testid="popup-message"]) for the error message

Other information

This is not a breaking change. No migrations needed. No security concerns.

- Add try-catch for InvalidArgumentException when parsing category visible date
- Return user-friendly error message instead of crashing on invalid input
- Add data-testid attributes to category date editing elements for testing
- Add data-testid to Edit Categories link in ForumBar
- Add Cypress test to verify error handling for invalid date format

Fixes Submitty#12327
@williamjallen

Copy link
Copy Markdown
Member

This is a duplicate of #12328. I just talked to the creator of that PR today and he plans to make changes to it soon.

@github-project-automation github-project-automation Bot moved this from Seeking Reviewer to Done in Submitty Development Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

discussion forum category date bug

2 participants