Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tagstudio/qt/mixed/tag_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def set_tag_widget(self, tag: Tag | None, index: int):
tag_widget.on_edit.disconnect()
tag_widget.on_remove.disconnect()
tag_widget.bg_button.clicked.disconnect()
tag_widget.search_for_tag_action.triggered.disconnect()

tag_id = tag.id
tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))
Expand Down
37 changes: 35 additions & 2 deletions tests/qt/test_tag_search_panel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright (C) 2025
# Licensed under the GPL-3.0 License.
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio


from PySide6.QtCore import SIGNAL
from pytestqt.qtbot import QtBot

from tagstudio.core.library.alchemy.library import Library
from tagstudio.qt.mixed.tag_search import TagSearchPanel
from tagstudio.qt.mixed.tag_widget import TagWidget
from tagstudio.qt.ts_qt import QtDriver


def test_update_tags(qtbot: QtBot, library: Library):
Expand All @@ -17,3 +18,35 @@ def test_update_tags(qtbot: QtBot, library: Library):

# When
panel.update_tags()


def test_tag_widget_actions_replaced_correctly(qtbot: QtBot, qt_driver: QtDriver, library: Library):
panel = TagSearchPanel(library)
qtbot.addWidget(panel)
panel.driver = qt_driver

# Set the widget
tags = library.tags
panel.set_tag_widget(tags[0], 0)
tag_widget: TagWidget = panel.scroll_layout.itemAt(0).widget()

should_replace_actions = {
tag_widget: ["on_edit()", "on_remove()"],
tag_widget.bg_button: ["clicked()"],
tag_widget.search_for_tag_action: ["triggered()"],
}

# Ensure each action has been set
ensure_one_receiver_per_action(should_replace_actions)

# Set the widget again
panel.set_tag_widget(tags[0], 0)

# Ensure each action has been replaced (amount of receivers is still 1)
ensure_one_receiver_per_action(should_replace_actions)


def ensure_one_receiver_per_action(should_replace_actions):
for action, signal_strings in should_replace_actions.items():
for signal_str in signal_strings:
assert action.receivers(SIGNAL(signal_str)) == 1