Files
chess-project/src/components/__tests__/Tutor.test.tsx
T
Stefan 49effedf61 Complete tactic recognition module with tests and real-time integration
- Add comprehensive test suite (20 tests) for tactic detection
- Fix pawn detection threshold bug (200 -> 100 centipawns)
- Add error handling to uciToSan for invalid moves
- Integrate tactical data into Tutor component for real-time feedback
- Pass missedTactics from ChessGame to Tutor via props
- Update LLM prompt to explain missed tactical opportunities
- Fix Jest configuration to handle react-markdown ESM issues
- All 50 tests passing
2025-11-26 16:51:38 +01:00

71 lines
1.7 KiB
TypeScript

import { render, screen, fireEvent, act } from '@testing-library/react';
import { Tutor } from '../Tutor';
import { Stockfish } from '@/lib/stockfish';
import { Chess } from 'chess.js';
import * as gemini from '@/lib/gemini';
jest.mock('@/lib/stockfish');
jest.mock('@/lib/gemini');
describe('Tutor', () => {
let stockfish: Stockfish;
let game: Chess;
beforeEach(() => {
stockfish = new Stockfish();
game = new Chess();
(gemini.getGenAIModel as jest.Mock).mockReturnValue({
startChat: jest.fn().mockReturnValue({
sendMessage: jest.fn().mockResolvedValue({
response: {
text: () => 'Test response',
},
}),
}),
});
});
it('should call evaluateCurrentPosition when hint button is clicked', async () => {
const evaluateSpy = jest.spyOn(stockfish, 'evaluate').mockResolvedValue({
bestMove: 'e2e4',
ponder: 'e7e5',
score: 10,
mate: null,
depth: 15,
});
render(
<Tutor
game={game}
currentFen={game.fen()}
userMove={null}
computerMove={null}
stockfish={stockfish}
evalP0={null}
evalP2={null}
openingData={null}
missedTactics={null}
onAnalysisComplete={() => {}}
apiKey="test-api-key"
personality={{
name: "Test Personality",
systemPrompt: "Test Prompt",
image: "🤖"
}}
language="en"
playerColor="white"
onCheckComputerMove={() => {}}
/>
);
const hintButton = screen.getByText(/hint/i);
await act(async () => {
fireEvent.click(hintButton);
});
expect(evaluateSpy).toHaveBeenCalledWith(game.fen(), 15);
});
});