Adds signal testing to UI elements

Extends UI element tests to include signal emission verification.

This ensures that UI elements correctly emit signals upon user interaction,
improving the reliability and responsiveness of the UI.

Adds QSignalSpy to track signal emissions for various UI components like
buttons, checkboxes, comboboxes, items, sliders, textboxes and thermos.
This commit is contained in:
2026-02-14 14:32:17 +01:00
parent 2a7959936a
commit 89ca146e97
10 changed files with 64 additions and 4 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
# Third Party
find_package(GTest QUIET)
find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(Qt6 REQUIRED COMPONENTS Core Test)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
@@ -23,6 +23,7 @@ if (GTest_FOUND)
magic_enum::magic_enum
GTest::gtest_main
Qt::Core
Qt::Test
)
target_include_directories(tests
+1 -2
View File
@@ -1,5 +1,4 @@
#include "ui.hpp"
#include "gtest/gtest.h"
#include <QSignalSpy>
#include <iostream>
#define UNUSED(x) (void)(x)
+8
View File
@@ -10,3 +10,11 @@ TEST(UI_button, to_from_json)
EXPECT_EQ(button.fg_color(), button2.fg_color());
EXPECT_EQ(button.bg_color(), button2.bg_color());
}
TEST(UI_button, signal)
{
UI_button button("button_text", Color::Default, Color::Default);
QSignalSpy spy(&button, &UI_button::clicked);
button.click();
EXPECT_EQ(spy.count(), 1);
}
+8
View File
@@ -11,3 +11,11 @@ TEST(UI_checkbox, to_from_json)
EXPECT_EQ(checkbox.bg_color(), checkbox2.bg_color());
EXPECT_EQ(checkbox.state(), checkbox2.state());
}
TEST(UI_checkbox, signal)
{
UI_checkbox checkbox("checkbox_text", Color::Default, Color::Default);
QSignalSpy spy(&checkbox, &UI_checkbox::changed);
checkbox.click();
EXPECT_EQ(spy.count(), 1);
}
+8
View File
@@ -11,3 +11,11 @@ TEST(UI_combobox, to_from_json)
EXPECT_EQ(combobox.bg_color(), combobox2.bg_color());
EXPECT_EQ(combobox.selected(), combobox2.selected());
}
TEST(UI_combobox, signal)
{
UI_combobox combobox(Color::Default, Color::Default, {"option1", "option2"});
QSignalSpy spy(&combobox, &UI_combobox::changed);
combobox.set_selected(1);
EXPECT_EQ(spy.count(), 1);
}
+2
View File
@@ -16,8 +16,10 @@ TEST(UI_dial, to_from_json)
TEST(UI_dial, set_value)
{
UI_dial dial("slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50);
QSignalSpy spy(&dial, &UI_dial::ui_changed);
dial.set_value(75);
EXPECT_EQ(dial.value(), 75);
EXPECT_EQ(spy.count(), 1);
}
TEST(UI_dial, unit)
+13
View File
@@ -63,3 +63,16 @@ TEST(UI_item, to_json)
EXPECT_EQ(j.at("fg_color"), Color(255, 255, 255).to_hex());
EXPECT_EQ(j.at("bg_color"), Color(0, 0, 0).to_hex());
}
TEST(UI_item, signal)
{
UI_item item("item", "item_text", Color(255, 255, 255), Color(0, 0, 0));
QSignalSpy spy(&item, &UI_item::ui_changed);
item.set_text("text");
item.append_text(" ");
item.set_bg_color(Color::Default);
item.set_fg_color(Color::Default);
item.set_enabled(0);
item.set_visible(0);
EXPECT_EQ(spy.count(), 6);
}
+5
View File
@@ -15,5 +15,10 @@ TEST(UI_slider, to_from_json)
TEST(UI_slider, value)
{
UI_slider slider("slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50);
QSignalSpy spy_ui(&slider, &UI_slider::ui_changed);
QSignalSpy spy_value(&slider, &UI_slider::changed);
EXPECT_EQ(slider.value(), 50);
slider.set_value(10);
EXPECT_EQ(spy_ui.count(), 1);
EXPECT_EQ(spy_value.count(), 1);
}
+15 -1
View File
@@ -15,7 +15,21 @@ TEST(UI_textbox, to_from_json)
TEST(UI_textbox, set_text)
{
UI_textbox textbox("hint", Color(0, 0, 0), Color(255, 255, 255));
QSignalSpy spy_ui(&textbox, &UI_textbox::ui_changed);
QSignalSpy spy_value(&textbox, &UI_textbox::changed);
EXPECT_EQ(textbox.text(), "");
textbox.set_text("random text");
EXPECT_EQ(textbox.text(), "random text");
}
EXPECT_GE(spy_ui.count(), 0);
EXPECT_GE(spy_value.count(), 0);
}
TEST(UI_textbox, set_hint)
{
UI_textbox textbox("hint", Color(0, 0, 0), Color(255, 255, 255));
QSignalSpy spy_ui(&textbox, &UI_textbox::ui_changed);
EXPECT_EQ(textbox.hint(), "hint");
textbox.set_hint("random text");
EXPECT_EQ(textbox.hint(), "random text");
EXPECT_EQ(spy_ui.count(), 1);
}
+2
View File
@@ -15,6 +15,8 @@ TEST(UI_thermo, to_from_json)
TEST(UI_thermo, set_value)
{
UI_thermo thermo("thermo_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50);
QSignalSpy spy(&thermo, &UI_thermo::ui_changed);
thermo.set_value(75);
EXPECT_EQ(thermo.value(), 75);
EXPECT_EQ(spy.count(), 1);
}