115 lines
2.8 KiB
Python
115 lines
2.8 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from sn_basis.functions.variable_wrapper import get_variable
|
|
from sn_plan41.ui.tab_a_ui import TabA
|
|
|
|
|
|
class _DummySignal:
|
|
def connect(self, _callback):
|
|
return None
|
|
|
|
|
|
class _DummyToggleButton:
|
|
def __init__(self):
|
|
self.arrow = None
|
|
self.style = ""
|
|
|
|
def setArrowType(self, arrow):
|
|
self.arrow = arrow
|
|
|
|
def setStyleSheet(self, style):
|
|
self.style = style
|
|
|
|
|
|
class _DummyWidget:
|
|
def __init__(self):
|
|
self.visible = None
|
|
|
|
def setVisible(self, visible):
|
|
self.visible = visible
|
|
|
|
|
|
class _DummyFileWidget:
|
|
def __init__(self):
|
|
self._path = ""
|
|
|
|
def setFilePath(self, path):
|
|
self._path = path
|
|
|
|
def filePath(self):
|
|
return self._path
|
|
|
|
|
|
class _DummyCombo:
|
|
def __init__(self, value="Pufferlayer"):
|
|
self._value = value
|
|
|
|
def currentText(self):
|
|
return self._value
|
|
|
|
|
|
class _DummyPruefmanager:
|
|
pass
|
|
|
|
|
|
class _DummyDataGrabber:
|
|
pass
|
|
|
|
|
|
class TestTabAUI(unittest.TestCase):
|
|
|
|
def _make_tab_without_qt(self):
|
|
tab = TabA.__new__(TabA)
|
|
tab.group_button = _DummyToggleButton()
|
|
tab.group_content = _DummyWidget()
|
|
tab.optional_button = _DummyToggleButton()
|
|
tab.optional_content = _DummyWidget()
|
|
tab.file_widget = _DummyFileWidget()
|
|
tab.linkliste_widget = _DummyFileWidget()
|
|
tab._raumfilter_combo = _DummyCombo("ohne")
|
|
tab.verfahrens_db = None
|
|
tab.lokale_linkliste = None
|
|
tab.logic = None
|
|
tab.pruefmanager = None
|
|
tab.data_grabber = None
|
|
return tab
|
|
|
|
def test_tab_a_callbacks_can_be_called_without_crash(self):
|
|
tab = self._make_tab_without_qt()
|
|
|
|
tab._toggle_group(True)
|
|
tab._toggle_group(False)
|
|
tab._toggle_optional(True)
|
|
tab._toggle_optional(False)
|
|
tab._on_verfahrens_db_changed("")
|
|
tab._on_linkliste_changed("")
|
|
|
|
self.assertEqual(tab.group_content.visible, False)
|
|
self.assertEqual(tab.optional_content.visible, False)
|
|
|
|
def test_tab_a_raumfilter_callback_persists_value(self):
|
|
tab = self._make_tab_without_qt()
|
|
|
|
tab._on_raumfilter_changed("ohne")
|
|
self.assertEqual(get_variable("Raumfilter", scope="project"), "ohne")
|
|
|
|
@patch("sn_plan41.ui.tab_a_ui.TabALogic")
|
|
def test_set_services_initializes_logic_and_injects_data_grabber(self, mock_logic_cls):
|
|
tab = self._make_tab_without_qt()
|
|
mock_logic = mock_logic_cls.return_value
|
|
|
|
pm = _DummyPruefmanager()
|
|
dg = _DummyDataGrabber()
|
|
|
|
tab.set_services(pruefmanager=pm, data_grabber=dg)
|
|
|
|
self.assertIs(tab.pruefmanager, pm)
|
|
self.assertIs(tab.data_grabber, dg)
|
|
self.assertIs(tab.logic, mock_logic)
|
|
self.assertIs(tab.logic.data_grabber, dg)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|