mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 07:39:10 +00:00
tests: add field container tests
This commit is contained in:
@@ -142,6 +142,7 @@ def qt_driver(qtbot, library):
|
||||
driver.preview_panel = Mock()
|
||||
driver.flow_container = Mock()
|
||||
driver.item_thumbs = []
|
||||
driver.autofill_action = Mock()
|
||||
|
||||
driver.lib = library
|
||||
# TODO - downsize this method and use it
|
||||
|
||||
115
tagstudio/tests/qt/test_field_containers.py
Normal file
115
tagstudio/tests/qt/test_field_containers.py
Normal file
@@ -0,0 +1,115 @@
|
||||
from src.qt.widgets.preview_panel import PreviewPanel
|
||||
|
||||
|
||||
def test_update_selection_empty(qt_driver, library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.select_item(1, append=False, bridge=False)
|
||||
qt_driver.select_item(1, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
for container in panel.fields.containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
def test_update_selection_single(qt_driver, library, entry_full):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.select_item(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# FieldContainer should show all applicable tags and field containers
|
||||
for container in panel.fields.containers:
|
||||
assert not container.isHidden()
|
||||
|
||||
|
||||
def test_update_selection_multiple(qt_driver, library):
|
||||
# TODO: Implement mixed field editing. Currently these containers will be hidden,
|
||||
# same as the empty selection behavior.
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# Select the multiple entries
|
||||
qt_driver.select_item(1, append=False, bridge=False)
|
||||
qt_driver.select_item(2, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# FieldContainer should show mixed field editing
|
||||
for container in panel.fields.containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
def test_add_tag_to_selection_single(qt_driver, library, entry_full):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
assert {t.id for t in entry_full.tags} == {1000}
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.select_item(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# Add new tag
|
||||
panel.fields.add_tags_to_selected(2000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(library.get_entries(with_joins=True))
|
||||
assert {t.id for t in refreshed_entry.tags} == {1000, 2000}
|
||||
|
||||
|
||||
def test_add_same_tag_to_selection_single(qt_driver, library, entry_full):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
assert {t.id for t in entry_full.tags} == {1000}
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.select_item(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# Add an existing tag
|
||||
panel.fields.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(library.get_entries(with_joins=True))
|
||||
assert {t.id for t in refreshed_entry.tags} == {1000}
|
||||
|
||||
|
||||
def test_add_tag_to_selection_multiple(qt_driver, library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
all_entries = library.get_entries(with_joins=True)
|
||||
|
||||
# We want to verify that tag 1000 is on some, but not all entries already.
|
||||
tag_present_on_some: bool = False
|
||||
tag_absent_on_some: bool = False
|
||||
|
||||
for e in all_entries:
|
||||
if 1000 in [t.id for t in e.tags]:
|
||||
tag_present_on_some = True
|
||||
else:
|
||||
tag_absent_on_some = True
|
||||
|
||||
assert tag_present_on_some
|
||||
assert tag_absent_on_some
|
||||
|
||||
# Select the multiple entries
|
||||
for i, e in enumerate(library.get_entries(with_joins=True), start=0):
|
||||
qt_driver.select_item(e.id, append=(True if i == 0 else False), bridge=False) # noqa: SIM210
|
||||
panel.update_widgets()
|
||||
|
||||
# Add new tag
|
||||
panel.fields.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload all entries and recheck the presence of tag 1000
|
||||
refreshed_entries = library.get_entries(with_joins=True)
|
||||
tag_present_on_some: bool = False
|
||||
tag_absent_on_some: bool = False
|
||||
|
||||
for e in refreshed_entries:
|
||||
if 1000 in [t.id for t in e.tags]:
|
||||
tag_present_on_some = True
|
||||
else:
|
||||
tag_absent_on_some = True
|
||||
|
||||
assert tag_present_on_some
|
||||
assert not tag_absent_on_some
|
||||
@@ -1,102 +1,45 @@
|
||||
# def test_hide_preview_not_selected(qt_driver, library):
|
||||
# qt_driver.frame_content = list(library.get_entries())
|
||||
# qt_driver.selected = []
|
||||
|
||||
# panel = PreviewPanel(library, qt_driver).thumb
|
||||
# panel.hide_preview()
|
||||
|
||||
# assert panel.preview_img.isVisible()
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import pytest
|
||||
from src.core.library import Entry
|
||||
from src.core.library.alchemy.enums import FieldTypeEnum
|
||||
from src.core.library.alchemy.fields import TextField, _FieldID
|
||||
from src.qt.widgets.preview_panel import PreviewPanel
|
||||
|
||||
|
||||
# def test_update_widgets_multiple_selected(qt_driver, library):
|
||||
# # entry with no tag fields
|
||||
# entry = Entry(
|
||||
# path=Path("test.txt"),
|
||||
# folder=library.folder,
|
||||
# fields=[TextField(type_key=_FieldID.TITLE.name, position=0)],
|
||||
# )
|
||||
def test_update_selection_empty(qt_driver, library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# assert not entry.tag_box_fields
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.select_item(1, append=False, bridge=False)
|
||||
qt_driver.select_item(1, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# library.add_entries([entry])
|
||||
# assert library.entries_count == 3
|
||||
|
||||
# qt_driver.frame_content = list(library.get_entries())
|
||||
# qt_driver.selected = [0, 1, 2]
|
||||
|
||||
# panel = PreviewPanel(library, qt_driver)
|
||||
# panel.update_widgets()
|
||||
|
||||
# assert {f.type_key for f in panel.common_fields} == {
|
||||
# _FieldID.TITLE.name,
|
||||
# }
|
||||
|
||||
# assert {f.type_key for f in panel.mixed_fields} == {
|
||||
# _FieldID.TAGS.name,
|
||||
# _FieldID.TAGS_META.name,
|
||||
# }
|
||||
# Panel should disable UI that allows for entry modification
|
||||
assert not panel.add_tag_button.isEnabled()
|
||||
assert not panel.add_field_button.isEnabled()
|
||||
|
||||
|
||||
# def test_write_container_text_line(qt_driver, entry_full, library):
|
||||
# # Given
|
||||
# field_container = PreviewPanel(library, qt_driver).fields
|
||||
def test_update_selection_single(qt_driver, library, entry_full):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# field = entry_full.text_fields[0]
|
||||
# assert len(entry_full.text_fields) == 1
|
||||
# assert field.type.type == FieldTypeEnum.TEXT_LINE
|
||||
# assert field.type.name == "Title"
|
||||
# Select the single entry
|
||||
qt_driver.select_item(entry_full.id, append=False, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# # set any value
|
||||
# field.value = "foo"
|
||||
# field_container.write_container(0, field)
|
||||
# field_container.cached_entries = [library.get_entry_full(entry_full.id)]
|
||||
|
||||
# assert len(field_container.containers) == 1
|
||||
# container = field_container.containers[0]
|
||||
# widget = container.get_inner_widget()
|
||||
# # test it's not "mixed data"
|
||||
# assert widget.text_label.text() == "foo"
|
||||
|
||||
# # When update and submit modal
|
||||
# modal = field_container.fields.containers[0].modal
|
||||
# modal.widget.text_edit.setText("bar")
|
||||
# modal.save_button.click()
|
||||
|
||||
# # Then reload entry
|
||||
# entry_full = next(library.get_entries(with_joins=True))
|
||||
# # the value was updated
|
||||
# assert entry_full.text_fields[0].value == "bar"
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_tag_button.isEnabled()
|
||||
assert panel.add_field_button.isEnabled()
|
||||
|
||||
|
||||
# def test_remove_field(qt_driver, library):
|
||||
# # Given
|
||||
# panel = PreviewPanel(library, qt_driver).fields
|
||||
# entries = list(library.get_entries(with_joins=True))
|
||||
# qt_driver.frame_content = entries
|
||||
def test_update_selection_multiple(qt_driver, library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
|
||||
# # When second entry is selected
|
||||
# panel.selected = [1]
|
||||
# Select the multiple entries
|
||||
qt_driver.select_item(1, append=False, bridge=False)
|
||||
qt_driver.select_item(2, append=True, bridge=False)
|
||||
panel.update_widgets()
|
||||
|
||||
# field = entries[1].text_fields[0]
|
||||
# panel.write_container(0, field)
|
||||
# panel.remove_field(field)
|
||||
|
||||
# entries = list(library.get_entries(with_joins=True))
|
||||
# assert not entries[1].text_fields
|
||||
|
||||
|
||||
# def test_update_field(qt_driver, library, entry_full):
|
||||
# panel = PreviewPanel(library, qt_driver).fields
|
||||
|
||||
# # select both entries
|
||||
# qt_driver.frame_content = [e.id for e in library.get_entries()][:2]
|
||||
# qt_driver.selected = [0, 1]
|
||||
# panel.selected = [0, 1]
|
||||
|
||||
# # update field
|
||||
# title_field = entry_full.text_fields[0]
|
||||
# panel.update_field(title_field, "meow")
|
||||
|
||||
# for entry in library.get_entries(with_joins=True):
|
||||
# field = [x for x in entry.text_fields if x.type_key == title_field.type_key][0]
|
||||
# assert field.value == "meow"
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_tag_button.isEnabled()
|
||||
assert panel.add_field_button.isEnabled()
|
||||
|
||||
Reference in New Issue
Block a user