#19968·kestra

Add unit tests for isLoggedIn

Author: MilosPaunovicCreated Sep 30, 2026Updated Sep 30, 2026
Labelsarea/frontendkind/cooldowngood first issue

What

ui/src/utils/basicAuth.ts has no test yet.

isLoggedIn reads a non-HttpOnly flag cookie the server issues in lockstep with the real BASIC_AUTH cookie, and the whole UI decides whether to show the login screen from it. It matches on an exact name=value entry, so the interesting cases are the near-misses that must not match.

What to do

Create ui/tests/unit/utils/basicAuth.spec.ts covering:

  • a cookie jar containing kestraBasicAuthenticated=true returns true
  • an empty cookie jar returns false
  • kestraBasicAuthenticated=false returns false
  • a different cookie whose name merely ends with the flag name does not match
  • the flag is found when it sits first, in the middle, and last among several cookies
  • a value with surrounding whitespace, such as kestraBasicAuthenticated= true, does not match

Set document.cookie per case under jsdom, or stub the cookie getter with Object.defineProperty, and reset it in afterEach. Only isLoggedIn is in scope; logout and signIn make network calls.

Reference

ui/tests/unit/utils/splitTranslation.spec.ts is an existing test of the same shape to copy from.

How to run

Install once, then run the whole suite:

bash
cd ui && npm install && npm run test:unit

While writing the test, run just this file so the feedback loop stays fast:

bash
cd ui && npm run test:unit -- tests/unit/utils/basicAuth.spec.ts

Proof required in the PR

[!IMPORTANT] The PR that closes this issue must include a screenshot of the test passing, pasted into the PR description. Pasted text output is not enough.

To produce it, run the single-file command above and screenshot the terminal. The capture should show the command, the test file, and the green summary lines (Test Files 1 passed (1) and Tests N passed (N)). Then drag the image straight into the PR description field on GitHub, which uploads and embeds it.