Skip to content

test(competitions): unit tests for loader, filters and date flattening #208

Description

@AnayDhawan

Blocked by #195 and #201.

Unit tests for the pure logic in the competitions vertical. The repo has 16 test files and 129 tests; this vertical should not be the part with none.

Setup that already exists

Vitest 4.1.9 with jsdom, @testing-library/react. vitest.config.ts includes src/**/*.test.ts and src/**/*.test.tsx, so tests are colocated next to what they test. npm run test:unit. CI runs it on every PR via the unit-tests job in .github/workflows/ci.yml.

Closest models: src/lib/places.test.ts for the filtering shape, src/lib/data-freshness.test.ts for date logic, src/components/map/results-list.test.tsx for a component test.

What to cover

src/lib/competitions.test.ts

  • filterCompetitions with each filter alone, and with two composed
  • Age filter is inclusive at both ends of age_min and age_max
  • query matches name, organizer and subjects, case-insensitively, and ignores surrounding whitespace
  • Empty filters returns everything; a filter matching nothing returns an empty array, not undefined
  • nextDate skips past dates, returns the soonest future one, and returns undefined when all dates are past
  • upcomingDates sorts ascending and includes country stages only when a country is given

src/lib/competition-events.test.ts

  • Flattening produces one event per date plus one per stage of the selected country only
  • A competition with no country_tracks produces only its own dates
  • The estimated flag survives flattening
  • Timezone handling does not shift a date across a day boundary. Pin a fixed now rather than using the real clock.

Date tests must not depend on when they run. check-data-freshness.mjs already accepts a --today= flag for exactly this reason. Pass an explicit now everywhere rather than letting a test pass in September and fail in January.

Acceptance criteria

  • npm run test:unit passes
  • No test depends on the current date
  • Filter composition is covered, not just single filters
  • Country-stage flattening is covered
  • Tests colocated in src/lib/, matching the existing convention

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions