Skip to content

test(frontend): cover lecture-view-prefs, login, usage-stats and useClickOutside - #2171

Open
noahkhomer18 wants to merge 1 commit into
TUM-Dev:devfrom
noahkhomer18:test/2166-frontend-lib-helpers
Open

noahkhomer18 wants to merge 1 commit into
TUM-Dev:devfrom
noahkhomer18:test/2166-frontend-lib-helpers

Conversation

@noahkhomer18

Copy link
Copy Markdown

Motivation and Context

Closes #2166. Four modules in frontend/src/lib/ had no unit tests.

Description

One test file next to each module, in the style of the existing *.test.ts files there (same fetch spying as api.test.ts, @vue/test-utils for the composable). Test-only: no source file or existing test is changed.

  • lecture-view-prefs.test.ts: defaults when nothing is stored; every choice restored from its own spa. key; a stored value that isn't one of the allowed words (the legacy numeric "1", "true" for the boolean) is discarded; each change is written back, including hideWatched as yes/no.
  • login.test.ts: fetchLoginOptions reads the three fields from /api/v2/login-options, falls back to #3070B3 when the colour is empty or left out of the JSON, and passes a failed request on; requestPasswordReset posts the address to /api/v2/users/reset-password and rejects with ApiError on failure.
  • usage-stats.test.ts: points with a series, an empty series and undefined; usageStats converting the bigint student count and handling a response with no series at all; usageCounters and usageCharts in the order, titles and colours the old pages used.
  • useClickOutside.test.ts: a press outside calls the handler, a press inside and a plain click don't, nothing happens while there is no target element, and the pointerdown listener added on mount is the one removed on unmount.

Steps for Testing

$ pnpm --dir frontend test
 Test Files  122 passed (122)
      Tests  1166 passed (1166)

$ pnpm --dir frontend run typecheck   # exit 0

Each file catches a real break. With one line of the module changed, then restored:

Module Change Result
lecture-view-prefs.ts drop the allowed.includes(saved) check fails: expected '1' to be 'newest'
login.ts drop the empty-colour fallback 2 fail: expected '' to be '#3070B3'
usage-stats.ts map every point's y to 0 2 fail in points and usageStats
useClickOutside.ts make the removeEventListener call a no-op fails: removeEventListener called 0 times

Screenshots

None, no UI change.

…lickOutside

Closes TUM-Dev#2166

Signed-off-by: Noah Khomer <108771853+noahkhomer18@users.noreply.github.com>
@noahkhomer18

Copy link
Copy Markdown
Author

The red e2e check is schedule.spec.ts › "renames a lecture from its popover", which timed out clicking the Bierkunde lecture. The header of that file says the fixture lecture becomes tomorrow's shortly before midnight, and this run started at 23:09 UTC. This PR only adds unit tests under frontend/src/lib, so a re-run during the day should go green.

This branch has not been deployed

No deployments
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.

Add unit tests for untested frontend helpers

1 participant