Skip to content

[FEATURE]: Add roll number interval overlap validator for multi-set assignments #25

Description

@Hanu2908

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

  1. 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;
        }>;
      }
  2. 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").
  3. 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.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cr-commandClass Representative administrative hubarea: validationClient and server input validation schemasenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions