- Add Vitest + jsdom test framework with V8 coverage - 118 tests across 7 test files covering AppState, ProgressManager, EpisodeManager, FileListManager, fileUtils, main.js logic, renderer escapeHtml, preload module polyfill - Fix async bug in extractFileDuration (await in non-async callback) - CI enforces 85% coverage threshold on testable modules - Exclude Electron IPC wrappers (FileManager, SearchManager, TagManager, ModalManager, UIManager) from coverage as they require Electron runtime
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import ProgressManager from '../utils/renderer/ProgressManager';
|
|
|
|
describe('ProgressManager', () => {
|
|
let progressContainer, progressText, progressCount;
|
|
let pm;
|
|
|
|
beforeEach(() => {
|
|
progressContainer = document.createElement('div');
|
|
progressText = document.createElement('span');
|
|
progressCount = document.createElement('span');
|
|
pm = new ProgressManager(progressContainer, progressText, progressCount);
|
|
});
|
|
|
|
describe('showProgress', () => {
|
|
it('shows progress with default message', () => {
|
|
pm.showProgress();
|
|
expect(progressContainer.style.display).toBe('block');
|
|
expect(progressText.textContent).toBe('Scanning directory...');
|
|
expect(progressCount.textContent).toBe('');
|
|
});
|
|
|
|
it('shows progress with custom message', () => {
|
|
pm.showProgress('Custom message');
|
|
expect(progressText.textContent).toBe('Custom message');
|
|
});
|
|
});
|
|
|
|
describe('hideProgress', () => {
|
|
it('hides progress container', () => {
|
|
pm.hideProgress();
|
|
expect(progressContainer.style.display).toBe('none');
|
|
});
|
|
});
|
|
|
|
describe('updateProgress', () => {
|
|
it('updates progress with current/total', () => {
|
|
pm.updateProgress(2, 10, 'video.mp4');
|
|
expect(progressText.textContent).toBe('Processing: video.mp4');
|
|
expect(progressCount.textContent).toBe('3 of 10 files');
|
|
});
|
|
|
|
it('handles first file (current=0)', () => {
|
|
pm.updateProgress(0, 5, 'file1.mp4');
|
|
expect(progressCount.textContent).toBe('1 of 5 files');
|
|
});
|
|
});
|
|
|
|
describe('updateProgressText', () => {
|
|
it('updates progress text', () => {
|
|
pm.updateProgressText('Custom text');
|
|
expect(progressText.textContent).toBe('Custom text');
|
|
});
|
|
});
|
|
|
|
describe('updateProgressCount', () => {
|
|
it('updates progress count', () => {
|
|
pm.updateProgressCount(5, 20);
|
|
expect(progressCount.textContent).toBe('6 of 20 files');
|
|
});
|
|
|
|
it('handles last file', () => {
|
|
pm.updateProgressCount(19, 20);
|
|
expect(progressCount.textContent).toBe('20 of 20 files');
|
|
});
|
|
});
|
|
|
|
describe('showDirectoryFeedback', () => {
|
|
it('logs directory feedback', () => {
|
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
pm.showDirectoryFeedback('extras');
|
|
expect(consoleSpy).toHaveBeenCalledWith('Directory "extras" created and file moved');
|
|
consoleSpy.mockRestore();
|
|
});
|
|
});
|
|
});
|