test: Add comprehensive test coverage for untested modules

Add tests for previously untested components and services:
- apiKeyService.ts: localStorage operations (14 tests)
- ApiKeyModal.tsx: form validation, submission (22 tests)
- App.tsx: state transitions, error handling (23 tests)
- latexService.ts: API calls, template detection (35 tests)
- latex_service.py: LaTeX escaping, compilation (59 tests)
- server.py: Flask routes, field mapping (38 tests)

Also fix geminiService tests by adding proper apiKeyService mock.

Total new test coverage: 173 TypeScript tests, 97 Python tests

https://claude.ai/code/session_01D4k6b4nUjwfcHMvectsri2
This commit is contained in:
Claude 2026-01-31 10:33:40 +00:00
parent 1eb00f3d64
commit 04fe925891
No known key found for this signature in database
7 changed files with 2158 additions and 8 deletions

View file

@ -2,17 +2,25 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { FileData, FormResponse } from '../../types';
import { PdfFieldInfo } from '../../services/pdfService';
// Create a mock function that can be referenced in the mock
// Mock the apiKeyService module - MUST be before geminiService import
vi.mock('../../services/apiKeyService', () => ({
getApiKey: vi.fn(() => 'AItest123'),
setApiKey: vi.fn(),
hasApiKey: vi.fn(() => true),
clearApiKey: vi.fn(),
}));
// Create mock function in module scope that will be hoisted properly
const mockGenerateContent = vi.fn();
// Mock the @google/genai module
vi.mock('@google/genai', async () => {
// Mock the @google/genai module using factory that references mockGenerateContent
vi.mock('@google/genai', () => {
return {
GoogleGenAI: vi.fn().mockImplementation(() => ({
models: {
GoogleGenAI: class MockGoogleGenAI {
models = {
generateContent: mockGenerateContent
}
})),
};
},
Type: {
OBJECT: 'OBJECT',
STRING: 'STRING',
@ -24,7 +32,7 @@ vi.mock('@google/genai', async () => {
});
// Import after mocking
const { processDocuments } = await import('../../services/geminiService');
import { processDocuments } from '../../services/geminiService';
describe('geminiService', () => {
const mockBlankForm: FileData = {