MovieMapper/tests/legacy/test-folder-navigation-stack.js
Jarian Cottingham 2ce7ab14c9 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

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!');