- Add double-click handler to make file names editable in UI - Remove duplicate IPC handler for rename-file in renderer.js - Fix checkEpisodeCountMatch to properly validate sequential episodes - Fix begin-mapping to handle both season folder and show folder cases - Improve open-file-in-player handler to properly log results
174 lines
6.7 KiB
JavaScript
174 lines
6.7 KiB
JavaScript
// Test folder navigation stack functionality
|
|
const { test } = require('node:test');
|
|
const assert = require('assert');
|
|
const AppState = require('./utils/renderer/AppState');
|
|
|
|
test('AppState navigation stack starts empty', () => {
|
|
const state = new AppState();
|
|
|
|
assert.strictEqual(state.navigationStack.length, 0, 'Navigation stack should start empty');
|
|
assert.strictEqual(state.currentDepth, 0, 'Current depth should start at 0');
|
|
});
|
|
|
|
test('AppState can add directories to navigation stack', () => {
|
|
const state = new AppState();
|
|
|
|
// Add first directory
|
|
state.addToNavigationStack('/test/dir1');
|
|
assert.strictEqual(state.navigationStack.length, 1, 'Should have 1 directory in stack');
|
|
assert.strictEqual(state.currentDepth, 0, 'Current depth should be 0');
|
|
assert.strictEqual(state.navigationStack[0], '/test/dir1', 'First directory should be /test/dir1');
|
|
|
|
// Add second directory
|
|
state.addToNavigationStack('/test/dir2');
|
|
assert.strictEqual(state.navigationStack.length, 2, 'Should have 2 directories in stack');
|
|
assert.strictEqual(state.currentDepth, 1, 'Current depth should be 1');
|
|
assert.strictEqual(state.navigationStack[1], '/test/dir2', 'Second directory should be /test/dir2');
|
|
|
|
// Add third directory
|
|
state.addToNavigationStack('/test/dir3');
|
|
assert.strictEqual(state.navigationStack.length, 3, 'Should have 3 directories in stack');
|
|
assert.strictEqual(state.currentDepth, 2, 'Current depth should be 2');
|
|
assert.strictEqual(state.navigationStack[2], '/test/dir3', 'Third directory should be /test/dir3');
|
|
});
|
|
|
|
test('AppState navigation stack supports going back', () => {
|
|
const state = new AppState();
|
|
|
|
// Add directories
|
|
state.addToNavigationStack('/test/dir1');
|
|
state.addToNavigationStack('/test/dir2');
|
|
state.addToNavigationStack('/test/dir3');
|
|
|
|
// Verify initial state
|
|
assert.strictEqual(state.canGoBack(), true, 'Should be able to go back from dir3');
|
|
|
|
// Go back once
|
|
const backDir1 = state.goBack();
|
|
assert.strictEqual(backDir1, '/test/dir2', 'Should go back to dir2');
|
|
assert.strictEqual(state.currentDepth, 1, 'Current depth should be 1');
|
|
assert.strictEqual(state.canGoBack(), true, 'Should still be able to go back from dir2');
|
|
|
|
// Go back again
|
|
const backDir2 = state.goBack();
|
|
assert.strictEqual(backDir2, '/test/dir1', 'Should go back to dir1');
|
|
assert.strictEqual(state.currentDepth, 0, 'Current depth should be 0');
|
|
assert.strictEqual(state.canGoBack(), false, 'Should not be able to go back from dir1');
|
|
|
|
// Try to go back when at root
|
|
const backDir3 = state.goBack();
|
|
assert.strictEqual(backDir3, null, 'Should return null when at root');
|
|
});
|
|
|
|
test('AppState navigation stack clears forward history', () => {
|
|
const state = new AppState();
|
|
|
|
// Navigate forward: dir1 -> dir2 -> dir3
|
|
state.addToNavigationStack('/test/dir1');
|
|
state.addToNavigationStack('/test/dir2');
|
|
state.addToNavigationStack('/test/dir3');
|
|
|
|
// Go back to dir2
|
|
state.goBack();
|
|
assert.strictEqual(state.currentDepth, 1, 'Should be at dir2');
|
|
|
|
// Navigate forward from dir2 to dir4
|
|
state.addToNavigationStack('/test/dir4');
|
|
|
|
// Verify forward history is cleared
|
|
assert.strictEqual(state.navigationStack.length, 3, 'Should still have 3 entries');
|
|
assert.strictEqual(state.navigationStack[0], '/test/dir1', 'First entry should still be dir1');
|
|
assert.strictEqual(state.navigationStack[1], '/test/dir2', 'Second entry should still be dir2');
|
|
assert.strictEqual(state.navigationStack[2], '/test/dir4', 'Third entry should be dir4 (not dir3)');
|
|
assert.strictEqual(state.currentDepth, 2, 'Current depth should be 2');
|
|
});
|
|
|
|
test('AppState getCurrentDirectoryFromStack works correctly', () => {
|
|
const state = new AppState();
|
|
|
|
// Empty stack
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), null, 'Should return null for empty stack');
|
|
|
|
// Add directory
|
|
state.addToNavigationStack('/test/dir1');
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), '/test/dir1', 'Should return dir1');
|
|
|
|
// Add another directory
|
|
state.addToNavigationStack('/test/dir2');
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), '/test/dir2', 'Should return dir2');
|
|
|
|
// Go back
|
|
state.goBack();
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), '/test/dir1', 'Should return dir1 after going back');
|
|
});
|
|
|
|
test('AppState navigation depth tracking', () => {
|
|
const state = new AppState();
|
|
|
|
assert.strictEqual(state.getNavigationDepth(), 0, 'Initial depth should be 0');
|
|
|
|
state.addToNavigationStack('/test/dir1');
|
|
assert.strictEqual(state.getNavigationDepth(), 0, 'Depth should be 0 at root');
|
|
|
|
state.addToNavigationStack('/test/dir2');
|
|
assert.strictEqual(state.getNavigationDepth(), 1, 'Depth should be 1 after one navigation');
|
|
|
|
state.addToNavigationStack('/test/dir3');
|
|
assert.strictEqual(state.getNavigationDepth(), 2, 'Depth should be 2 after two navigations');
|
|
|
|
state.goBack();
|
|
assert.strictEqual(state.getNavigationDepth(), 1, 'Depth should be 1 after going back once');
|
|
});
|
|
|
|
test('AppState navigation stack reset', () => {
|
|
const state = new AppState();
|
|
|
|
// Add some directories
|
|
state.addToNavigationStack('/test/dir1');
|
|
state.addToNavigationStack('/test/dir2');
|
|
assert.strictEqual(state.navigationStack.length, 2, 'Should have 2 directories');
|
|
|
|
// Reset
|
|
state.reset();
|
|
assert.strictEqual(state.navigationStack.length, 0, 'Navigation stack should be empty after reset');
|
|
assert.strictEqual(state.currentDepth, 0, 'Current depth should be 0 after reset');
|
|
});
|
|
|
|
test('AppState handles special folder names', () => {
|
|
const state = new AppState();
|
|
|
|
// Test special folder names
|
|
const specialFolders = ['extras', 'behind the scenes', 'delete', 'trailers'];
|
|
|
|
specialFolders.forEach(folder => {
|
|
state.addToNavigationStack(`/test/source/${folder}`);
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), `/test/source/${folder}`);
|
|
state.goBack();
|
|
});
|
|
});
|
|
|
|
test('AppState handles nested paths', () => {
|
|
const state = new AppState();
|
|
|
|
// Test deeply nested paths
|
|
const nestedPath = '/Users/testuser/Movies/Show Name/Season 1/extras';
|
|
state.addToNavigationStack(nestedPath);
|
|
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), nestedPath);
|
|
assert.strictEqual(state.getNavigationDepth(), 0);
|
|
});
|
|
|
|
test('AppState handles same directory multiple times', () => {
|
|
const state = new AppState();
|
|
|
|
// Navigate to same directory multiple times
|
|
state.addToNavigationStack('/test/dir1');
|
|
state.addToNavigationStack('/test/dir2');
|
|
state.addToNavigationStack('/test/dir1'); // Go back to dir1
|
|
|
|
assert.strictEqual(state.getCurrentDirectoryFromStack(), '/test/dir1');
|
|
assert.strictEqual(state.getNavigationDepth(), 2);
|
|
assert.strictEqual(state.getNavigationStack().length, 3);
|
|
});
|
|
|
|
console.log('All navigation stack tests passed!'); |