feat: implement remaining TODO.md feature ideas + fix mobile headers
Implements the six previously-unscoped feature ideas plus a mobile layout fix reported via screenshot: - Mobile: Recipes/Collections/Pantry/Meal Plan/Shopping Lists headers now stack and wrap instead of clipping buttons on narrow viewports. - Recipe diff/compare view: word/list diff against any past version, next to Restore in version history. - Shared meal plans & shopping lists: new shoppingListMembers/ mealPlanMembers tables (viewer/editor roles, mirrors collectionMembers), share dialogs, membership-checked routes. - PDF cookbook export: /print/collection/[id] renders a whole collection with page breaks, using the existing print-CSS pattern instead of adding a PDF rendering dependency. - Grocery delivery handoff: shopping lists can copy-as-text (works today) or send to Instacart once INSTACART_API_KEY is configured (stub adapter — real API needs a partner agreement). - Personalized "For You" feed tab: ranks public recipes by tag/ dietary overlap with the user's favorited/highly-rated history. - PWA: added manifest.json + icons on top of the existing service worker so the app is installable; cook-mode pages were already cached for offline use. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { buildPreferenceMap, scoreCandidate, rankForYou } from "../for-you-ranking";
|
||||
|
||||
describe("buildPreferenceMap", () => {
|
||||
it("counts tags and true dietary-tag keys across liked recipes", () => {
|
||||
const map = buildPreferenceMap([
|
||||
{ tags: ["spicy", "quick"], dietaryTags: { vegan: true, glutenFree: false } },
|
||||
{ tags: ["spicy"], dietaryTags: null },
|
||||
]);
|
||||
expect(map.get("spicy")).toBe(2);
|
||||
expect(map.get("quick")).toBe(1);
|
||||
expect(map.get("vegan")).toBe(1);
|
||||
expect(map.get("glutenFree")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns an empty map for no liked recipes", () => {
|
||||
expect(buildPreferenceMap([]).size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("scoreCandidate", () => {
|
||||
it("sums preference weights for overlapping tags", () => {
|
||||
const prefs = new Map([["spicy", 3], ["vegan", 1]]);
|
||||
const score = scoreCandidate({ tags: ["spicy"], dietaryTags: { vegan: true } }, prefs);
|
||||
expect(score).toBe(4);
|
||||
});
|
||||
|
||||
it("scores 0 when nothing overlaps", () => {
|
||||
const prefs = new Map([["spicy", 3]]);
|
||||
expect(scoreCandidate({ tags: ["sweet"], dietaryTags: null }, prefs)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("rankForYou", () => {
|
||||
const base = { dietaryTags: null };
|
||||
|
||||
it("sorts by score descending", () => {
|
||||
const prefs = new Map([["spicy", 5]]);
|
||||
const candidates = [
|
||||
{ id: "a", tags: ["sweet"], createdAt: new Date("2024-01-01"), ...base },
|
||||
{ id: "b", tags: ["spicy"], createdAt: new Date("2024-01-01"), ...base },
|
||||
];
|
||||
const ranked = rankForYou(candidates, prefs);
|
||||
expect(ranked.map((r) => r.id)).toEqual(["b", "a"]);
|
||||
});
|
||||
|
||||
it("breaks ties by recency", () => {
|
||||
const prefs = new Map<string, number>();
|
||||
const candidates = [
|
||||
{ id: "old", tags: [], createdAt: new Date("2024-01-01"), ...base },
|
||||
{ id: "new", tags: [], createdAt: new Date("2024-06-01"), ...base },
|
||||
];
|
||||
const ranked = rankForYou(candidates, prefs);
|
||||
expect(ranked.map((r) => r.id)).toEqual(["new", "old"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user