- Colour tokens reach WCAG AA: lighter muted text and accent in the dark theme, darker muted/success/warning/danger/donate in the light theme, and new accent-solid / danger-solid fills for buttons with white text. tests/styles/contrast.test.ts checks every text token on every surface. - Generated text carries its language (lang) on Output, the YouTube and quick previews, History, Batch, Social and Playlist, so screen readers read Japanese output with a Japanese voice. - RouteAnnouncer reads the new page's name after a navigation; focus stays. - Toast region and close button are translated; Alt+T is in the shortcut list. - Endings table inputs and the custom bank name get accessible names; the From/To headers are translated. - Settings > Editor > Single-key shortcuts turns the bare ? off (WCAG 2.1.4). - Text inputs use outline-hidden so the focus outline shows in Windows High Contrast; the genre remove button is 24px, small close/dismiss buttons grow on touch screens. - Desktop: zoomHotkeysEnabled (Ctrl/Cmd + = / -), with the set-webview-zoom permission for the macOS/Linux polyfill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
362 lines
14 KiB
TypeScript
362 lines
14 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
||
import { healSettings } from "@store/settings-heal";
|
||
|
||
describe("healSettings", () => {
|
||
it("returns a full defaults object when given null / undefined / non-object input", () => {
|
||
const fromNull = healSettings(null);
|
||
const fromUndefined = healSettings(undefined);
|
||
const fromString = healSettings("not an object");
|
||
|
||
// All three should have the full required shape with default-ish values.
|
||
for (const healed of [fromNull, fromUndefined, fromString]) {
|
||
expect(healed.theme).toBe("dark");
|
||
expect(healed.showCharCount).toBe(true);
|
||
expect(healed.compactTagDisplay).toBe(false);
|
||
expect(healed.hashtagCount).toBe(3);
|
||
expect(healed.showQualityBadge).toBe(true);
|
||
expect(healed.showCopyright).toBe(true);
|
||
expect(healed.showUsagePolicy).toBe(false);
|
||
expect(healed.titleFormat).toEqual({
|
||
badgePosition: "middle",
|
||
separator: "emDash",
|
||
badgeCase: "upper",
|
||
order: "gameFirst",
|
||
});
|
||
expect(healed.showPinnedCommentTemplate).toBe(false);
|
||
expect(healed.pinnedCommentIncludeAskNextGame).toBe(true);
|
||
expect(healed.editorAccordionState).toEqual(expect.objectContaining({ gameInfo: true }));
|
||
}
|
||
});
|
||
|
||
it("back-fills missing keys with defaults but keeps user-set values", () => {
|
||
const healed = healSettings({
|
||
theme: "light",
|
||
hashtagCount: 1,
|
||
// showCharCount, compactTagDisplay, etc. all missing
|
||
});
|
||
|
||
expect(healed.theme).toBe("light");
|
||
expect(healed.hashtagCount).toBe(1);
|
||
// Back-filled:
|
||
expect(healed.showCharCount).toBe(true);
|
||
expect(healed.compactTagDisplay).toBe(false);
|
||
expect(healed.showQualityBadge).toBe(true);
|
||
expect(healed.editorAccordionState).toBeDefined();
|
||
});
|
||
|
||
it("strips the removed `autoSaveDraft` key even if persisted", () => {
|
||
const healed = healSettings({ autoSaveDraft: true, theme: "dark" }) as unknown as Record<
|
||
string,
|
||
unknown
|
||
>;
|
||
expect(healed.autoSaveDraft).toBeUndefined();
|
||
});
|
||
|
||
it("strips both legacy `defaultGenre` (v1) and `defaultGenres` (v2-v0.21) — both removed in v0.22.0", () => {
|
||
const healed = healSettings({
|
||
defaultGenre: "rpg",
|
||
defaultGenres: ["horror", "action"],
|
||
}) as unknown as Record<string, unknown>;
|
||
expect(healed.defaultGenre).toBeUndefined();
|
||
expect(healed.defaultGenres).toBeUndefined();
|
||
});
|
||
|
||
it("preserves all keys when given a complete payload", () => {
|
||
const complete = {
|
||
appLanguage: "vi" as const,
|
||
defaultOutputLanguage: "en" as const,
|
||
theme: "light" as const,
|
||
hideScrollbars: true,
|
||
singleKeyShortcuts: false,
|
||
showCharCount: false,
|
||
compactTagDisplay: true,
|
||
historyLimit: 50,
|
||
includeMultilingualTags: false,
|
||
includeTrendingTags: false,
|
||
hashtagCount: 2,
|
||
showQualityBadge: false,
|
||
showCopyright: false,
|
||
showGameCopyright: false,
|
||
showUsagePolicy: true,
|
||
showSponsorCredit: true,
|
||
showThirdPartyAds: false,
|
||
showTranslationQuality: true,
|
||
splitContactEmail: true,
|
||
titleFormat: {
|
||
badgePosition: "prefix" as const,
|
||
separator: "hyphen" as const,
|
||
badgeCase: "lower" as const,
|
||
order: "typeFirst" as const,
|
||
},
|
||
showPinnedCommentTemplate: true,
|
||
pinnedCommentIncludeAskNextGame: false,
|
||
pinnedCommentIncludeGenrePlaylist: true,
|
||
genrePlaylists: { horror: "https://www.youtube.com/playlist?list=abc" },
|
||
editorAccordionState: { gameInfo: false, videoSettings: true },
|
||
sidebarCollapsed: true,
|
||
logRetentionDays: 14,
|
||
legalConsentVersion: 1,
|
||
legalConsentAt: "2026-06-13T00:00:00.000Z",
|
||
strictMode: true,
|
||
// Spelled out in full: `healSettings` merges this map against the
|
||
// defaults, so a partial one here would heal to something wider than
|
||
// `complete` and fail the round-trip. The merge itself is covered below.
|
||
settingsAccordionState: {
|
||
appearance: false,
|
||
defaults: true,
|
||
editorSettings: true,
|
||
guardrails: true,
|
||
titleFormat: true,
|
||
description: true,
|
||
tags: true,
|
||
genrePlaylists: true,
|
||
history: true,
|
||
logs: true,
|
||
},
|
||
copyAllIncludesTags: true,
|
||
lastProfileId: "profile-1",
|
||
lastPresetId: null,
|
||
};
|
||
const healed = healSettings(complete);
|
||
expect(healed).toEqual(complete);
|
||
});
|
||
|
||
describe("v11 → v12 (v0.35.0): strictMode + settingsAccordionState", () => {
|
||
it("defaults strictMode to false when absent", () => {
|
||
expect(healSettings({ theme: "dark" }).strictMode).toBe(false);
|
||
});
|
||
|
||
it("preserves an explicit strictMode", () => {
|
||
expect(healSettings({ strictMode: true }).strictMode).toBe(true);
|
||
});
|
||
|
||
it("coerces a non-boolean strictMode to false rather than trusting truthiness", () => {
|
||
// A hand-edited `"yes"` is truthy in JS. Silently switching the seatbelt
|
||
// on is the opposite of an opt-in, so it must fall back to the default.
|
||
expect(healSettings({ strictMode: "yes" }).strictMode).toBe(false);
|
||
expect(healSettings({ strictMode: 1 }).strictMode).toBe(false);
|
||
expect(healSettings({ strictMode: null }).strictMode).toBe(false);
|
||
});
|
||
|
||
it("back-fills the whole accordion map when absent", () => {
|
||
const healed = healSettings({ theme: "dark" });
|
||
expect(healed.settingsAccordionState.genrePlaylists).toBe(false);
|
||
expect(healed.settingsAccordionState.appearance).toBe(true);
|
||
});
|
||
|
||
it("merges a partial accordion map instead of replacing it", () => {
|
||
// A user who collapsed one section on v0.35.0 must still get defaults
|
||
// for any section added in a later version.
|
||
const healed = healSettings({ settingsAccordionState: { appearance: false } });
|
||
expect(healed.settingsAccordionState.appearance).toBe(false);
|
||
expect(healed.settingsAccordionState.logs).toBe(true);
|
||
expect(healed.settingsAccordionState.genrePlaylists).toBe(false);
|
||
});
|
||
|
||
it("ignores a non-object accordion map", () => {
|
||
const healed = healSettings({ settingsAccordionState: "nope" });
|
||
expect(healed.settingsAccordionState.appearance).toBe(true);
|
||
});
|
||
});
|
||
|
||
it("back-fills logRetentionDays to 7 when absent (pre-v0.17 payload)", () => {
|
||
const healed = healSettings({ theme: "dark" as const });
|
||
expect(healed.logRetentionDays).toBe(7);
|
||
});
|
||
|
||
it("clamps logRetentionDays to [1, 90]", () => {
|
||
expect(healSettings({ logRetentionDays: 0 } as unknown).logRetentionDays).toBe(1);
|
||
expect(healSettings({ logRetentionDays: -5 } as unknown).logRetentionDays).toBe(1);
|
||
expect(healSettings({ logRetentionDays: 1000 } as unknown).logRetentionDays).toBe(90);
|
||
expect(healSettings({ logRetentionDays: 30.7 } as unknown).logRetentionDays).toBe(30);
|
||
});
|
||
|
||
it("back-fills showSponsorCredit default when the key is absent (v3 → v4 payload)", () => {
|
||
// Simulates a settings file written in v0.6 phase 1 where the new
|
||
// sponsor toggle hadn't been introduced yet.
|
||
const healed = healSettings({
|
||
theme: "dark" as const,
|
||
showCopyright: true,
|
||
});
|
||
expect(healed.showSponsorCredit).toBe(false);
|
||
});
|
||
|
||
it("back-fills titleFormat default when the key is absent (v4 → v5 payload)", () => {
|
||
// Simulates a settings file written in v0.6 where titleFormat did
|
||
// not exist yet.
|
||
const healed = healSettings({
|
||
theme: "dark" as const,
|
||
showCopyright: true,
|
||
});
|
||
expect(healed.titleFormat).toEqual({
|
||
badgePosition: "middle",
|
||
separator: "emDash",
|
||
badgeCase: "upper",
|
||
order: "gameFirst",
|
||
});
|
||
});
|
||
|
||
it("merges partial titleFormat, filling missing sub-keys with defaults", () => {
|
||
const healed = healSettings({
|
||
titleFormat: { badgePosition: "prefix" },
|
||
});
|
||
// User-set value preserved:
|
||
expect(healed.titleFormat.badgePosition).toBe("prefix");
|
||
// Missing sub-keys back-filled from defaults:
|
||
expect(healed.titleFormat.separator).toBe("emDash");
|
||
expect(healed.titleFormat.badgeCase).toBe("upper");
|
||
});
|
||
|
||
it("replaces a non-object titleFormat value with defaults", () => {
|
||
// A corrupt on-disk file might have `titleFormat: null` or a string.
|
||
const healedFromNull = healSettings({ titleFormat: null });
|
||
const healedFromString = healSettings({ titleFormat: "bogus" });
|
||
for (const healed of [healedFromNull, healedFromString]) {
|
||
expect(healed.titleFormat).toEqual({
|
||
badgePosition: "middle",
|
||
separator: "emDash",
|
||
badgeCase: "upper",
|
||
order: "gameFirst",
|
||
});
|
||
}
|
||
});
|
||
|
||
it("back-fills pinned-comment toggles when the keys are absent (v5 → v6 payload)", () => {
|
||
// Simulates a settings file written in v0.7 phase 1, before the
|
||
// pinned-comment template feature existed.
|
||
const healed = healSettings({
|
||
theme: "dark" as const,
|
||
titleFormat: {
|
||
badgePosition: "middle",
|
||
separator: "emDash",
|
||
badgeCase: "upper",
|
||
order: "gameFirst",
|
||
},
|
||
});
|
||
expect(healed.showPinnedCommentTemplate).toBe(false);
|
||
expect(healed.pinnedCommentIncludeAskNextGame).toBe(true);
|
||
});
|
||
|
||
it("preserves user-set pinned-comment toggles when they differ from defaults", () => {
|
||
const healed = healSettings({
|
||
showPinnedCommentTemplate: true,
|
||
pinnedCommentIncludeAskNextGame: false,
|
||
});
|
||
expect(healed.showPinnedCommentTemplate).toBe(true);
|
||
expect(healed.pinnedCommentIncludeAskNextGame).toBe(false);
|
||
});
|
||
|
||
it("back-fills genre-playlist defaults when the keys are absent (v6 → v7 payload)", () => {
|
||
// Simulates a settings file written in v0.7 phase 2, before the
|
||
// pinned-comment genre-playlist feature existed.
|
||
const healed = healSettings({
|
||
theme: "dark" as const,
|
||
showPinnedCommentTemplate: true,
|
||
});
|
||
expect(healed.pinnedCommentIncludeGenrePlaylist).toBe(false);
|
||
expect(healed.genrePlaylists).toEqual({});
|
||
});
|
||
|
||
it("preserves user-set genrePlaylists map", () => {
|
||
const healed = healSettings({
|
||
genrePlaylists: {
|
||
horror: "https://www.youtube.com/playlist?list=horror",
|
||
rpg: "https://www.youtube.com/playlist?list=rpg",
|
||
},
|
||
pinnedCommentIncludeGenrePlaylist: true,
|
||
});
|
||
expect(healed.genrePlaylists).toEqual({
|
||
horror: "https://www.youtube.com/playlist?list=horror",
|
||
rpg: "https://www.youtube.com/playlist?list=rpg",
|
||
});
|
||
expect(healed.pinnedCommentIncludeGenrePlaylist).toBe(true);
|
||
});
|
||
|
||
it("replaces a non-object genrePlaylists value with the empty default", () => {
|
||
const healedFromNull = healSettings({ genrePlaylists: null });
|
||
const healedFromString = healSettings({ genrePlaylists: "bogus" });
|
||
for (const healed of [healedFromNull, healedFromString]) {
|
||
expect(healed.genrePlaylists).toEqual({});
|
||
}
|
||
});
|
||
|
||
it("back-fills legalConsentVersion 0 + legalConsentAt null for a legacy payload (pre-v0.28)", () => {
|
||
// A settings file written before the consent gate existed has neither
|
||
// key — it must heal to "never accepted" so the gate shows on first run.
|
||
const healed = healSettings({ theme: "dark" as const, hashtagCount: 3 });
|
||
expect(healed.legalConsentVersion).toBe(0);
|
||
expect(healed.legalConsentAt).toBeNull();
|
||
});
|
||
|
||
it("preserves a stored legalConsentVersion and coerces malformed/negative values to 0", () => {
|
||
expect(healSettings({ legalConsentVersion: 1 }).legalConsentVersion).toBe(1);
|
||
expect(
|
||
healSettings({ legalConsentVersion: "nope" as unknown as number }).legalConsentVersion,
|
||
).toBe(0);
|
||
expect(healSettings({ legalConsentVersion: -3 }).legalConsentVersion).toBe(0);
|
||
expect(healSettings({ legalConsentVersion: 2.9 }).legalConsentVersion).toBe(2);
|
||
});
|
||
});
|
||
|
||
describe("healSettings — historyLimit (v1.0.0)", () => {
|
||
it("clamps the history limit into 10–500", () => {
|
||
expect(healSettings({ historyLimit: 1 }).historyLimit).toBe(10);
|
||
expect(healSettings({ historyLimit: 1e9 }).historyLimit).toBe(500);
|
||
expect(healSettings({ historyLimit: 250.7 }).historyLimit).toBe(250);
|
||
});
|
||
|
||
it("falls back to the default for a non-number", () => {
|
||
expect(healSettings({ historyLimit: "many" }).historyLimit).toBe(100);
|
||
expect(healSettings({ historyLimit: Number.NaN }).historyLimit).toBe(100);
|
||
});
|
||
});
|
||
|
||
describe("healSettings — v1.0.0 fields", () => {
|
||
it("coerces the new fields", () => {
|
||
const healed = healSettings({
|
||
copyAllIncludesTags: "yes",
|
||
lastProfileId: 7,
|
||
lastPresetId: "",
|
||
titleFormat: { order: "sideways" },
|
||
});
|
||
expect(healed.copyAllIncludesTags).toBe(false);
|
||
expect(healed.lastProfileId).toBeNull();
|
||
expect(healed.lastPresetId).toBeNull();
|
||
expect(healed.titleFormat.order).toBe("gameFirst");
|
||
});
|
||
});
|
||
|
||
describe("healSettings — v1.1.0 hideScrollbars", () => {
|
||
it("defaults to showing scrollbars when absent", () => {
|
||
expect(healSettings({ theme: "dark" }).hideScrollbars).toBe(false);
|
||
});
|
||
|
||
it("keeps a real boolean", () => {
|
||
expect(healSettings({ hideScrollbars: true }).hideScrollbars).toBe(true);
|
||
expect(healSettings({ hideScrollbars: false }).hideScrollbars).toBe(false);
|
||
});
|
||
|
||
it("does not let a truthy non-boolean hide every scrollbar", () => {
|
||
expect(healSettings({ hideScrollbars: "yes" }).hideScrollbars).toBe(false);
|
||
expect(healSettings({ hideScrollbars: 1 }).hideScrollbars).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe("healSettings — v1.5.1 singleKeyShortcuts", () => {
|
||
it("keeps the bare ? shortcut on when absent (older settings and backups)", () => {
|
||
expect(healSettings({ theme: "dark" }).singleKeyShortcuts).toBe(true);
|
||
expect(healSettings(null).singleKeyShortcuts).toBe(true);
|
||
});
|
||
|
||
it("keeps a real boolean", () => {
|
||
expect(healSettings({ singleKeyShortcuts: false }).singleKeyShortcuts).toBe(false);
|
||
expect(healSettings({ singleKeyShortcuts: true }).singleKeyShortcuts).toBe(true);
|
||
});
|
||
|
||
it("falls back to on for anything that is not a boolean", () => {
|
||
expect(healSettings({ singleKeyShortcuts: "no" }).singleKeyShortcuts).toBe(true);
|
||
expect(healSettings({ singleKeyShortcuts: 0 }).singleKeyShortcuts).toBe(true);
|
||
expect(healSettings({ singleKeyShortcuts: null }).singleKeyShortcuts).toBe(true);
|
||
});
|
||
});
|