diff --git a/borgmatic/actions/browse/archives_list.py b/borgmatic/actions/browse/archives_list.py index 6335a8cd..84098c84 100644 --- a/borgmatic/actions/browse/archives_list.py +++ b/borgmatic/actions/browse/archives_list.py @@ -40,8 +40,8 @@ class Archives_list(textual.widgets.OptionList): When this widget gets mounted in the DOM, subscribe to archive loaded events so that we can find out about archives as they load. Also start loading archives from the repository. - Loading is started *after* subscribing to archive loaded signals so that there's not a gap - where we might miss out on signal publishes. + Loading is started *after* subscribing to the archive loaded signal so that there's not a + gap where we might miss out on signal publishes. ''' self.archive_loaded.subscribe(self, self.on_archive_loaded) diff --git a/borgmatic/actions/browse/file_preview.py b/borgmatic/actions/browse/file_preview.py index 7e117eae..edae0b46 100644 --- a/borgmatic/actions/browse/file_preview.py +++ b/borgmatic/actions/browse/file_preview.py @@ -59,8 +59,8 @@ class File_preview(textual.widgets.RichLog): When this widget gets mounted in the DOM, subscribe to archive loaded events so that we can find out about archives as they load. Also start loading file contents from the archive. - Loading is started *after* subscribing to file preview loaded signals so that there's not a - gap where we might miss out on signal publishes. + Loading is started *after* subscribing to the file preview loaded signal so that there's not + a gap where we might miss out on signal publishes. ''' self.file_preview_loaded.subscribe(self, self.on_file_preview_loaded) @@ -75,6 +75,9 @@ class File_preview(textual.widgets.RichLog): ) def on_file_preview_loaded(self, file_contents): + ''' + When a file loads, write its contents (syntax highlighted) to this file preview widget. + ''' self.loading_timer.stop() self.clear() diff --git a/docs/how-to/develop-on-borgmatic.md b/docs/how-to/develop-on-borgmatic.md index 5e6264a2..9edba4af 100644 --- a/docs/how-to/develop-on-borgmatic.md +++ b/docs/how-to/develop-on-borgmatic.md @@ -42,6 +42,13 @@ change that last line to: uv tool install --editable .[dev,Apprise] ``` +Or to work on the [browse +action](https://torsion.org/borgmatic/reference/command-line/actions/browse/): + +```bash +uv tool install --editable .[dev,browse] +``` + To get oriented with the borgmatic source code, have a look at the [source code reference](https://torsion.org/borgmatic/reference/source-code/). diff --git a/tests/integration/actions/browse/test_archives_list.py b/tests/integration/actions/browse/test_archives_list.py index 4f00c0e6..ad28146f 100644 --- a/tests/integration/actions/browse/test_archives_list.py +++ b/tests/integration/actions/browse/test_archives_list.py @@ -1,9 +1,48 @@ from borgmatic.actions.browse import archives_list as module from flexmock import flexmock +import textual.app import textual.widgets.option_list +async def test_archives_list_on_mount_does_not_raise(): + flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator') + flexmock(module.borgmatic.actions.browse.workers).should_receive('add_repository_archives') + archives_list = module.Archives_list(config=flexmock(), repository=flexmock()) + flexmock(archives_list.archive_loaded).should_receive('subscribe') + + async with textual.app.App().run_test() as pilot: + archives_list.on_mount() + + +def test_archives_list_on_archive_loaded_with_loading_done_removes_loading_indicator(): + loading_timer = flexmock() + flexmock(module.borgmatic.actions.browse.loading).should_receive( + 'add_inline_loading_indicator' + ).and_return(loading_timer) + archives_list = module.Archives_list(config=flexmock(), repository=flexmock()) + flexmock(loading_timer).should_receive('stop') + flexmock(archives_list).should_receive('remove_option').with_args('loading-indicator').once() + flexmock(archives_list).should_receive('add_options').never() + + archives_list.on_archive_loaded(module.borgmatic.actions.browse.workers.LOADING_DONE) + + +def test_archives_list_on_archive_loaded_adds_archive_name(): + loading_timer = flexmock() + flexmock(module.borgmatic.actions.browse.loading).should_receive( + 'add_inline_loading_indicator' + ).and_return(loading_timer) + archives_list = module.Archives_list(config=flexmock(), repository=flexmock()) + flexmock(loading_timer).should_receive('stop').never() + loading_indicator = flexmock() + flexmock(archives_list).should_receive('get_option').and_return(loading_indicator) + flexmock(archives_list).should_receive('remove_option').with_args('loading-indicator').once() + flexmock(archives_list).should_receive('add_options').once() + + archives_list.on_archive_loaded('archive') + + def test_archives_list_on_option_list_option_highlighted_with_highlighted_none_marks_it_unchanged(): flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator') diff --git a/tests/integration/actions/browse/test_file_preview.py b/tests/integration/actions/browse/test_file_preview.py index 4c9ef44e..f35ff1b2 100644 --- a/tests/integration/actions/browse/test_file_preview.py +++ b/tests/integration/actions/browse/test_file_preview.py @@ -10,3 +10,36 @@ def test_file_preview_does_not_raise(): module.File_preview( config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo/bar.txt' ) + + +async def test_file_preview_on_mount_does_not_raise(): + flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator') + flexmock(module.borgmatic.actions.browse.workers).should_receive('load_file_preview') + file_preview = module.File_preview( + config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt' + ) + flexmock(file_preview.file_preview_loaded).should_receive('subscribe') + + async with textual.app.App().run_test() as pilot: + file_preview.on_mount() + + +def test_file_preview_on_file_preview_loaded_with_none_file_contents_displays_error(): + flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator').and_return(flexmock(stop=lambda: None)) + file_preview = module.File_preview( + config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt' + ) + flexmock(file_preview).should_receive('write').with_args('Cannot display a preview for this file').once() + + file_preview.on_file_preview_loaded(None) + + +def test_file_preview_on_file_preview_loaded_with_file_contents_displays_contents(): + flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator').and_return(flexmock(stop=lambda: None)) + file_preview = module.File_preview( + config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt' + ) + flexmock(file_preview).should_receive('write').with_args('Cannot display a preview for this file').never() + flexmock(file_preview).should_receive('write').once() + + file_preview.on_file_preview_loaded('hi')