More tests!

This commit is contained in:
Dan Helfman
2026-05-31 20:30:59 -07:00
parent 30ca942f76
commit ec8e52944c
5 changed files with 86 additions and 4 deletions
@@ -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')
@@ -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')