0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

refactor: add pydantic config, add change_theme

This commit is contained in:
2024-06-13 13:08:50 +02:00
parent bc709c4184
commit 6b8432f5b2
2 changed files with 92 additions and 30 deletions

View File

@ -18,26 +18,38 @@ def text_box_widget(qtbot, mocked_client):
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!"
"""Test the TextBox widget."""
text = "Hello World!"
text_box_widget.set_text(text)
assert text_box_widget.toPlainText() == text
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"
)
text_box_widget.set_color("white", "blue")
text_box_widget.set_font_size(14)
assert text_box_widget.styleSheet() == "background-color: white; color: blue; font-size: 14px"
text = "<h1>Welcome to PyQt6</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>"
with mock.patch.object(text_box_widget, "setHtml") as mocked_set_html:
text_box_widget.set_text(text)
assert mocked_set_html.call_count == 1
assert mocked_set_html.call_args == mock.call(text)
with mock.patch.object(text_box_widget, "setHtml") as mock_set_plain_text:
text_box_widget.set_text(
"<h1>Welcome to PyQt6</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>"
)
assert mock_set_plain_text.call_args == mock.call(
"<h1>Welcome to PyQt6</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>"
)
# pylint: disable=protected-access
assert (
text_box_widget._text
== "<h1>Welcome to PyQt6</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>"
)
def test_textbox_change_theme(text_box_widget):
"""Test change theme functionaility"""
# Default is dark theme
text_box_widget.change_theme()
assert text_box_widget.config.theme == "light"
assert (
text_box_widget.styleSheet()
== f"background-color: #FFF; color: #000; font-size: {text_box_widget.config.font_size}px"
)
text_box_widget.change_theme()
assert text_box_widget.config.theme == "dark"
assert (
text_box_widget.styleSheet()
== f"background-color: #000; color: #FFF; font-size: {text_box_widget.config.font_size}px"
)