- 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
315 lines
9.8 KiB
Plaintext
315 lines
9.8 KiB
Plaintext
// Test folder click handler functionality - simplified version
|
|
const { test } = require('node:test');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const AppState = require('./utils/renderer/AppState');
|
|
|
|
test('UIManager handles folder click for regular folders', async () => {
|
|
// Create a temporary test directory
|
|
const testDir = path.join(__dirname, 'test_folder_click');
|
|
if (!fs.existsSync(testDir)) {
|
|
fs.mkdirSync(testDir);
|
|
}
|
|
|
|
try {
|
|
// Create mock UIManager with just the methods we need to test
|
|
const mockUIManager = {
|
|
currentDirectory: null,
|
|
selectedDirEl: { textContent: '' },
|
|
|
|
appState: {
|
|
navigationStack: [],
|
|
currentDepth: 0,
|
|
|
|
addToNavigationStack: function(dir) {
|
|
this.navigationStack.push(dir);
|
|
this.currentDepth = this.navigationStack.length - 1;
|
|
},
|
|
|
|
getNavigationStack: function() {
|
|
return this.navigationStack;
|
|
},
|
|
|
|
canGoBack: function() {
|
|
return this.currentDepth > 0;
|
|
}
|
|
},
|
|
|
|
scanDirectory: async (dir) => {
|
|
return { success: true, files: [] };
|
|
},
|
|
|
|
_logAuditEvent: async () => {},
|
|
|
|
openDirectory: async (directory) => {
|
|
this.appState.addToNavigationStack(directory);
|
|
this.currentDirectory = directory;
|
|
},
|
|
|
|
handleFolderClick: async function(folderPath, folderName) {
|
|
console.log('Folder clicked:', folderName, 'at path:', folderPath);
|
|
|
|
// Validate folder path exists
|
|
const fs = require('fs');
|
|
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
|
|
console.error('Invalid folder path:', folderPath);
|
|
return; // Don't navigate
|
|
}
|
|
|
|
// Open the folder
|
|
await this.openDirectory(folderPath);
|
|
}
|
|
};
|
|
|
|
// Bind the methods to the object to ensure proper 'this' binding
|
|
const boundOpenDirectory = mockUIManager.openDirectory.bind(mockUIManager);
|
|
const boundHandleFolderClick = mockUIManager.handleFolderClick.bind(mockUIManager);
|
|
|
|
// Test with non-existent folder (should not navigate)
|
|
const nonExistentPath = '/non/existent/path';
|
|
const consoleError = console.error;
|
|
console.error = () => {}; // Suppress error output
|
|
|
|
try {
|
|
await boundHandleFolderClick(nonExistentPath, 'nonexistent');
|
|
// Should not navigate to non-existent folder
|
|
assert.strictEqual(mockUIManager.currentDirectory, null, 'Should not navigate to non-existent folder');
|
|
} finally {
|
|
console.error = consoleError;
|
|
}
|
|
|
|
// Test with valid folder
|
|
await boundHandleFolderClick(testDir, 'test_folder_click');
|
|
assert.strictEqual(mockUIManager.currentDirectory, testDir, 'Should navigate to valid folder');
|
|
assert.strictEqual(mockUIManager.appState.getNavigationStack().length, 1, 'Should add folder to navigation stack');
|
|
} finally {
|
|
// Clean up test directory
|
|
if (fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
test('UIManager validates folder path before navigation', async () => {
|
|
const mockUIManager = {
|
|
currentDirectory: '/test/source',
|
|
selectedDirEl: { textContent: '' },
|
|
|
|
appState: {
|
|
navigationStack: ['/test/source'],
|
|
currentDepth: 0,
|
|
|
|
addToNavigationStack: function(dir) {
|
|
this.navigationStack.push(dir);
|
|
this.currentDepth = this.navigationStack.length - 1;
|
|
},
|
|
|
|
canGoBack: function() {
|
|
return this.currentDepth > 0;
|
|
}
|
|
},
|
|
|
|
openDirectory: async (directory) => {
|
|
this.appState.addToNavigationStack(directory);
|
|
this.currentDirectory = directory;
|
|
},
|
|
|
|
handleFolderClick: async function(folderPath, folderName) {
|
|
console.log('Folder clicked:', folderName, 'at path:', folderPath);
|
|
|
|
// Validate folder path exists
|
|
const fs = require('fs');
|
|
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
|
|
console.error('Invalid folder path:', folderPath);
|
|
return; // Don't navigate
|
|
}
|
|
|
|
// Open the folder
|
|
await this.openDirectory(folderPath);
|
|
}
|
|
};
|
|
|
|
// Bind the methods to the object
|
|
const boundHandleFolderClick = mockUIManager.handleFolderClick.bind(mockUIManager);
|
|
|
|
// Test with non-existent folder
|
|
const nonExistentPath = '/non/existent/path';
|
|
const consoleError = console.error;
|
|
console.error = () => {}; // Suppress error output
|
|
|
|
try {
|
|
await boundHandleFolderClick(nonExistentPath, 'nonexistent');
|
|
// Should not navigate to non-existent folder
|
|
assert.strictEqual(mockUIManager.currentDirectory, '/test/source', 'Should not change directory for non-existent folder');
|
|
} finally {
|
|
console.error = consoleError;
|
|
}
|
|
});
|
|
|
|
test('UIManager handles special folder navigation', async () => {
|
|
const testDir = path.join(__dirname, 'test_special_folders');
|
|
|
|
// Create special folder structure
|
|
if (!fs.existsSync(testDir)) {
|
|
fs.mkdirSync(testDir);
|
|
}
|
|
|
|
const extrasPath = path.join(testDir, 'extras');
|
|
const behindScenesPath = path.join(testDir, 'behind the scenes');
|
|
|
|
if (!fs.existsSync(extrasPath)) {
|
|
fs.mkdirSync(extrasPath);
|
|
}
|
|
|
|
if (!fs.existsSync(behindScenesPath)) {
|
|
fs.mkdirSync(behindScenesPath);
|
|
}
|
|
|
|
try {
|
|
const mockUIManager = {
|
|
currentDirectory: null,
|
|
selectedDirEl: { textContent: '' },
|
|
|
|
appState: {
|
|
navigationStack: [],
|
|
currentDepth: 0,
|
|
|
|
addToNavigationStack: function(dir) {
|
|
this.navigationStack.push(dir);
|
|
this.currentDepth = this.navigationStack.length - 1;
|
|
},
|
|
|
|
getNavigationStack: function() {
|
|
return this.navigationStack;
|
|
},
|
|
|
|
canGoBack: function() {
|
|
return this.currentDepth > 0;
|
|
}
|
|
},
|
|
|
|
scanDirectory: async (dir) => {
|
|
return { success: true, files: [] };
|
|
},
|
|
|
|
_logAuditEvent: async () => {},
|
|
|
|
openDirectory: async (directory) => {
|
|
this.appState.addToNavigationStack(directory);
|
|
this.currentDirectory = directory;
|
|
},
|
|
|
|
handleFolderClick: async function(folderPath, folderName) {
|
|
console.log('Folder clicked:', folderName, 'at path:', folderPath);
|
|
|
|
// Validate folder path exists
|
|
const fs = require('fs');
|
|
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
|
|
console.error('Invalid folder path:', folderPath);
|
|
return; // Don't navigate
|
|
}
|
|
|
|
// Open the folder
|
|
await this.openDirectory(folderPath);
|
|
}
|
|
};
|
|
|
|
// Bind the methods to the object
|
|
const boundHandleFolderClick = mockUIManager.handleFolderClick.bind(mockUIManager);
|
|
|
|
// Test navigating to extras folder
|
|
await boundHandleFolderClick(extrasPath, 'extras');
|
|
assert.strictEqual(mockUIManager.currentDirectory, extrasPath, 'Should navigate to extras folder');
|
|
|
|
// Test navigating to behind the scenes folder
|
|
await boundHandleFolderClick(behindScenesPath, 'behind the scenes');
|
|
assert.strictEqual(mockUIManager.currentDirectory, behindScenesPath, 'Should navigate to behind the scenes folder');
|
|
|
|
// Verify navigation stack
|
|
const stack = mockUIManager.appState.getNavigationStack();
|
|
assert.ok(stack.includes(extrasPath));
|
|
assert.ok(stack.includes(behindScenesPath));
|
|
} finally {
|
|
// Clean up
|
|
if (fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Folder click handler validates path exists', () => {
|
|
const testDir = path.join(__dirname, 'test_path_validation');
|
|
|
|
if (!fs.existsSync(testDir)) {
|
|
fs.mkdirSync(testDir);
|
|
}
|
|
|
|
try {
|
|
const mockUIManager = {
|
|
currentDirectory: testDir,
|
|
selectedDirEl: { textContent: '' },
|
|
|
|
appState: {
|
|
navigationStack: [testDir],
|
|
currentDepth: 0,
|
|
|
|
addToNavigationStack: function(dir) {
|
|
this.navigationStack.push(dir);
|
|
this.currentDepth = this.navigationStack.length - 1;
|
|
}
|
|
},
|
|
|
|
openDirectory: async (directory) => {
|
|
this.appState.addToNavigationStack(directory);
|
|
this.currentDirectory = directory;
|
|
},
|
|
|
|
handleFolderClick: function(folderPath, folderName) {
|
|
const fs = require('fs');
|
|
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
|
|
return; // Don't navigate
|
|
}
|
|
|
|
this.openDirectory(folderPath);
|
|
}
|
|
};
|
|
|
|
// Test with file instead of directory
|
|
const testFile = path.join(testDir, 'testfile.txt');
|
|
fs.writeFileSync(testFile, 'test content');
|
|
|
|
const consoleError = console.error;
|
|
console.error = () => {};
|
|
|
|
try {
|
|
mockUIManager.handleFolderClick(testFile, 'testfile.txt');
|
|
// Should not navigate to file
|
|
assert.strictEqual(mockUIManager.currentDirectory, testDir, 'Should not navigate to file');
|
|
} finally {
|
|
console.error = consoleError;
|
|
}
|
|
|
|
// Test with non-existent directory
|
|
const nonExistentDir = path.join(testDir, 'nonexistent');
|
|
mockUIManager.handleFolderClick(nonExistentDir, 'nonexistent');
|
|
assert.strictEqual(mockUIManager.currentDirectory, testDir, 'Should not navigate to non-existent directory');
|
|
} finally {
|
|
if (fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
test('UIManager handleFolderClick method exists', () => {
|
|
const mockUIManager = {
|
|
handleFolderClick: function(folderPath, folderName) {
|
|
// Mock implementation
|
|
}
|
|
};
|
|
|
|
assert.ok(mockUIManager.handleFolderClick, 'handleFolderClick method should exist');
|
|
assert.strictEqual(typeof mockUIManager.handleFolderClick, 'function', 'handleFolderClick should be a function');
|
|
});
|
|
|
|
console.log('All folder click handler tests passed!'); |