Disabled "Collapse" button in "Flat" view (#1855)

Our `DiffResultDialog` and `ExtractDialog` show a context menu for items of the list/tree view. The collapse action in this menu only makes sense for the tree mode of the view. This commit therefore enables the option only for this view mode.

* src/vorta/views/extract_dialog.py
* src/vorta/views/diff_result.py

* tests/unit/test_diff.py : Add tests for the new behaviour.
* tests/unit/test_extract.py
This commit is contained in:
Adwait 2024-04-01 20:07:58 +05:30 committed by GitHub
parent d721011c90
commit bde55188e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 2 deletions

View File

@ -190,10 +190,13 @@ class DiffResultDialog(DiffResultBase, DiffResultUI):
"""
if selection == 0:
mode = FileTreeModel.DisplayMode.TREE
self.bCollapseAll.setEnabled(True)
elif selection == 1:
mode = FileTreeModel.DisplayMode.SIMPLIFIED_TREE
self.bCollapseAll.setEnabled(True)
elif selection == 2:
mode = FileTreeModel.DisplayMode.FLAT
self.bCollapseAll.setEnabled(False)
else:
raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection))

View File

@ -185,8 +185,10 @@ class ExtractDialog(ExtractDialogBase, ExtractDialogUI):
"""
if selection == 0:
mode = FileTreeModel.DisplayMode.TREE
self.bCollapseAll.setEnabled(True)
elif selection == 1:
mode = FileTreeModel.DisplayMode.SIMPLIFIED_TREE
self.bCollapseAll.setEnabled(True)
else:
raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection))

View File

@ -6,14 +6,17 @@ import vorta.utils
import vorta.views.archive_tab
from PyQt6.QtCore import QDateTime, QItemSelectionModel, Qt
from PyQt6.QtWidgets import QMenu
from vorta.store.models import ArchiveModel
from vorta.views.diff_result import (
ChangeType,
DiffData,
DiffResultDialog,
DiffTree,
FileType,
parse_diff_json,
parse_diff_lines,
)
from vorta.views.partials.treemodel import FileTreeModel
def setup_diff_result_window(qtbot, mocker, tab, borg_json_output, json_mock_file="diff_archives"):
@ -457,3 +460,19 @@ def test_archive_diff_json_parser(line, expected):
assert item.path == PurePath(expected[0]).parts
assert item.data == DiffData(*expected[1:])
@pytest.mark.parametrize(
"selection, expected_mode, expected_bCollapseAllEnabled",
[
(0, FileTreeModel.DisplayMode.TREE, True),
(1, FileTreeModel.DisplayMode.SIMPLIFIED_TREE, True),
(2, FileTreeModel.DisplayMode.FLAT, False),
],
)
def test_change_display_mode(selection: int, expected_mode, expected_bCollapseAllEnabled):
dialog = DiffResultDialog(ArchiveModel(), ArchiveModel(), DiffTree())
dialog.change_display_mode(selection)
assert dialog.model.mode == expected_mode
assert dialog.bCollapseAll.isEnabled() == expected_bCollapseAllEnabled

View File

@ -1,7 +1,15 @@
import pytest
import vorta.borg
from PyQt6.QtCore import QModelIndex, Qt
from vorta.views.extract_dialog import ExtractTree, FileData, FileType, parse_json_lines
from vorta.views.partials.treemodel import FileSystemItem
from vorta.store.models import ArchiveModel
from vorta.views.extract_dialog import (
ExtractDialog,
ExtractTree,
FileData,
FileType,
parse_json_lines,
)
from vorta.views.partials.treemodel import FileSystemItem, FileTreeModel
def prepare_borg(mocker, borg_json_output):
@ -177,3 +185,15 @@ def test_selection():
select(model, iab)
assert a.data.checkstate == Qt.CheckState(1)
@pytest.mark.parametrize(
"selection, expected_mode, expected_bCollapseAllEnabled",
[(0, FileTreeModel.DisplayMode.TREE, True), (1, FileTreeModel.DisplayMode.SIMPLIFIED_TREE, True)],
)
def test_change_display_mode(selection: int, expected_mode, expected_bCollapseAllEnabled):
dialog = ExtractDialog(ArchiveModel(), ExtractTree())
dialog.change_display_mode(selection)
assert dialog.model.mode == expected_mode
assert dialog.bCollapseAll.isEnabled() == expected_bCollapseAllEnabled