Add unit tests for getUid and ensureUid
What
ui/src/utils/uid.ts has no test yet.
ensureUid is what gives an install its stable anonymous identifier, so it must generate exactly once and then keep returning the same value.
What to do
Create ui/tests/unit/utils/uid.spec.ts covering:
getUidreturnsnullwhen nothing is storedgetUidreturns the stored value when there is oneensureUidgenerates and persists a uid when storage is emptyensureUidreturns the existing uid and does not overwrite it when one is already stored- two
ensureUidcalls in a row return the same value
localStorage is available under jsdom; clear it in a beforeEach so the cases stay independent.
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:
cd ui && npm install && npm run test:unitWhile writing the test, run just this file so the feedback loop stays fast:
cd ui && npm run test:unit -- tests/unit/utils/uid.spec.tsProof required in the PR
[!IMPORTANT] The
PRthat closes this issue must include a screenshot of the test passing, pasted into thePRdescription. 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)andTests N passed (N)). Then drag the image straight into thePRdescription field on GitHub, which uploads and embeds it.
Source: kestra-io/kestra