Add component tests for P3.11 (82 tests across 5 files)
- DecisionCard tests: 11 tests covering rendering, status icons, styling - DataPanel tests: 18 tests covering biometrics display, null handling, styling - NutritionPanel tests: 12 tests covering seeds, carbs, keto guidance display - OverrideToggles tests: 18 tests covering toggle states, callbacks, styling - DayCell tests: 23 tests covering phase coloring, today highlighting, click handling Total tests now: 707 passing across 40 test files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
143
src/components/dashboard/data-panel.test.tsx
Normal file
143
src/components/dashboard/data-panel.test.tsx
Normal file
@@ -0,0 +1,143 @@
|
||||
// ABOUTME: Unit tests for DataPanel component.
|
||||
// ABOUTME: Tests biometrics display including body battery, HRV, and intensity.
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DataPanel } from "./data-panel";
|
||||
|
||||
describe("DataPanel", () => {
|
||||
const baseProps = {
|
||||
bodyBatteryCurrent: 75,
|
||||
bodyBatteryYesterdayLow: 25,
|
||||
hrvStatus: "Balanced",
|
||||
weekIntensity: 120,
|
||||
phaseLimit: 200,
|
||||
remainingMinutes: 80,
|
||||
};
|
||||
|
||||
describe("rendering", () => {
|
||||
it("renders the YOUR DATA heading", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
expect(screen.getByText("YOUR DATA")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders body battery current value", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
expect(screen.getByText(/Body Battery: 75/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders yesterday low value", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
expect(screen.getByText(/Yesterday Low: 25/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders HRV status", () => {
|
||||
render(<DataPanel {...baseProps} hrvStatus="Balanced" />);
|
||||
|
||||
expect(screen.getByText(/HRV: Balanced/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders week intensity with phase limit", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
expect(screen.getByText(/Week: 120\/200 min/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders remaining minutes", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
expect(screen.getByText(/Remaining: 80 min/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("null value handling", () => {
|
||||
it("displays N/A when bodyBatteryCurrent is null", () => {
|
||||
render(<DataPanel {...baseProps} bodyBatteryCurrent={null} />);
|
||||
|
||||
expect(screen.getByText(/Body Battery: N\/A/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays N/A when bodyBatteryYesterdayLow is null", () => {
|
||||
render(<DataPanel {...baseProps} bodyBatteryYesterdayLow={null} />);
|
||||
|
||||
expect(screen.getByText(/Yesterday Low: N\/A/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays N/A for both when both are null", () => {
|
||||
render(
|
||||
<DataPanel
|
||||
{...baseProps}
|
||||
bodyBatteryCurrent={null}
|
||||
bodyBatteryYesterdayLow={null}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText(/Body Battery: N\/A/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Yesterday Low: N\/A/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("HRV status variations", () => {
|
||||
it("displays Balanced HRV status", () => {
|
||||
render(<DataPanel {...baseProps} hrvStatus="Balanced" />);
|
||||
|
||||
expect(screen.getByText(/HRV: Balanced/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays Unbalanced HRV status", () => {
|
||||
render(<DataPanel {...baseProps} hrvStatus="Unbalanced" />);
|
||||
|
||||
expect(screen.getByText(/HRV: Unbalanced/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays Unknown HRV status", () => {
|
||||
render(<DataPanel {...baseProps} hrvStatus="Unknown" />);
|
||||
|
||||
expect(screen.getByText(/HRV: Unknown/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("intensity values", () => {
|
||||
it("displays zero intensity correctly", () => {
|
||||
render(<DataPanel {...baseProps} weekIntensity={0} />);
|
||||
|
||||
expect(screen.getByText(/Week: 0\/200 min/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays when over phase limit", () => {
|
||||
render(<DataPanel {...baseProps} weekIntensity={250} phaseLimit={200} />);
|
||||
|
||||
expect(screen.getByText(/Week: 250\/200 min/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays zero remaining minutes", () => {
|
||||
render(<DataPanel {...baseProps} remainingMinutes={0} />);
|
||||
|
||||
expect(screen.getByText(/Remaining: 0 min/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays negative remaining minutes", () => {
|
||||
render(<DataPanel {...baseProps} remainingMinutes={-50} />);
|
||||
|
||||
expect(screen.getByText(/Remaining: -50 min/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("styling", () => {
|
||||
it("renders within a bordered container", () => {
|
||||
const { container } = render(<DataPanel {...baseProps} />);
|
||||
|
||||
const panel = container.firstChild as HTMLElement;
|
||||
expect(panel).toHaveClass("rounded-lg", "border", "p-4");
|
||||
});
|
||||
|
||||
it("renders heading with semibold font", () => {
|
||||
render(<DataPanel {...baseProps} />);
|
||||
|
||||
const heading = screen.getByText("YOUR DATA");
|
||||
expect(heading).toHaveClass("font-semibold");
|
||||
});
|
||||
});
|
||||
});
|
||||
166
src/components/dashboard/decision-card.test.tsx
Normal file
166
src/components/dashboard/decision-card.test.tsx
Normal file
@@ -0,0 +1,166 @@
|
||||
// ABOUTME: Unit tests for DecisionCard component.
|
||||
// ABOUTME: Tests rendering of decision status, icon, and reason.
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Decision } from "@/types";
|
||||
import { DecisionCard } from "./decision-card";
|
||||
|
||||
describe("DecisionCard", () => {
|
||||
describe("rendering", () => {
|
||||
it("renders the decision icon", () => {
|
||||
const decision: Decision = {
|
||||
status: "REST",
|
||||
reason: "Your body needs recovery today",
|
||||
icon: "🛌",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("🛌")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the decision status", () => {
|
||||
const decision: Decision = {
|
||||
status: "TRAIN",
|
||||
reason: "Good to go",
|
||||
icon: "🏃",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("TRAIN")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the decision reason", () => {
|
||||
const decision: Decision = {
|
||||
status: "GENTLE",
|
||||
reason: "Take it easy today",
|
||||
icon: "🧘",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("Take it easy today")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("different status types", () => {
|
||||
it("renders REST status correctly", () => {
|
||||
const decision: Decision = {
|
||||
status: "REST",
|
||||
reason: "HRV unbalanced - recovery day",
|
||||
icon: "🛌",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("REST")).toBeInTheDocument();
|
||||
expect(screen.getByText("🛌")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("HRV unbalanced - recovery day"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders GENTLE status correctly", () => {
|
||||
const decision: Decision = {
|
||||
status: "GENTLE",
|
||||
reason: "Light movement recommended",
|
||||
icon: "🧘",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("GENTLE")).toBeInTheDocument();
|
||||
expect(screen.getByText("🧘")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("Light movement recommended"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders LIGHT status correctly", () => {
|
||||
const decision: Decision = {
|
||||
status: "LIGHT",
|
||||
reason: "Keep intensity moderate",
|
||||
icon: "🚶",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("LIGHT")).toBeInTheDocument();
|
||||
expect(screen.getByText("🚶")).toBeInTheDocument();
|
||||
expect(screen.getByText("Keep intensity moderate")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders REDUCED status correctly", () => {
|
||||
const decision: Decision = {
|
||||
status: "REDUCED",
|
||||
reason: "Lower intensity today",
|
||||
icon: "⬇️",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("REDUCED")).toBeInTheDocument();
|
||||
expect(screen.getByText("⬇️")).toBeInTheDocument();
|
||||
expect(screen.getByText("Lower intensity today")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders TRAIN status correctly", () => {
|
||||
const decision: Decision = {
|
||||
status: "TRAIN",
|
||||
reason: "Full intensity training approved",
|
||||
icon: "🏃",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
expect(screen.getByText("TRAIN")).toBeInTheDocument();
|
||||
expect(screen.getByText("🏃")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("Full intensity training approved"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("styling", () => {
|
||||
it("renders within a bordered container", () => {
|
||||
const decision: Decision = {
|
||||
status: "REST",
|
||||
reason: "Test reason",
|
||||
icon: "🛌",
|
||||
};
|
||||
|
||||
const { container } = render(<DecisionCard decision={decision} />);
|
||||
|
||||
const card = container.firstChild as HTMLElement;
|
||||
expect(card).toHaveClass("rounded-lg", "border", "p-6");
|
||||
});
|
||||
|
||||
it("renders status as bold heading", () => {
|
||||
const decision: Decision = {
|
||||
status: "TRAIN",
|
||||
reason: "Test",
|
||||
icon: "🏃",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
const heading = screen.getByRole("heading", { level: 2 });
|
||||
expect(heading).toHaveTextContent("TRAIN");
|
||||
expect(heading).toHaveClass("font-bold");
|
||||
});
|
||||
|
||||
it("renders reason with muted color", () => {
|
||||
const decision: Decision = {
|
||||
status: "REST",
|
||||
reason: "Muted reason text",
|
||||
icon: "🛌",
|
||||
};
|
||||
|
||||
render(<DecisionCard decision={decision} />);
|
||||
|
||||
const reason = screen.getByText("Muted reason text");
|
||||
expect(reason).toHaveClass("text-gray-600");
|
||||
});
|
||||
});
|
||||
});
|
||||
136
src/components/dashboard/nutrition-panel.test.tsx
Normal file
136
src/components/dashboard/nutrition-panel.test.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
// ABOUTME: Unit tests for NutritionPanel component.
|
||||
// ABOUTME: Tests display of seeds, carb range, and keto guidance.
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { NutritionGuidance } from "@/types";
|
||||
import { NutritionPanel } from "./nutrition-panel";
|
||||
|
||||
describe("NutritionPanel", () => {
|
||||
const baseNutrition: NutritionGuidance = {
|
||||
seeds: "Flax & Pumpkin",
|
||||
carbRange: "100-150g",
|
||||
ketoGuidance: "Moderate carbs today",
|
||||
};
|
||||
|
||||
describe("rendering", () => {
|
||||
it("renders the NUTRITION TODAY heading", () => {
|
||||
render(<NutritionPanel nutrition={baseNutrition} />);
|
||||
|
||||
expect(screen.getByText("NUTRITION TODAY")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders seeds guidance with emoji", () => {
|
||||
render(<NutritionPanel nutrition={baseNutrition} />);
|
||||
|
||||
expect(screen.getByText(/🌱 Flax & Pumpkin/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders carb range with emoji", () => {
|
||||
render(<NutritionPanel nutrition={baseNutrition} />);
|
||||
|
||||
expect(screen.getByText(/🍽️ Carbs: 100-150g/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders keto guidance with emoji", () => {
|
||||
render(<NutritionPanel nutrition={baseNutrition} />);
|
||||
|
||||
expect(
|
||||
screen.getByText(/🥑 Keto: Moderate carbs today/),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("seed cycling phases", () => {
|
||||
it("displays follicular phase seeds (flax & pumpkin)", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
seeds: "Flax & Pumpkin",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(screen.getByText(/🌱 Flax & Pumpkin/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays luteal phase seeds (sunflower & sesame)", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
seeds: "Sunflower & Sesame",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(screen.getByText(/🌱 Sunflower & Sesame/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("carb range variations", () => {
|
||||
it("displays low carb range", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
carbRange: "50-75g",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(screen.getByText(/🍽️ Carbs: 50-75g/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays high carb range", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
carbRange: "150-200g",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(screen.getByText(/🍽️ Carbs: 150-200g/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("keto guidance variations", () => {
|
||||
it("displays keto-friendly guidance", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
ketoGuidance: "Good day for keto",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(
|
||||
screen.getByText(/🥑 Keto: Good day for keto/),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays carb-loading guidance", () => {
|
||||
const nutrition: NutritionGuidance = {
|
||||
...baseNutrition,
|
||||
ketoGuidance: "Consider carb loading",
|
||||
};
|
||||
|
||||
render(<NutritionPanel nutrition={nutrition} />);
|
||||
|
||||
expect(
|
||||
screen.getByText(/🥑 Keto: Consider carb loading/),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("styling", () => {
|
||||
it("renders within a bordered container", () => {
|
||||
const { container } = render(
|
||||
<NutritionPanel nutrition={baseNutrition} />,
|
||||
);
|
||||
|
||||
const panel = container.firstChild as HTMLElement;
|
||||
expect(panel).toHaveClass("rounded-lg", "border", "p-4");
|
||||
});
|
||||
|
||||
it("renders heading with semibold font", () => {
|
||||
render(<NutritionPanel nutrition={baseNutrition} />);
|
||||
|
||||
const heading = screen.getByText("NUTRITION TODAY");
|
||||
expect(heading).toHaveClass("font-semibold");
|
||||
});
|
||||
});
|
||||
});
|
||||
216
src/components/dashboard/override-toggles.test.tsx
Normal file
216
src/components/dashboard/override-toggles.test.tsx
Normal file
@@ -0,0 +1,216 @@
|
||||
// ABOUTME: Unit tests for OverrideToggles component.
|
||||
// ABOUTME: Tests toggle states, callbacks, and all override types.
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OverrideType } from "@/types";
|
||||
import { OverrideToggles } from "./override-toggles";
|
||||
|
||||
describe("OverrideToggles", () => {
|
||||
const baseProps = {
|
||||
activeOverrides: [] as OverrideType[],
|
||||
onToggle: vi.fn(),
|
||||
};
|
||||
|
||||
describe("rendering", () => {
|
||||
it("renders the OVERRIDES heading", () => {
|
||||
render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
expect(screen.getByText("OVERRIDES")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders all four override options", () => {
|
||||
render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
expect(screen.getByText("Flare Mode")).toBeInTheDocument();
|
||||
expect(screen.getByText("High Stress")).toBeInTheDocument();
|
||||
expect(screen.getByText("Poor Sleep")).toBeInTheDocument();
|
||||
expect(screen.getByText("PMS Symptoms")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders four checkboxes", () => {
|
||||
render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
const checkboxes = screen.getAllByRole("checkbox");
|
||||
expect(checkboxes).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkbox states", () => {
|
||||
it("all checkboxes are unchecked when activeOverrides is empty", () => {
|
||||
render(<OverrideToggles {...baseProps} activeOverrides={[]} />);
|
||||
|
||||
const checkboxes = screen.getAllByRole("checkbox");
|
||||
for (const checkbox of checkboxes) {
|
||||
expect(checkbox).not.toBeChecked();
|
||||
}
|
||||
});
|
||||
|
||||
it("flare checkbox is checked when flare is active", () => {
|
||||
render(<OverrideToggles {...baseProps} activeOverrides={["flare"]} />);
|
||||
|
||||
const flareCheckbox = screen.getByRole("checkbox", {
|
||||
name: "Flare Mode",
|
||||
});
|
||||
expect(flareCheckbox).toBeChecked();
|
||||
});
|
||||
|
||||
it("stress checkbox is checked when stress is active", () => {
|
||||
render(<OverrideToggles {...baseProps} activeOverrides={["stress"]} />);
|
||||
|
||||
const stressCheckbox = screen.getByRole("checkbox", {
|
||||
name: "High Stress",
|
||||
});
|
||||
expect(stressCheckbox).toBeChecked();
|
||||
});
|
||||
|
||||
it("sleep checkbox is checked when sleep is active", () => {
|
||||
render(<OverrideToggles {...baseProps} activeOverrides={["sleep"]} />);
|
||||
|
||||
const sleepCheckbox = screen.getByRole("checkbox", {
|
||||
name: "Poor Sleep",
|
||||
});
|
||||
expect(sleepCheckbox).toBeChecked();
|
||||
});
|
||||
|
||||
it("pms checkbox is checked when pms is active", () => {
|
||||
render(<OverrideToggles {...baseProps} activeOverrides={["pms"]} />);
|
||||
|
||||
const pmsCheckbox = screen.getByRole("checkbox", {
|
||||
name: "PMS Symptoms",
|
||||
});
|
||||
expect(pmsCheckbox).toBeChecked();
|
||||
});
|
||||
|
||||
it("multiple checkboxes are checked when multiple overrides are active", () => {
|
||||
render(
|
||||
<OverrideToggles
|
||||
{...baseProps}
|
||||
activeOverrides={["flare", "stress", "pms"]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("checkbox", { name: "Flare Mode" }),
|
||||
).toBeChecked();
|
||||
expect(
|
||||
screen.getByRole("checkbox", { name: "High Stress" }),
|
||||
).toBeChecked();
|
||||
expect(
|
||||
screen.getByRole("checkbox", { name: "Poor Sleep" }),
|
||||
).not.toBeChecked();
|
||||
expect(
|
||||
screen.getByRole("checkbox", { name: "PMS Symptoms" }),
|
||||
).toBeChecked();
|
||||
});
|
||||
|
||||
it("all checkboxes are checked when all overrides are active", () => {
|
||||
render(
|
||||
<OverrideToggles
|
||||
{...baseProps}
|
||||
activeOverrides={["flare", "stress", "sleep", "pms"]}
|
||||
/>,
|
||||
);
|
||||
|
||||
const checkboxes = screen.getAllByRole("checkbox");
|
||||
for (const checkbox of checkboxes) {
|
||||
expect(checkbox).toBeChecked();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("toggle interactions", () => {
|
||||
it("calls onToggle with flare when flare checkbox is clicked", () => {
|
||||
const onToggle = vi.fn();
|
||||
render(<OverrideToggles activeOverrides={[]} onToggle={onToggle} />);
|
||||
|
||||
const flareCheckbox = screen.getByRole("checkbox", {
|
||||
name: "Flare Mode",
|
||||
});
|
||||
fireEvent.click(flareCheckbox);
|
||||
|
||||
expect(onToggle).toHaveBeenCalledWith("flare");
|
||||
expect(onToggle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("calls onToggle with stress when stress checkbox is clicked", () => {
|
||||
const onToggle = vi.fn();
|
||||
render(<OverrideToggles activeOverrides={[]} onToggle={onToggle} />);
|
||||
|
||||
const stressCheckbox = screen.getByRole("checkbox", {
|
||||
name: "High Stress",
|
||||
});
|
||||
fireEvent.click(stressCheckbox);
|
||||
|
||||
expect(onToggle).toHaveBeenCalledWith("stress");
|
||||
expect(onToggle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("calls onToggle with sleep when sleep checkbox is clicked", () => {
|
||||
const onToggle = vi.fn();
|
||||
render(<OverrideToggles activeOverrides={[]} onToggle={onToggle} />);
|
||||
|
||||
const sleepCheckbox = screen.getByRole("checkbox", {
|
||||
name: "Poor Sleep",
|
||||
});
|
||||
fireEvent.click(sleepCheckbox);
|
||||
|
||||
expect(onToggle).toHaveBeenCalledWith("sleep");
|
||||
expect(onToggle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("calls onToggle with pms when pms checkbox is clicked", () => {
|
||||
const onToggle = vi.fn();
|
||||
render(<OverrideToggles activeOverrides={[]} onToggle={onToggle} />);
|
||||
|
||||
const pmsCheckbox = screen.getByRole("checkbox", {
|
||||
name: "PMS Symptoms",
|
||||
});
|
||||
fireEvent.click(pmsCheckbox);
|
||||
|
||||
expect(onToggle).toHaveBeenCalledWith("pms");
|
||||
expect(onToggle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("calls onToggle when unchecking an active override", () => {
|
||||
const onToggle = vi.fn();
|
||||
render(
|
||||
<OverrideToggles activeOverrides={["flare"]} onToggle={onToggle} />,
|
||||
);
|
||||
|
||||
const flareCheckbox = screen.getByRole("checkbox", {
|
||||
name: "Flare Mode",
|
||||
});
|
||||
fireEvent.click(flareCheckbox);
|
||||
|
||||
expect(onToggle).toHaveBeenCalledWith("flare");
|
||||
});
|
||||
});
|
||||
|
||||
describe("styling", () => {
|
||||
it("renders within a bordered container", () => {
|
||||
const { container } = render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
const panel = container.firstChild as HTMLElement;
|
||||
expect(panel).toHaveClass("rounded-lg", "border", "p-4");
|
||||
});
|
||||
|
||||
it("renders heading with semibold font", () => {
|
||||
render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
const heading = screen.getByText("OVERRIDES");
|
||||
expect(heading).toHaveClass("font-semibold");
|
||||
});
|
||||
|
||||
it("renders labels as clickable cursor-pointer", () => {
|
||||
render(<OverrideToggles {...baseProps} />);
|
||||
|
||||
const labels = screen.getAllByText(
|
||||
/Flare Mode|High Stress|Poor Sleep|PMS Symptoms/,
|
||||
);
|
||||
for (const label of labels) {
|
||||
const labelElement = label.closest("label");
|
||||
expect(labelElement).toHaveClass("cursor-pointer");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user