mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(mood): rebuild logging as a 5-face hero with tag picker and factor ratings
Replace the score-number radio + free-text form with an icon-first
"How are you?" hero that matches the native client: a row of five mood
faces in best-on-the-left order is the primary input, and picking one
reveals a brief annotate panel (time, the category-grouped tag picker,
factor ratings, and the note field).
The tag picker now reads the catalog's `kind` / `scaleMin` / `scaleMax`
metadata. BINARY tags stay icon-above-label toggle tiles sent as
`tagKeys`; RATED factors (work / social / sleep quality / stress, and
the 1..2 Yes/No conflict factor) render a compact 1..scaleMax segmented
control and are sent as a parallel `ratedFactors: [{ key, rating }]`
array. The entries list / history stays reachable below the hero.
Add the mood-face icon map (Laugh / Smile / Meh / Frown / Angry) and the
`heroQuestion`, `factorYes`, `factorNo`, `factorRatingOption` strings
across all six locales.
This commit is contained in:
1 parent
2bb810852e
commit
e9eb7dc704
10 files changed
+315
-54
No files matched your search
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
* v1.11.5 — QoL-Lows coverage for the mood form + list fixes.
|
||||
* v1.11.5 / v1.12.0 — coverage for the mood form + list.
|
||||
*
|
||||
* Project convention is SSR-only component tests (`renderToStaticMarkup`,
|
||||
* no `@testing-library/react`) plus source-string structural assertions
|
||||
* for the interactive plumbing that an SSR mount can't exercise. The
|
||||
* three fixes pinned here:
|
||||
* for the interactive plumbing that an SSR mount can't exercise.
|
||||
*
|
||||
* 1. `<MoodList>` — the delete mutation surfaces a toast on failure
|
||||
* (it previously had no `onError`, so a rejected DELETE was silent).
|
||||
* 2. `<MoodForm>` — Reset confirms first when the form holds typed
|
||||
* input, and resets immediately when pristine.
|
||||
* 3. `<MoodForm>` — the note field shows a live character counter so
|
||||
* the `maxLength` cap no longer truncates without feedback.
|
||||
* v1.12.0 rebuilt the logging surface into the "How are you?" 5-face
|
||||
* hero: the five mood faces are the primary input (rendered on a
|
||||
* pristine form), and the annotate panel — time, tags, factor ratings,
|
||||
* the note field + its counter — reveals only after a face is picked.
|
||||
* A pristine SSR mount therefore shows the hero but not the counter;
|
||||
* the counter / reset / note plumbing is pinned via source-string
|
||||
* assertions below.
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
@@ -44,13 +44,43 @@ const listSrc = readFileSync(
|
||||
"utf8",
|
||||
);
|
||||
|
||||
describe("MoodForm — note character counter (v1.11.5)", () => {
|
||||
it("renders the counter at 0/500 for a pristine form", () => {
|
||||
describe("MoodForm — 5-face hero (v1.12.0)", () => {
|
||||
it("renders the five mood faces as a radiogroup on a pristine form", () => {
|
||||
const html = renderForm();
|
||||
expect(html).toContain('data-testid="mood-note-counter"');
|
||||
expect(html).toContain("0/500");
|
||||
// The "How are you?" hero is the primary input — present before any
|
||||
// mood is picked.
|
||||
expect(html).toContain('data-slot="mood-face-hero"');
|
||||
expect(html).toContain("How are you?");
|
||||
// Best-on-the-left order: every enum value renders one face button.
|
||||
for (const mood of [
|
||||
"SUPER_GUT",
|
||||
"GUT",
|
||||
"OKAY",
|
||||
"SCHLECHT",
|
||||
"LAUSIG",
|
||||
]) {
|
||||
expect(html).toContain(`data-mood="${mood}"`);
|
||||
}
|
||||
// The first face is SUPER_GUT (best on the left).
|
||||
expect(html.indexOf('data-mood="SUPER_GUT"')).toBeLessThan(
|
||||
html.indexOf('data-mood="LAUSIG"'),
|
||||
);
|
||||
});
|
||||
|
||||
it("hides the annotate panel (and note counter) until a face is picked", () => {
|
||||
// A pristine SSR mount cannot pick a mood, so the panel stays closed.
|
||||
const html = renderForm();
|
||||
expect(html).not.toContain('data-slot="mood-annotate-panel"');
|
||||
expect(html).not.toContain('data-testid="mood-note-counter"');
|
||||
// The panel is gated on `moodPicked` (mood !== "").
|
||||
expect(formSrc).toContain("const moodPicked = mood !== \"\"");
|
||||
expect(formSrc).toMatch(
|
||||
/moodPicked &&[\s\S]*data-slot="mood-annotate-panel"/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MoodForm — note character counter (v1.11.5)", () => {
|
||||
it("ties the textarea cap to the shared NOTE_MAX_LENGTH constant", () => {
|
||||
expect(formSrc).toContain("const NOTE_MAX_LENGTH = 500");
|
||||
expect(formSrc).toContain("maxLength={NOTE_MAX_LENGTH}");
|
||||
@@ -67,6 +97,7 @@ describe("MoodForm — Reset confirm when dirty (v1.11.5)", () => {
|
||||
expect(formSrc).toMatch(/const isDirty =\s*\n?\s*mood !== ""/);
|
||||
expect(formSrc).toContain('tagsInput.trim() !== ""');
|
||||
expect(formSrc).toContain("tagKeys.length > 0");
|
||||
expect(formSrc).toContain("ratedFactors.length > 0");
|
||||
expect(formSrc).toContain('note.trim() !== ""');
|
||||
// The `isDirty` expression itself must not read `moodLoggedAt`.
|
||||
const isDirtyExpr = formSrc.slice(
|
||||
@@ -94,6 +125,28 @@ describe("MoodForm — Reset confirm when dirty (v1.11.5)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("MoodForm — rated factors (v1.12.0)", () => {
|
||||
it("lifts a ratedFactors set and threads it to the tag picker", () => {
|
||||
expect(formSrc).toContain("const [ratedFactors, setRatedFactors]");
|
||||
expect(formSrc).toMatch(/function rateFactor\(key: string, rating: number \| null\)/);
|
||||
// The picker receives both the binary toggle and the factor rate
|
||||
// callbacks so it can render BINARY chips and RATED controls.
|
||||
expect(formSrc).toMatch(
|
||||
/<MoodTagPicker[\s\S]*ratedFactors=\{ratedFactors\}[\s\S]*onRateFactor=\{rateFactor\}/,
|
||||
);
|
||||
});
|
||||
|
||||
it("sends ratedFactors as a parallel array on POST (omitted when empty)", () => {
|
||||
expect(formSrc).toContain(
|
||||
"ratedFactors: ratedFactors.length > 0 ? ratedFactors : undefined,",
|
||||
);
|
||||
// The binary structured-tag contract stays byte-identical.
|
||||
expect(formSrc).toContain(
|
||||
"tagKeys: tagKeys.length > 0 ? tagKeys : undefined,",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MoodList — delete failure toast (v1.11.5)", () => {
|
||||
it("surfaces a toast on a rejected delete instead of failing silently", () => {
|
||||
expect(listSrc).toContain('import { toast } from "sonner"');
|
||||
|
||||
Reference in new issue
Block a user