Description
In ClassHub, Class Representatives (CRs) can dispatch multi-set assignments where different question sets are mapped to roll number ranges (e.g., Set A: Rolls 1–25, Set B: Rolls 26–50).
Currently, if a CR accidentally inputs overlapping ranges (e.g., Set A: 1–25 and Set B: 20–45) or inverted boundaries (e.g., 25–1), the error is only caught on database insertion. We need a shared client-side interval validation function with immediate UI feedback in the CR Command assignment composer.
Relevant files
src/lib/utils/rolls.ts (Roll parsing and number utilities)
src/pages/app/CRCommandPage.tsx (Assignment creation modal & sets dispatcher)
tests/unit/rolls.test.ts (Unit test suite for roll helper functions)
Requirements and acceptance criteria
-
Validation helper function:
- Implement and export
validateRollIntervals(sets: Array<{ rollStart: number; rollEnd: number; label?: string }>) in src/lib/utils/rolls.ts.
- Return a structured result:
interface IntervalValidationResult {
isValid: boolean;
errors: Array<{
index: number;
field: 'rollStart' | 'rollEnd' | 'range';
message: string;
}>;
}
-
Validation rules:
- Contiguous/Touching intervals:
[1, 25] and [26, 50] are VALID.
- Overlapping intervals:
[1, 25] and [25, 50] (touching endpoints sharing roll 25) or [1, 25] and [20, 30] are INVALID ("Roll range overlaps with Set X").
- Inverted boundaries:
rollStart > rollEnd (e.g. 25 to 10) is INVALID ("Start roll must be less than or equal to end roll").
- Non-positive values:
rollStart <= 0 or rollEnd <= 0 are INVALID ("Roll numbers must be positive integers").
-
UI Integration:
- In
src/pages/app/CRCommandPage.tsx, run validateRollIntervals on change and display an inline error badge/message next to invalid set inputs.
- Disable the "Dispatch Assignment" button while range validation errors exist.
-
Testing:
- Add unit tests in
tests/unit/rolls.test.ts covering non-overlapping sets, overlapping sets, subsets, inverted ranges, and single-student ranges (rollStart === rollEnd).
- All tests must pass with
npm test.
Testing locally
npm test tests/unit/rolls.test.ts
Description
In ClassHub, Class Representatives (CRs) can dispatch multi-set assignments where different question sets are mapped to roll number ranges (e.g., Set A: Rolls 1–25, Set B: Rolls 26–50).
Currently, if a CR accidentally inputs overlapping ranges (e.g., Set A: 1–25 and Set B: 20–45) or inverted boundaries (e.g., 25–1), the error is only caught on database insertion. We need a shared client-side interval validation function with immediate UI feedback in the CR Command assignment composer.
Relevant files
src/lib/utils/rolls.ts(Roll parsing and number utilities)src/pages/app/CRCommandPage.tsx(Assignment creation modal & sets dispatcher)tests/unit/rolls.test.ts(Unit test suite for roll helper functions)Requirements and acceptance criteria
Validation helper function:
validateRollIntervals(sets: Array<{ rollStart: number; rollEnd: number; label?: string }>)insrc/lib/utils/rolls.ts.Validation rules:
[1, 25]and[26, 50]are VALID.[1, 25]and[25, 50](touching endpoints sharing roll 25) or[1, 25]and[20, 30]are INVALID ("Roll range overlaps with Set X").rollStart > rollEnd(e.g.25to10) is INVALID ("Start roll must be less than or equal to end roll").rollStart <= 0orrollEnd <= 0are INVALID ("Roll numbers must be positive integers").UI Integration:
src/pages/app/CRCommandPage.tsx, runvalidateRollIntervalson change and display an inline error badge/message next to invalid set inputs.Testing:
tests/unit/rolls.test.tscovering non-overlapping sets, overlapping sets, subsets, inverted ranges, and single-student ranges (rollStart === rollEnd).npm test.Testing locally
npm test tests/unit/rolls.test.ts