fix(auth): stabilize hydration-dependent UI

This commit is contained in:
2026-07-14 13:27:41 +08:00
parent b6551b6a5a
commit 8eaea17156
8 changed files with 175 additions and 66 deletions
@@ -1,25 +1,11 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { describe, expect, it } from "vitest";
import { SplashBackground } from "../splash-background";
import { SplashButton } from "../splash-button";
import { SplashContent } from "../splash-content";
import { SplashLogo } from "../splash-logo";
const authStateMock = vi.hoisted(() => ({
value: {
authPanelMode: "facebook",
isLoading: false,
errorMessage: null,
loginStatus: "notLoggedIn",
hasInitialized: true,
},
}));
vi.mock("@/stores/auth/auth-context", () => ({
useAuthState: () => authStateMock.value,
}));
describe("splash Tailwind components", () => {
it("renders SplashLogo with Tailwind wrapper and image classes", () => {
const html = renderToStaticMarkup(<SplashLogo />);
@@ -48,33 +34,19 @@ describe("splash Tailwind components", () => {
expect(html).toContain("Welcome to my secret hideout");
});
it("renders SplashButton ready and loading states", () => {
authStateMock.value = {
...authStateMock.value,
hasInitialized: true,
isLoading: false,
};
const readyHtml = renderToStaticMarkup(
it("renders SplashButton as an always-ready action", () => {
const html = renderToStaticMarkup(
<SplashButton onStartChat={() => undefined} />,
);
authStateMock.value = {
...authStateMock.value,
hasInitialized: false,
isLoading: false,
};
const loadingHtml = renderToStaticMarkup(
<SplashButton onStartChat={() => undefined} />,
);
expect(readyHtml).toContain("z-2");
expect(readyHtml).toContain("max-w-120");
expect(readyHtml).toContain("bg-[linear-gradient(to_right");
expect(readyHtml).toContain("active:enabled:scale-96");
expect(readyHtml).toContain("active:enabled:brightness-90");
expect(readyHtml).toContain("touch-manipulation");
expect(readyHtml).toContain("Start Chatting");
expect(loadingHtml).toContain("disabled");
expect(loadingHtml).toContain("animate-spin");
expect(html).toContain("z-2");
expect(html).toContain("max-w-120");
expect(html).toContain("bg-[linear-gradient(to_right");
expect(html).toContain("active:enabled:scale-96");
expect(html).toContain("active:enabled:brightness-90");
expect(html).toContain("touch-manipulation");
expect(html).toContain("Start Chatting");
expect(html).not.toContain("disabled=\"");
expect(html).not.toContain("animate-spin");
});
});