- Implemented ThemeProvider to manage theme state and preferences. - Added ThemeControl component for users to switch between system, light, and dark themes. - Integrated localStorage for theme preference persistence. - Updated document styles based on theme changes. test: add tests for permanent deletion of habits and related records - Created tests to ensure permanent deletion of habits removes all dependent records. - Verified that deletion requires ownership, authentication, and checks for archived habits. - Added tests to confirm rollback behavior on deletion failures. test: add tests for habit palette and progress card functionality - Implemented tests for habit color progression and theme-based color shading. - Added tests for progress card calculations and calendar display logic. feat: define theme types and preferences - Introduced Theme and ThemePreference types for better type safety. - Created utility functions for resolving theme based on user preference and system settings. - Defined theme palettes for light and dark modes to ensure adequate contrast.
25 lines
1.8 KiB
TypeScript
25 lines
1.8 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { cardCalendar, cardStats } from "./progress-card";
|
|
import type { ShareData } from "../sharing/contracts";
|
|
const habit = (days: ShareData["habits"][number]["days"]): ShareData["habits"][number] => ({ name: "Reading", color: "#90647e", completed: days.filter(d => d.complete).length, scheduled: days.filter(d => d.due).length, days, legend: { empty: "#eee", partial: ["#ccc"], complete: "#90647e" } });
|
|
const days = [
|
|
{ date: "2024-02-28", due: true, complete: true, ratio: 1, color: "#90647e" },
|
|
{ date: "2024-02-29", due: true, complete: false, ratio: .5, color: "#ccc" },
|
|
{ date: "2024-03-01", due: false, complete: false, ratio: null, color: "#fff" },
|
|
{ date: "2024-03-02", due: true, complete: false, ratio: 0, color: "#eee" },
|
|
{ date: "2024-03-03", due: true, complete: true, ratio: 1, color: "#90647e" },
|
|
];
|
|
test("share calendar preserves dashboard week positions, leap days, shades and days off", () => {
|
|
const chart = cardCalendar(habit(days));
|
|
expect(chart.entries.map(d => [d.column, d.row])).toEqual([[1, 4], [1, 5], [1, 6], [1, 7], [2, 1]]);
|
|
expect(chart.entries.map(d => d.day.color)).toEqual(days.map(d => d.color));
|
|
expect(chart.entries[2]!.day.state).toBe("not-due");
|
|
expect(chart.entries[1]!.day.value).toBe(.5);
|
|
});
|
|
test("period summary counts the whole selected range, not the last day's completion", () => {
|
|
const data: ShareData = { from: days[0]!.date, to: days.at(-1)!.date, timezone: "UTC", habits: [habit(days)] };
|
|
expect(cardStats(data)).toEqual({ completed: 2, scheduled: 4, percent: 50 });
|
|
expect(cardStats({ ...data, from: data.to, habits: [habit(days.slice(-1))] })).toEqual({ completed: 1, scheduled: 1, percent: 100 });
|
|
expect(cardStats({ ...data, habits: [habit([days[2]!])] }).percent).toBeNull();
|
|
});
|