Add backend unit test framework and modularize settings UI

Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
This commit is contained in:
kikootwo
2026-01-15 16:49:59 -05:00
parent b3f89d67bb
commit 94dbaf073b
127 changed files with 23549 additions and 2868 deletions
@@ -0,0 +1,84 @@
/**
* Component: Paths Settings Tab - Custom Hook
* Documentation: documentation/settings-pages.md
*/
'use client';
import { useState } from 'react';
import type { PathsSettings, TestResult } from '../../lib/types';
interface UsePathsSettingsProps {
paths: PathsSettings;
onChange: (paths: PathsSettings) => void;
onValidationChange: (isValid: boolean) => void;
}
export function usePathsSettings({ paths, onChange, onValidationChange }: UsePathsSettingsProps) {
const [testing, setTesting] = useState(false);
const [testResult, setTestResult] = useState<TestResult | null>(null);
/**
* Update a single path field
*/
const updatePath = (field: keyof PathsSettings, value: string | boolean) => {
onChange({ ...paths, [field]: value });
onValidationChange(false);
};
/**
* Test if paths are valid and writable
*/
const testPaths = async () => {
setTesting(true);
setTestResult(null);
try {
const response = await fetch('/api/setup/test-paths', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
downloadDir: paths.downloadDir,
mediaDir: paths.mediaDir,
}),
});
const data = await response.json();
if (data.success) {
const result: TestResult = {
success: true,
message: 'All paths are valid and writable'
};
setTestResult(result);
onValidationChange(true);
return result;
} else {
const result: TestResult = {
success: false,
message: data.error || 'Path validation failed'
};
setTestResult(result);
onValidationChange(false);
return result;
}
} catch (error) {
const result: TestResult = {
success: false,
message: error instanceof Error ? error.message : 'Failed to test paths'
};
setTestResult(result);
onValidationChange(false);
return result;
} finally {
setTesting(false);
}
};
return {
testing,
testResult,
updatePath,
testPaths,
};
}