MovieMapper/tests/legacy/test-breadcrumb-navigation.js
Jarian Cottingham 1a35eb346e chore: reorganize repo layout, remove dead files
- Move phase/plan docs into docs/
- Move legacy node:test files into tests/legacy/ with README
- Remove .backup file, test audit artifacts, and unused AI prompt/skill files
- Remove broken iOS GitHub workflows (reference missing MovieMapper-iOS/)
2026-08-20 20:11:57 +00:00

287 lines
8.1 KiB
JavaScript

// Test breadcrumb navigation functionality
const { test } = require('node:test');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const UIManager = require('./utils/renderer/UIManager');
test('UIManager creates breadcrumb container', () => {
const mockUIManager = new UIManager();
// Mock the appState
mockUIManager.appState = {
getNavigationStack: () => [],
canGoBack: () => false
};
// Mock DOM elements
mockUIManager.selectedDirEl = { textContent: '' };
mockUIManager.breadcrumbContainer = null;
// Create mock header element
const mockHeader = { parentNode: document.createElement('div') };
document.body.appendChild(mockHeader.parentNode);
mockHeader.parentNode.className = 'sidebar';
// Mock querySelector
mockUIManager.querySelector = (selector) => {
if (selector === '.sidebar-header') return mockHeader;
return null;
};
// This would test the breadcrumb creation
// For now, we verify the method exists
assert.ok(mockUIManager.updateBreadcrumbNavigation, 'updateBreadcrumbNavigation method should exist');
});
test('UIManager breadcrumb displays directory names', () => {
const mockUIManager = {
selectedDirEl: { textContent: '' },
breadcrumbContainer: null,
appState: {
getNavigationStack: () => [
'/Users/test/Movies',
'/Users/test/Movies/Show Name',
'/Users/test/Movies/Show Name/Season 1'
],
canGoBack: () => true
}
};
// Mock DOM methods
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach((dir, index) => {
const parts = dir.split(path.sep);
const displayName = parts[parts.length - 1];
if (displayName === 'Movies' || displayName === 'Show Name' || displayName === 'Season 1') {
// Directory name should be extracted correctly
}
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(mockUIManager.breadcrumbContainer, 'Breadcrumb container should be created');
});
test('UIManager breadcrumb handles empty stack', () => {
const mockUIManager = {
selectedDirEl: { textContent: '' },
appState: {
getNavigationStack: () => [],
canGoBack: () => false
}
};
// Mock DOM methods
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach(() => {
// Should not be called for empty stack
assert.ok(false, 'Should not iterate over empty stack');
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(true, 'Should handle empty stack without errors');
});
test('UIManager breadcrumb handles single directory', () => {
const mockUIManager = {
selectedDirEl: { textContent: '' },
appState: {
getNavigationStack: () => ['/Users/test/Movies'],
canGoBack: () => false
}
};
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach((dir, index) => {
const parts = dir.split(path.sep);
const displayName = parts[parts.length - 1];
if (index === 0) {
// Should be the last (and only) breadcrumb
// No separator should be added
}
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(true, 'Should handle single directory');
});
test('UIManager breadcrumb navigation click handler', () => {
const mockUIManager = {
currentDirectory: null,
selectedDirEl: { textContent: '' },
appState: {
navigationStack: ['/Users/test/Movies', '/Users/test/Movies/Show Name', '/Users/test/Movies/Show Name/Season 1'],
currentDepth: 2,
getNavigationStack: () => this.navigationStack,
canGoBack: () => this.currentDepth > 0,
// Mock setting depth
setDepth: function(depth) {
this.currentDepth = depth;
}
}
};
let clickedDepth = null;
let clickedDir = null;
mockUIManager.scanDirectory = async (dir) => {
return { success: true, files: [] };
};
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach((dir, index) => {
if (index === 1) {
// Simulate clicking on second breadcrumb
clickedDepth = index;
clickedDir = dir;
}
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.strictEqual(clickedDepth, 1, 'Should track clicked depth');
assert.strictEqual(clickedDir, '/Users/test/Movies/Show Name', 'Should track clicked directory');
});
test('UIManager breadcrumb shows back button when appropriate', () => {
const mockUIManager = {
selectedDirEl: { textContent: '' },
appState: {
getNavigationStack: () => ['/Users/test/Movies', '/Users/test/Movies/Show Name'],
canGoBack: () => true
}
};
mockUIManager.updateBreadcrumbNavigation = function() {
const container = document.createElement('div');
// Check if back button should be shown
if (this.appState.canGoBack()) {
const backBtn = document.createElement('button');
backBtn.textContent = '← Back';
container.appendChild(backBtn);
}
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(true, 'Should show back button when canGoBack is true');
});
test('UIManager breadcrumb handles special folder names', () => {
const mockUIManager = {
selectedDirEl: { textContent: '' },
appState: {
getNavigationStack: () => [
'/Users/test/Movies',
'/Users/test/Movies/Show Name',
'/Users/test/Movies/Show Name/extras',
'/Users/test/Movies/Show Name/behind the scenes'
],
canGoBack: () => true
}
};
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach((dir, index) => {
const parts = dir.split(path.sep);
const displayName = parts[parts.length - 1];
// Should handle special folder names
if (displayName === 'extras' || displayName === 'behind the scenes') {
// These should be displayed correctly
}
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(true, 'Should handle special folder names');
});
test('UIManager breadcrumb clears forward history on navigation', () => {
const mockUIManager = {
currentDirectory: null,
selectedDirEl: { textContent: '' },
appState: {
navigationStack: ['/Users/test/Movies', '/Users/test/Movies/Show Name', '/Users/test/Movies/Show Name/Season 1'],
currentDepth: 2,
getNavigationStack: () => this.navigationStack,
canGoBack: () => this.currentDepth > 0,
setDepth: function(depth) {
this.currentDepth = depth;
}
}
};
mockUIManager.scanDirectory = async (dir) => {
return { success: true, files: [] };
};
mockUIManager.updateBreadcrumbNavigation = function() {
const breadcrumbs = this.appState.getNavigationStack();
const container = document.createElement('div');
breadcrumbs.forEach((dir, index) => {
if (index === 1) {
// Simulate navigating to middle breadcrumb
this.appState.currentDepth = index;
}
});
this.breadcrumbContainer = container;
};
mockUIManager.updateBreadcrumbNavigation();
assert.ok(true, 'Should handle navigation to middle breadcrumb');
});
console.log('All breadcrumb navigation tests passed!');