feat: add comprehensive unit and integration testing infrastructure
Run Tests / Backend Tests (pull_request) Has been cancelled
Run Tests / Frontend Tests (pull_request) Has been cancelled
Run Tests / Test Summary (pull_request) Has been cancelled

- Backend: pytest with unit tests (auth, rbac, config) and integration tests (auth flow, docker, files)
- Frontend: vitest with unit tests (api client) and component tests (login)
- CI: Gitea Actions workflow for automated testing with coverage reports
- Documentation: TESTING.md guide with setup, usage, and best practices
- Coverage goals: 80%+ backend, 70%+ frontend
This commit is contained in:
Gan, Jimmy
2026-03-30 11:11:39 +08:00
parent 99b626eadc
commit 8431920d26
20 changed files with 3313 additions and 1 deletions
+85
View File
@@ -0,0 +1,85 @@
/**
* Global test setup for Vitest
*/
import { vi } from 'vitest';
// Mock Web APIs that may not be available in jsdom
// Mock WebSocket
global.WebSocket = class MockWebSocket {
constructor(url) {
this.url = url;
this.readyState = 0; // CONNECTING
setTimeout(() => {
this.readyState = 1; // OPEN
this.onopen?.();
}, 0);
}
send(data) {}
close() {
this.readyState = 3; // CLOSED
this.onclose?.();
}
addEventListener(event, handler) {
this[`on${event}`] = handler;
}
};
// Mock Web Speech API
global.SpeechRecognition = vi.fn(() => ({
start: vi.fn(),
stop: vi.fn(),
abort: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn()
}));
global.webkitSpeechRecognition = global.SpeechRecognition;
global.speechSynthesis = {
speak: vi.fn(),
cancel: vi.fn(),
pause: vi.fn(),
resume: vi.fn(),
getVoices: vi.fn(() => [])
};
global.SpeechSynthesisUtterance = vi.fn();
// Mock WebAuthn
global.navigator.credentials = {
create: vi.fn(),
get: vi.fn()
};
// Mock localStorage
const localStorageMock = {
getItem: vi.fn(),
setItem: vi.fn(),
removeItem: vi.fn(),
clear: vi.fn()
};
global.localStorage = localStorageMock;
// Mock ResizeObserver
global.ResizeObserver = vi.fn(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn()
}));
// Mock MutationObserver
global.MutationObserver = vi.fn(() => ({
observe: vi.fn(),
disconnect: vi.fn(),
takeRecords: vi.fn(() => [])
}));
// Mock fetch
global.fetch = vi.fn();
// Reset mocks before each test
beforeEach(() => {
vi.clearAllMocks();
localStorageMock.getItem.mockReturnValue(null);
});