fix: align chess game tests after rebase
This commit is contained in:
@@ -5,6 +5,7 @@ if (typeof window !== 'undefined') {
|
||||
// Mock scrollIntoView for JSDOM
|
||||
window.HTMLElement.prototype.scrollIntoView = jest.fn();
|
||||
window.HTMLMediaElement.prototype.play = () => Promise.resolve();
|
||||
window.HTMLMediaElement.prototype.pause = jest.fn();
|
||||
}
|
||||
|
||||
// Mock react-markdown to avoid ESM issues in Jest
|
||||
|
||||
@@ -143,6 +143,7 @@ describe("ChessGame Component", () => {
|
||||
});
|
||||
|
||||
it("restores a PGN game and persists save data without apiKey", async () => {
|
||||
await act(async () => {
|
||||
render(
|
||||
<ChessGame
|
||||
gameId="restore-game"
|
||||
@@ -152,6 +153,7 @@ describe("ChessGame Component", () => {
|
||||
onBack={() => {}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
const saved = JSON.parse(localStorage.getItem("chess_tutor_save") || "{}");
|
||||
@@ -196,6 +198,16 @@ describe("ChessGame Component", () => {
|
||||
/>
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(stockfishMock.evaluate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("tutor")).toHaveTextContent("Eval P0: 0.5");
|
||||
});
|
||||
|
||||
stockfishMock.evaluate.mockClear();
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByTestId("chessboard"));
|
||||
fireEvent.click(screen.getByTestId("chessboard"));
|
||||
@@ -203,10 +215,10 @@ describe("ChessGame Component", () => {
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(stockfishMock.evaluate.mock.calls.length).toBeGreaterThanOrEqual(2);
|
||||
expect(stockfishMock.evaluate.mock.calls.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
const playerTriggeredEvaluations = stockfishMock.evaluate.mock.calls.filter(([fen]: [string]) => typeof fen === "string");
|
||||
expect(playerTriggeredEvaluations.length).toBeLessThanOrEqual(3);
|
||||
expect(playerTriggeredEvaluations.length).toBeLessThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -289,7 +289,6 @@ export default function ChessGame({ gameId, initialFen, initialPgn, initialPerso
|
||||
fen,
|
||||
language,
|
||||
selectedPersonality,
|
||||
apiKey,
|
||||
playerColor, // Save player color too
|
||||
pgn: gameRef.current.pgn(),
|
||||
updatedAt: Date.now(),
|
||||
@@ -302,7 +301,7 @@ export default function ChessGame({ gameId, initialFen, initialPgn, initialPerso
|
||||
|
||||
upsertSavedGame(saveData);
|
||||
localStorage.setItem("chess_tutor_save", JSON.stringify(saveData));
|
||||
}, [fen, language, selectedPersonality, apiKey, playerColor, gameId, evalP0]);
|
||||
}, [fen, language, selectedPersonality, playerColor, gameId, evalP0]);
|
||||
|
||||
// Game Over Detection
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user