feat: add comprehensive unit and integration testing infrastructure
- 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:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Component tests for Login.svelte
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||
import Login from '../../src/routes/Login.svelte';
|
||||
|
||||
// Mock the API module
|
||||
vi.mock('../../src/lib/api.js', () => ({
|
||||
login: vi.fn(),
|
||||
setToken: vi.fn(),
|
||||
setCurrentUser: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Login Component', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should render login form', () => {
|
||||
render(Login);
|
||||
|
||||
// Check for username and password inputs
|
||||
expect(screen.getByLabelText(/username/i) || screen.getByPlaceholderText(/username/i)).toBeTruthy();
|
||||
expect(screen.getByLabelText(/password/i) || screen.getByPlaceholderText(/password/i)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have login button', () => {
|
||||
render(Login);
|
||||
|
||||
const loginButton = screen.getByRole('button', { name: /login/i }) ||
|
||||
screen.getByText(/login/i);
|
||||
expect(loginButton).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should accept user input', async () => {
|
||||
render(Login);
|
||||
|
||||
const usernameInput = screen.getByLabelText(/username/i) ||
|
||||
screen.getByPlaceholderText(/username/i);
|
||||
const passwordInput = screen.getByLabelText(/password/i) ||
|
||||
screen.getByPlaceholderText(/password/i);
|
||||
|
||||
await fireEvent.input(usernameInput, { target: { value: 'testuser' } });
|
||||
await fireEvent.input(passwordInput, { target: { value: 'testpass' } });
|
||||
|
||||
expect(usernameInput.value).toBe('testuser');
|
||||
expect(passwordInput.value).toBe('testpass');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user