fix(file-manager): browse symlinked directories and expand home
Symlinked directories were listed as files, so Enter opened them in the editor instead of browsing them. Mappings and the remote control API reach the panel without a shell, so --start-dir now expands a leading ~ itself. Add the missing Python integration tests for the result handler.
This commit is contained in:
4 files changed
+195
-3
No files matched your search
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2026, FWS
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from kittens.file_manager.main import change_directory, handle_result
|
||||
|
||||
from .base import BaseTest
|
||||
|
||||
|
||||
class TestFileManager(BaseTest):
|
||||
def test_file_manager(self):
|
||||
"""The documented defaults are the ones the panel starts with."""
|
||||
from kittens.file_manager.main import definition
|
||||
|
||||
options = {o.name: o for o in definition.iter_all_options()}
|
||||
for name, expected in (
|
||||
('show_hidden', 'no'),
|
||||
('sort_by', 'name'),
|
||||
('sync_cwd', 'yes'),
|
||||
):
|
||||
self.assertIn(name, options, f'{name} must be a documented option')
|
||||
self.ae(options[name].defval_as_string, expected, name)
|
||||
self.assertTrue(options[name].long_text, f'{name} must have help text')
|
||||
|
||||
def test_change_directory_at_the_prompt(self):
|
||||
w = MagicMock()
|
||||
w.at_prompt = True
|
||||
change_directory(w, '/tmp/a b')
|
||||
|
||||
w.write_to_child.assert_called_once_with("cd '/tmp/a b'\r")
|
||||
w.paste_text.assert_not_called()
|
||||
|
||||
def test_change_directory_while_a_program_runs(self):
|
||||
# While a program owns the terminal the command is only pasted, so that
|
||||
# it can be reviewed instead of being fed to the program's stdin.
|
||||
w = MagicMock()
|
||||
w.at_prompt = False
|
||||
change_directory(w, "/tmp/it's")
|
||||
|
||||
w.paste_text.assert_called_once_with("cd '/tmp/it'\"'\"'s'")
|
||||
w.write_to_child.assert_not_called()
|
||||
|
||||
def test_result_changes_the_target_window_directory(self):
|
||||
boss = MagicMock()
|
||||
window = MagicMock()
|
||||
boss.window_id_map.get.return_value = window
|
||||
with patch('kittens.file_manager.main.change_directory') as cd:
|
||||
handle_result([], {'action': 'cd', 'path': '/tmp/project'}, 42, boss)
|
||||
|
||||
cd.assert_called_once_with(window, '/tmp/project')
|
||||
boss.ring_bell_if_allowed.assert_not_called()
|
||||
|
||||
def test_result_with_sync_does_not_type_into_the_shell(self):
|
||||
# With sync_cwd on, the panel wrote the directory in the session file
|
||||
# and the shell hook applies it; typing a second cd would move twice.
|
||||
boss = MagicMock()
|
||||
with patch('kittens.file_manager.main.change_directory') as cd:
|
||||
handle_result([], {'action': 'cd', 'path': '/tmp/project', 'sync': True}, 42, boss)
|
||||
|
||||
cd.assert_not_called()
|
||||
boss.window_id_map.get.assert_not_called()
|
||||
|
||||
def test_result_without_the_target_window_rings_the_bell(self):
|
||||
boss = MagicMock()
|
||||
boss.window_id_map.get.return_value = None
|
||||
handle_result([], {'action': 'cd', 'path': '/tmp/project'}, 42, boss)
|
||||
|
||||
boss.ring_bell_if_allowed.assert_called_once()
|
||||
|
||||
def test_result_ignores_incomplete_payloads(self):
|
||||
boss = MagicMock()
|
||||
with patch('kittens.file_manager.main.change_directory') as cd:
|
||||
handle_result([], {}, 42, boss)
|
||||
handle_result([], {'action': 'open', 'path': '/tmp'}, 42, boss)
|
||||
handle_result([], {'action': 'cd'}, 42, boss)
|
||||
|
||||
cd.assert_not_called()
|
||||
boss.ring_bell_if_allowed.assert_not_called()
|
||||
Reference in new issue
Block a user