mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-28 22:01:24 +00:00
refactor(preview_panel): mvc split (#952)
* refactor: basic split * fix: renaming and usage test didn't work for the tests * fix: tests * refactor: restructuring * refactor: further separation and lots of related changes * refactor: remove last reference to a widget from controller * refactor: address todo * fix: failing tests and mypy compaint * refactor: move control logic to controller * refactor: more readable button style * fix: set_selection was called with invalid argument
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from tagstudio.qt.widgets.preview_panel import PreviewPanel
|
||||
from tagstudio.qt.controller.widgets.preview_panel_controller import PreviewPanel
|
||||
|
||||
|
||||
def test_update_selection_empty(qt_driver, library):
|
||||
@@ -7,10 +7,10 @@ def test_update_selection_empty(qt_driver, library):
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
qt_driver.toggle_item_selection(1, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
for container in panel.fields.containers:
|
||||
for container in panel.field_containers_widget.containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ def test_update_selection_single(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show all applicable tags and field containers
|
||||
for container in panel.fields.containers:
|
||||
for container in panel.field_containers_widget.containers:
|
||||
assert not container.isHidden()
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ def test_update_selection_multiple(qt_driver, library):
|
||||
# Select the multiple entries
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
qt_driver.toggle_item_selection(2, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show mixed field editing
|
||||
for container in panel.fields.containers:
|
||||
for container in panel.field_containers_widget.containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ def test_add_tag_to_selection_single(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.fields.add_tags_to_selected(2000)
|
||||
panel.field_containers_widget.add_tags_to_selected(2000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(library.get_entries(with_joins=True))
|
||||
@@ -65,10 +65,10 @@ def test_add_same_tag_to_selection_single(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add an existing tag
|
||||
panel.fields.add_tags_to_selected(1000)
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(library.get_entries(with_joins=True))
|
||||
@@ -95,10 +95,10 @@ def test_add_tag_to_selection_multiple(qt_driver, library):
|
||||
# Select the multiple entries
|
||||
for i, e in enumerate(library.get_entries(with_joins=True), start=0):
|
||||
qt_driver.toggle_item_selection(e.id, append=(True if i == 0 else False), bridge=False) # noqa: SIM210
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.fields.add_tags_to_selected(1000)
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload all entries and recheck the presence of tag 1000
|
||||
refreshed_entries = library.get_entries(with_joins=True)
|
||||
@@ -123,11 +123,11 @@ def test_meta_tag_category(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.fields.containers) == 3
|
||||
for i, container in enumerate(panel.fields.containers):
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
@@ -155,11 +155,11 @@ def test_custom_tag_category(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.fields.containers) == 3
|
||||
for i, container in enumerate(panel.fields.containers):
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
|
||||
@@ -12,9 +12,9 @@ from pytestqt.qtbot import QtBot
|
||||
from tagstudio.core.enums import ShowFilepathOption
|
||||
from tagstudio.core.library.alchemy.library import Library, LibraryStatus
|
||||
from tagstudio.core.library.alchemy.models import Entry
|
||||
from tagstudio.qt.controller.widgets.preview_panel_controller import PreviewPanel
|
||||
from tagstudio.qt.modals.settings_panel import SettingsPanel
|
||||
from tagstudio.qt.ts_qt import QtDriver
|
||||
from tagstudio.qt.widgets.preview_panel import PreviewPanel
|
||||
|
||||
|
||||
# Tests to see if the file path setting is applied correctly
|
||||
@@ -59,7 +59,7 @@ def test_file_path_display(
|
||||
|
||||
# Select 2
|
||||
qt_driver.toggle_item_selection(2, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
qt_driver.settings.show_filepath = filepath_option
|
||||
|
||||
@@ -68,7 +68,7 @@ def test_file_path_display(
|
||||
assert isinstance(entry, Entry)
|
||||
filename = entry.path
|
||||
assert library.library_dir is not None
|
||||
panel.file_attrs.update_stats(filepath=library.library_dir / filename)
|
||||
panel._file_attributes_widget.update_stats(filepath=library.library_dir / filename)
|
||||
|
||||
# Generate the expected file string.
|
||||
# This is copied directly from the file_attributes.py file
|
||||
@@ -86,7 +86,7 @@ def test_file_path_display(
|
||||
file_str += f"<b>{'\u200b'.join(part_)}</b>"
|
||||
|
||||
# Assert the file path is displayed correctly
|
||||
assert panel.file_attrs.file_label.text() == file_str
|
||||
assert panel._file_attributes_widget.file_label.text() == file_str
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from tagstudio.qt.widgets.preview_panel import PreviewPanel
|
||||
from tagstudio.qt.controller.widgets.preview_panel_controller import PreviewPanel
|
||||
|
||||
|
||||
def test_update_selection_empty(qt_driver, library):
|
||||
@@ -7,11 +7,10 @@ def test_update_selection_empty(qt_driver, library):
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
qt_driver.toggle_item_selection(1, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should disable UI that allows for entry modification
|
||||
assert not panel.add_tag_button.isEnabled()
|
||||
assert not panel.add_field_button.isEnabled()
|
||||
assert not panel.add_buttons_enabled
|
||||
|
||||
|
||||
def test_update_selection_single(qt_driver, library, entry_full):
|
||||
@@ -19,11 +18,10 @@ def test_update_selection_single(qt_driver, library, entry_full):
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_tag_button.isEnabled()
|
||||
assert panel.add_field_button.isEnabled()
|
||||
assert panel.add_buttons_enabled
|
||||
|
||||
|
||||
def test_update_selection_multiple(qt_driver, library):
|
||||
@@ -32,8 +30,7 @@ def test_update_selection_multiple(qt_driver, library):
|
||||
# Select the multiple entries
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
qt_driver.toggle_item_selection(2, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_tag_button.isEnabled()
|
||||
assert panel.add_field_button.isEnabled()
|
||||
assert panel.add_buttons_enabled
|
||||
|
||||
Reference in New Issue
Block a user