mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-07-14 16:51: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,62 @@
|
||||
/**
|
||||
* Component: Library Service Factory Tests
|
||||
* Documentation: documentation/features/audiobookshelf-integration.md
|
||||
*/
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { clearLibraryServiceCache, getLibraryService } from '@/lib/services/library';
|
||||
|
||||
const MockPlexService = vi.hoisted(() => class MockPlexService {});
|
||||
const MockAbsService = vi.hoisted(() => class MockAbsService {});
|
||||
|
||||
const configServiceMock = vi.hoisted(() => ({
|
||||
getBackendMode: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/services/config.service', () => ({
|
||||
getConfigService: () => configServiceMock,
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/services/library/PlexLibraryService', () => ({
|
||||
PlexLibraryService: MockPlexService,
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/services/library/AudiobookshelfLibraryService', () => ({
|
||||
AudiobookshelfLibraryService: MockAbsService,
|
||||
}));
|
||||
|
||||
describe('Library service factory', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
clearLibraryServiceCache();
|
||||
});
|
||||
|
||||
it('returns Plex service when backend mode is plex', async () => {
|
||||
configServiceMock.getBackendMode.mockResolvedValue('plex');
|
||||
|
||||
const service = await getLibraryService();
|
||||
|
||||
expect(service).toBeInstanceOf(MockPlexService);
|
||||
});
|
||||
|
||||
it('returns cached service when mode is unchanged', async () => {
|
||||
configServiceMock.getBackendMode.mockResolvedValue('plex');
|
||||
|
||||
const first = await getLibraryService();
|
||||
const second = await getLibraryService();
|
||||
|
||||
expect(first).toBe(second);
|
||||
});
|
||||
|
||||
it('switches to Audiobookshelf service when mode changes', async () => {
|
||||
configServiceMock.getBackendMode
|
||||
.mockResolvedValueOnce('plex')
|
||||
.mockResolvedValueOnce('audiobookshelf');
|
||||
|
||||
const first = await getLibraryService();
|
||||
const second = await getLibraryService();
|
||||
|
||||
expect(first).toBeInstanceOf(MockPlexService);
|
||||
expect(second).toBeInstanceOf(MockAbsService);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user