11# Copyright (C) 2025
22# Licensed under the GPL-3.0 License.
33# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
4-
5-
4+ from PySide6 .QtCore import SIGNAL
65from pytestqt .qtbot import QtBot
76
87from tagstudio .core .library .alchemy .library import Library
98from tagstudio .qt .mixed .tag_search import TagSearchPanel
9+ from tagstudio .qt .mixed .tag_widget import TagWidget
10+ from tagstudio .qt .ts_qt import QtDriver
1011
1112
1213def test_update_tags (qtbot : QtBot , library : Library ):
@@ -17,3 +18,35 @@ def test_update_tags(qtbot: QtBot, library: Library):
1718
1819 # When
1920 panel .update_tags ()
21+
22+
23+ def test_tag_widget_actions_replaced_correctly (qtbot : QtBot , qt_driver : QtDriver , library : Library ):
24+ panel = TagSearchPanel (library )
25+ qtbot .addWidget (panel )
26+ panel .driver = qt_driver
27+
28+ # Set the widget
29+ tags = library .tags
30+ panel .set_tag_widget (tags [0 ], 0 )
31+ tag_widget : TagWidget = panel .scroll_layout .itemAt (0 ).widget ()
32+
33+ should_replace_actions = {
34+ tag_widget : ["on_edit()" , "on_remove()" ],
35+ tag_widget .bg_button : ["clicked()" ],
36+ tag_widget .search_for_tag_action : ["triggered()" ],
37+ }
38+
39+ # Ensure each action has been set
40+ ensure_one_receiver_per_action (should_replace_actions )
41+
42+ # Set the widget again
43+ panel .set_tag_widget (tags [0 ], 0 )
44+
45+ # Ensure each action has been replaced (amount of receivers is still 1)
46+ ensure_one_receiver_per_action (should_replace_actions )
47+
48+
49+ def ensure_one_receiver_per_action (should_replace_actions ):
50+ for action , signal_strings in should_replace_actions .items ():
51+ for signal_str in signal_strings :
52+ assert action .receivers (SIGNAL (signal_str )) == 1
0 commit comments