Files
memos/web/tests/user-theme.test.tsx
T
boojack 153625210b chore: open calendar and map to guests, simplify navigation
Calendar and Map are reading views like Timeline, so signed-out visitors
can now open them and see the memos readable to them. Their Space
variants still require sign-in, and composing stays signed-in only.

Navigation:
- Guests get Timeline, Calendar, Map; Attachments stays signed-in only.
  The About pill is gone; About lives in the scope menu and the common
  sidebar for everyone.
- One NavPill renders every nav control, from a single destination list.
- A memo list without a creator is Explore, so Timeline sends guests
  there directly instead of through the Home redirect.

Scope menu:
- One UserMenu for both cases: preferences, then account pages when
  signed in. Guests sign in from the sidebar footer only.
- Guests no longer see a Browse control whose only option is Explore.
- Theme and Language are submenus instead of dialogs; a choice applies
  at once, saved to the account or kept locally for guests.
- The system theme listener reads the latest preference, so local guest
  choices follow OS changes correctly.
2026-09-26 17:09:15 +08:00

43 lines
1.4 KiB
TypeScript

import { renderHook } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { useUserTheme } from "@/hooks/useUserTheme";
import { loadTheme } from "@/utils/theme";
vi.mock("@/contexts/AuthContext", () => ({
useAuth: () => ({ userGeneralSetting: undefined }),
}));
describe("guest theme preferences", () => {
afterEach(() => {
vi.unstubAllGlobals();
localStorage.clear();
});
it.each(["system", "default-dark"])("respects local changes after starting with %s", (initialTheme) => {
let dark = false;
const changes = new EventTarget();
vi.stubGlobal("matchMedia", () => ({
get matches() {
return dark;
},
addEventListener: changes.addEventListener.bind(changes),
removeEventListener: changes.removeEventListener.bind(changes),
}));
loadTheme(initialTheme);
renderHook(() => useUserTheme());
loadTheme("paper");
dark = true;
changes.dispatchEvent(new Event("change"));
expect(document.documentElement).toHaveAttribute("data-theme", "paper");
expect(localStorage.getItem("memos-theme")).toBe("paper");
loadTheme("system");
expect(document.documentElement).toHaveAttribute("data-theme", "default-dark");
dark = false;
changes.dispatchEvent(new Event("change"));
expect(document.documentElement).toHaveAttribute("data-theme", "default");
expect(localStorage.getItem("memos-theme")).toBe("system");
});
});