diff --git a/tests/unit_tests/test_text_box_widget.py b/tests/unit_tests/test_text_box_widget.py new file mode 100644 index 00000000..95fa0877 --- /dev/null +++ b/tests/unit_tests/test_text_box_widget.py @@ -0,0 +1,43 @@ +import re +from unittest import mock + +import pytest + +from bec_widgets.widgets.text_box.text_box import TextBox + +from .client_mocks import mocked_client + + +@pytest.fixture +def text_box_widget(qtbot, mocked_client): + widget = TextBox(client=mocked_client) + qtbot.addWidget(widget) + qtbot.waitExposed(widget) + yield widget + widget.close() + + +def test_textbox_widget(text_box_widget): + + text_box_widget.set_text("Hello World!") + # pylint: disable=protected-access + assert text_box_widget._text == "Hello World!" + + text_box_widget.set_color("#FFDDC1", "#123456") + text_box_widget.set_font_size(20) + assert ( + text_box_widget.styleSheet() == "background-color: #FFDDC1; color: #123456; font-size: 20px" + ) + + with mock.patch.object(text_box_widget, "setHtml") as mock_set_plain_text: + text_box_widget.set_text( + "
This is an example of displaying HTML text.
" + ) + assert mock_set_plain_text.call_args == mock.call( + "This is an example of displaying HTML text.
" + ) + # pylint: disable=protected-access + assert ( + text_box_widget._text + == "This is an example of displaying HTML text.
" + )