mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
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:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Component: Path Mapper Tests
|
||||
* Documentation: documentation/phase3/qbittorrent.md
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { PathMapper } from '@/lib/utils/path-mapper';
|
||||
|
||||
describe('PathMapper', () => {
|
||||
it('returns original path when mapping is disabled', () => {
|
||||
const result = PathMapper.transform('/remote/path/book', {
|
||||
enabled: false,
|
||||
remotePath: '/remote/path',
|
||||
localPath: '/local/path',
|
||||
});
|
||||
|
||||
expect(result).toBe('/remote/path/book');
|
||||
});
|
||||
|
||||
it('transforms remote path to local path when enabled', () => {
|
||||
const result = PathMapper.transform('/remote/mnt/d/done/Book', {
|
||||
enabled: true,
|
||||
remotePath: '/remote/mnt/d/done',
|
||||
localPath: '/downloads',
|
||||
});
|
||||
|
||||
expect(result.replace(/\\/g, '/')).toBe('/downloads/Book');
|
||||
});
|
||||
|
||||
it('returns original path when remote prefix does not match', () => {
|
||||
const result = PathMapper.transform('/other/path/book', {
|
||||
enabled: true,
|
||||
remotePath: '/remote/path',
|
||||
localPath: '/local/path',
|
||||
});
|
||||
|
||||
expect(result).toBe('/other/path/book');
|
||||
});
|
||||
|
||||
it('validates mapping configuration when enabled', () => {
|
||||
expect(() =>
|
||||
PathMapper.validate({ enabled: true, remotePath: '', localPath: '/local' })
|
||||
).toThrow('Remote path cannot be empty');
|
||||
expect(() =>
|
||||
PathMapper.validate({ enabled: true, remotePath: '/remote', localPath: '' })
|
||||
).toThrow('Local path cannot be empty');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user