Files
DeepTutor/web/tests/app-shell-code-block-hydration.spec.tsx
Bingxi Zhao (Frank) 04040a2c06 release: v1.6.5
Ship a content workspace you choose, one exec tool for every language,
Mastery Path modes that gate its tools, and Settings that grades
readiness instead of listing faults.

Release notes: assets/releases/ver1-6-5.md
2026-09-06 13:46:29 +08:00

53 lines
1.6 KiB
TypeScript

import { render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it } from "vitest";
import { AppShellProvider, useAppShell } from "@/context/AppShellContext";
import {
CODE_BLOCK_SHOW_LINE_NUMBERS_STORAGE_KEY,
CODE_BLOCK_THEME_STORAGE_KEY,
CODE_BLOCK_WRAP_LONG_LINES_STORAGE_KEY,
LANGUAGE_STORAGE_KEY,
} from "@/context/app-shell-storage";
function CodeBlockPreferencesProbe() {
const {
codeBlockTheme,
codeBlockShowLineNumbers,
codeBlockWrapLongLines,
} = useAppShell();
return (
<output
aria-label="code block preferences"
data-theme={codeBlockTheme}
data-show-line-numbers={String(codeBlockShowLineNumbers)}
data-wrap-long-lines={String(codeBlockWrapLongLines)}
/>
);
}
describe("AppShellProvider code-block hydration", () => {
beforeEach(() => {
localStorage.setItem(LANGUAGE_STORAGE_KEY, "en");
});
it("rehydrates all persisted code-block preferences after mounting", async () => {
localStorage.setItem(CODE_BLOCK_THEME_STORAGE_KEY, "dracula");
localStorage.setItem(CODE_BLOCK_SHOW_LINE_NUMBERS_STORAGE_KEY, "true");
localStorage.setItem(CODE_BLOCK_WRAP_LONG_LINES_STORAGE_KEY, "true");
render(
<AppShellProvider>
<CodeBlockPreferencesProbe />
</AppShellProvider>,
);
const preferences = screen.getByLabelText("code block preferences");
await waitFor(() => {
expect(preferences).toHaveAttribute("data-theme", "dracula");
expect(preferences).toHaveAttribute("data-show-line-numbers", "true");
expect(preferences).toHaveAttribute("data-wrap-long-lines", "true");
});
});
});