From 9fbf7b01ffee39ffa1d8682bf515a7b44027f66b Mon Sep 17 00:00:00 2001 From: Tomer Shalev Date: Tue, 30 Apr 2024 08:08:21 +0000 Subject: [PATCH] Initial GUI tests The GUI is rather useless when the app is being run in the test environment, as there are no printers connected (there is no USB backend at all). This simple test verifies the most basic existence of selected widget, and their content. We will need to figure out how to test the app with a state that resembles actual printer. We might need to introduce test mode, in which all supported printers are shown in the device selector, so we can test various features for each. --- pyproject.toml | 3 ++- src/labelle/gui/tests/test_gui.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/labelle/gui/tests/test_gui.py diff --git a/pyproject.toml b/pyproject.toml index 1997df64..0d622ee3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,8 @@ requires-python = ">=3.8,<4" [project.optional-dependencies] test = [ "pytest-cov", - "pytest-image-diff" + "pytest-image-diff", + "pytest-qt", ] [project.urls] diff --git a/src/labelle/gui/tests/test_gui.py b/src/labelle/gui/tests/test_gui.py new file mode 100644 index 00000000..0abf0e35 --- /dev/null +++ b/src/labelle/gui/tests/test_gui.py @@ -0,0 +1,25 @@ +from labelle.gui.gui import LabelleWindow +from labelle.gui.q_label_widgets import ( + TextDymoLabelWidget, +) + + +def test_main_window(qtbot): + widget = LabelleWindow() + qtbot.addWidget(widget) + + assert not widget._actions.isEnabled() + assert widget._device_selector.isEnabled() + assert not widget._label_list.isEnabled() + assert not widget._render_widget.isEnabled() + assert not widget._render.isEnabled() + assert not widget._settings_toolbar.isEnabled() + assert ( + widget._device_selector._error_label.text() + == "Failed scanning devices: No backend available" + ) + assert not widget._actions._print_button.isEnabled() + assert widget._label_list.count() == 1 + item = widget._label_list.itemWidget(widget._label_list.item(0)) + assert isinstance(item, TextDymoLabelWidget) + assert item.label.toPlainText() == "text"