Files
jobtrackingapp/job-tracker-ui/src/setupTests.ts
T
cesnimda 6150e7f19b test(ui): stabilize slow suites and repair stale trust-loop mocks
- Raise testing-library asyncUtilTimeout to 4s and jest timeout to 30s:
  heavy MUI views exceeded the 1s default on slower machines
  (profile-page, daily-control-loop double-mount).
- end-to-end-trust-loop: mock the /tailored-cv-draft endpoint the
  redesigned Tailored CV tab now loads, and assert on the structured
  draft instead of the removed legacy tailoredCvText textarea.

Full suite now green locally: 18/18 suites, 39/39 tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 22:00:26 +02:00

66 lines
2.7 KiB
TypeScript

import React from 'react';
import { configure } from '@testing-library/react';
// Heavy MUI views (job table, workspace dialog, profile page) can exceed the
// 1s default async query timeout on slower machines; findBy*/waitFor assertions
// still resolve as soon as the element appears.
configure({ asyncUtilTimeout: 4000 });
jest.setTimeout(30000);
jest.mock('./api', () => ({
api: {
get: jest.fn(),
post: jest.fn(() => Promise.resolve({ data: {} })),
put: jest.fn(() => Promise.resolve({ data: {} })),
patch: jest.fn(() => Promise.resolve({ data: {} })),
delete: jest.fn(() => Promise.resolve({ data: {} })),
interceptors: { request: { use: jest.fn() }, response: { use: jest.fn() } },
},
getApiErrorMessage: jest.fn((error: any, fallback?: string) => {
const text = typeof error?.response?.data === 'string' && error.response.data.trim()
? error.response.data.trim()
: typeof error?.message === 'string' && error.message.trim()
? error.message.trim()
: '';
if (!text) return fallback || 'Request failed.';
if (/<\s*html\b|<\s*body\b|<\s*head\b|<\s*title\b|<\s*!doctype\b/i.test(text)) return fallback || 'Request failed.';
return text.length > 300 ? `${text.slice(0, 297).trimEnd()}...` : text;
}),
}));
jest.mock('./components/GoogleAuthCard', () => () => null);
beforeEach(() => {
const { api } = require('./api');
api.get.mockImplementation((url: string) => {
if (url === '/auth/config') {
return Promise.resolve({ data: { requireAuth: false, googleEnabled: false, localEnabled: true, allowRegistration: false } });
}
if (url === '/auth/me') {
return Promise.resolve({ data: { roles: [], email: 'demo@example.com', userName: 'demo' } });
}
if (url === '/jobapplications/reminders') {
return Promise.resolve({ data: [] });
}
if (url === '/companies') {
return Promise.resolve({ data: [] });
}
if (url === '/jobapplications') {
return Promise.resolve({ data: { items: [], total: 0, page: 1, pageSize: 15 } });
}
if (url === '/jobapplications/stats') {
return Promise.resolve({ data: { total: 0, active: 0, deleted: 0, byStatus: {}, appliedLast30Days: 0, averageDaysSinceApplied: 0 } });
}
if (url === '/jobapplications/analytics-overview') {
return Promise.resolve({ data: { funnel: [], responseRateBySource: [], topCompanies: [], totalResponses: 0, totalActive: 0 } });
}
if (url === '/jobapplications/analytics' || url === '/jobapplications/tags') {
return Promise.resolve({ data: [] });
}
if (url === '/jobapplications/tag-trends') {
return Promise.resolve({ data: { months: [], series: [] } });
}
return Promise.resolve({ data: [] });
});
});