feat(routines): record which games' built-ins are on, and who was asked
Both prefs are absent unless the reader answers, so built-ins are opt-in for every install, old ones included. The question is asked only about a game on screen, and only once. A built-in the reader made their own stays hidden while the copy exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8aa820e2c0
commit
bfd79c295e
3 files changed
+87
-1
No files matched your search
+38
-1
@@ -1,5 +1,12 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { ROUTINES, RoutineSchema, routinesFor } from "../src/shared/routines.ts";
|
||||
import {
|
||||
activeRoutines,
|
||||
ROUTINES,
|
||||
RoutineSchema,
|
||||
routinesFor,
|
||||
routineToAsk,
|
||||
} from "../src/shared/routines.ts";
|
||||
import { restorePrefsValue } from "../src/client/state/usePrefs.ts";
|
||||
import { taskStatus } from "../src/shared/task.ts";
|
||||
|
||||
/**
|
||||
@@ -46,3 +53,33 @@ describe("ROUTINES", () => {
|
||||
expect(s).toMatchObject({ scope: "week", count: 900, required: 1300 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("which built-ins are on", () => {
|
||||
test("only for games the reader said yes to", () => {
|
||||
expect(activeRoutines(undefined, new Set()).map((r) => r.id)).toEqual([]);
|
||||
expect(activeRoutines(["zzz"], new Set()).map((r) => r.id)).toEqual(["routine:zzz:ridu-weekly"]);
|
||||
});
|
||||
|
||||
test("one the reader made their own is hidden while the copy exists", () => {
|
||||
expect(activeRoutines(["zzz", "endfield"], new Set(["routine:zzz:ridu-weekly"])).map((r) => r.id))
|
||||
.toEqual(["routine:endfield:weekly-routine"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("which game to ask about", () => {
|
||||
test("the first game on screen with built-ins, not asked and not on", () => {
|
||||
expect(routineToAsk(["genshin", "zzz", "endfield"], undefined, undefined)).toBe("zzz");
|
||||
expect(routineToAsk(["genshin", "zzz", "endfield"], undefined, ["zzz"])).toBe("endfield");
|
||||
expect(routineToAsk(["zzz"], ["zzz"], undefined)).toBeNull();
|
||||
expect(routineToAsk(["genshin"], undefined, undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("restoring prefs with the new fields", () => {
|
||||
test("junk in the arrays is sanitised, and absent stays absent", () => {
|
||||
const r = restorePrefsValue({ routineGames: ["zzz", 7], routinesAsked: "zzz" });
|
||||
expect(r.routineGames).toEqual(["zzz"]);
|
||||
expect(r.routinesAsked).toBeUndefined();
|
||||
expect(restorePrefsValue({}).routineGames).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user