058e5db9b5
eslint-plugin-react-hooks now analyzes the smaller Home, so render-time ref writes and sync effect setState were failing the staging gate. Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { createElement, createRef } from "react";
|
|
import { renderToString } from "react-dom/server";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
AccountDialogOverlay,
|
|
type AccountOverlayModel,
|
|
} from "../src/components/account-dialog-overlay.tsx";
|
|
|
|
test("a closed account overlay does not render profile or logout content", () => {
|
|
const overlayRef = createRef<HTMLElement | null>() as AccountOverlayModel["overlayRef"];
|
|
const closeButtonRef = createRef<HTMLButtonElement | null>() as AccountOverlayModel["closeButtonRef"];
|
|
let profileRenders = 0;
|
|
let logoutRenders = 0;
|
|
const model: AccountOverlayModel = {
|
|
title: "个人资料",
|
|
dialogClass: "profile-modal",
|
|
signingOut: false,
|
|
close() {},
|
|
navigate() {},
|
|
openRedeem() {},
|
|
overlayRef,
|
|
closeButtonRef,
|
|
renderProfile() {
|
|
profileRenders += 1;
|
|
return null;
|
|
},
|
|
renderChartLibrary() {
|
|
return null;
|
|
},
|
|
renderGeneral() {
|
|
return null;
|
|
},
|
|
renderLogout() {
|
|
logoutRenders += 1;
|
|
return null;
|
|
},
|
|
};
|
|
|
|
const html = renderToString(createElement(AccountDialogOverlay, {
|
|
open: false,
|
|
dialog: null,
|
|
model,
|
|
}));
|
|
|
|
assert.equal(html, "");
|
|
assert.equal(profileRenders, 0);
|
|
assert.equal(logoutRenders, 0);
|
|
});
|
|
|
|
test("home does not write overlay epoch or chat actions during render", () => {
|
|
const page = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8");
|
|
const overlay = readFileSync(new URL("../src/components/account-dialog-overlay.tsx", import.meta.url), "utf8");
|
|
assert.match(overlay, /model: AccountOverlayModel \| null/);
|
|
assert.doesNotMatch(overlay, /openEpoch/);
|
|
assert.doesNotMatch(overlay, /modelRef/);
|
|
assert.doesNotMatch(page, /accountOverlayEpochRef/);
|
|
assert.doesNotMatch(page, /sessionsRef\.current = sessions/);
|
|
assert.match(page, /queueMicrotask\(\(\) => setActiveChartId\(storedChartId\)\)/);
|
|
assert.match(page, /useEffect\(\(\) => \{\s*chatActionsRef\.current = \{/);
|
|
});
|