summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-06-05 20:05:31 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-06-05 20:06:40 +0200
commit098be1647edc83493bcbf79d1ee5bbfee6711cf1 (patch)
tree0dca0f2c0b9c9ade972b983eac548d7d20cd1c85
parentfe40c3fc1f371d2da7918365c6dd6ec8a6c40dd4 (diff)
downloadturns-098be1647edc83493bcbf79d1ee5bbfee6711cf1.tar.xz
turns-098be1647edc83493bcbf79d1ee5bbfee6711cf1.zip
gui: reintroduce ParticipantRow tests
-rw-r--r--gui/CMakeLists.txt1
-rw-r--r--gui/include/template_widget.hpp1
-rw-r--r--gui/tests/gtk-test.cpp11
-rw-r--r--gui/tests/participant_row.cpp164
4 files changed, 160 insertions, 17 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index a86ca52..b5ecf19 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -157,6 +157,7 @@ install(TARGETS "gui")
add_executable("gui-tests"
"tests/gtk-test.cpp"
"tests/messages.cpp"
+ "tests/participant_row.cpp"
"tests/resources.cpp"
)
diff --git a/gui/include/template_widget.hpp b/gui/include/template_widget.hpp
index 34bc5ff..2575ad8 100644
--- a/gui/include/template_widget.hpp
+++ b/gui/include/template_widget.hpp
@@ -32,7 +32,6 @@ namespace Turns::gui
{
}
- protected:
template<typename WidgetType = Gtk::Widget>
auto get_widget(char const * name) -> WidgetType *
{
diff --git a/gui/tests/gtk-test.cpp b/gui/tests/gtk-test.cpp
index 4eea74a..8f897d9 100644
--- a/gui/tests/gtk-test.cpp
+++ b/gui/tests/gtk-test.cpp
@@ -5,16 +5,16 @@
#include "turnsmm/init.hpp"
+#include <catch2/internal/catch_test_run_info.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>
+#include <adwaitamm/application.hpp>
+#include <adwaitamm/wrap_init.hpp>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/init.h>
-#include <adwaitamm/application.hpp>
-#include <adwaitamm/wrap_init.hpp>
-
#include <libintl.h>
#include <clocale>
@@ -37,6 +37,11 @@ namespace turns::ui::tests
Turns::init();
}
+ auto testCaseEnded(Catch::TestCaseStats const &) -> void override
+ {
+ setlocale(LC_ALL, "");
+ }
+
private:
Glib::RefPtr<Adwaita::Application> m_app{};
};
diff --git a/gui/tests/participant_row.cpp b/gui/tests/participant_row.cpp
index e32be78..1ab67af 100644
--- a/gui/tests/participant_row.cpp
+++ b/gui/tests/participant_row.cpp
@@ -3,33 +3,171 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
-#include "turns/ui/participant_row.hpp"
+#include "participant_row.hpp"
-#include "turns/core/disposition.hpp"
-#include "turns/core/participant.hpp"
+#include "messages.hpp"
+
+#include <turnsmm/participant.hpp>
#include <catch2/catch_test_macros.hpp>
+#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+#include <gtkmm/button.h>
+#include <gtkmm/label.h>
+#include <gtkmm/togglebutton.h>
+#include <gtkmm/widget.h>
-#include <gtkmm/object.h>
-
-#include <memory>
+#include <algorithm>
+#include <format>
-namespace turns::ui::tests
+namespace Turns::gui::tests
{
- TEST_CASE("A freshly constructed participant row")
+ SCENARIO("Creating a participant row")
{
- SECTION("can be created without a participant")
+ GIVEN("a participant row constructed without a participant")
{
- REQUIRE(std::make_shared<ParticipantRow>(Glib::RefPtr<core::Participant>{}));
+ auto instance = ParticipantRow{nullptr};
+
+ THEN("its title is empty")
+ {
+ auto title = instance.get_widget<Gtk::Label>("title");
+ REQUIRE(title->get_text().empty());
+ }
+
+ THEN("its subtitle is empty")
+ {
+ auto subtitle = instance.get_widget<Gtk::Label>("subtitle");
+ REQUIRE(subtitle->get_text().empty());
+ }
+
+ THEN("its delete button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::Button>("delete");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its edit button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::Button>("edit");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its toggle_defeated button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its toggle_defeated button is not active")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE_FALSE(button->get_active());
+ }
+
+ THEN("the CSS classes of the toggle_defeated button do not contain any starting with disposition-")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ auto classes = button->get_css_classes();
+ REQUIRE_FALSE(std::ranges::any_of(classes, [](auto cls) { return cls.raw().starts_with("disposition-"); }));
+ }
}
- SECTION("can be created with a participant")
+ GIVEN("a participant row constructed with a participant")
{
- REQUIRE(std::make_shared<ParticipantRow>(core::Participant::create("Tazmyla Fireforge", 13, core::Disposition::Secret)));
+ auto participant = Participant::create("Test Participant #1", 5.2f, Participant::Disposition::Neutral);
+ auto instance = ParticipantRow{participant};
+
+ THEN("its title is the participant's name")
+ {
+ auto title = instance.get_widget<Gtk::Label>("title");
+ REQUIRE(title->get_text() == participant->get_name());
+ }
+
+ THEN("its subtitle is the participant's formatted priority")
+ {
+ auto subtitle = instance.get_widget<Gtk::Label>("subtitle");
+ auto priority = participant->get_priority();
+ REQUIRE(subtitle->get_text() == std::vformat(_(message::priority_number), std::make_format_args(priority)));
+ }
+
+ THEN("its delete button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::Button>("delete");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its edit button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::Button>("edit");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its toggle_defeated button is sensitive")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE(button->is_sensitive());
+ }
+
+ THEN("its toggle_defeated button is not active")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE_FALSE(button->get_active());
+ }
+
+ THEN("the CSS classes of the toggle_defeated button do not contain any starting with disposition-")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ auto classes = button->get_css_classes();
+ REQUIRE_FALSE(std::ranges::any_of(classes, [](auto cls) { return cls.raw().starts_with("disposition-"); }));
+ }
+
+ WHEN("the name of the participant is changed")
+ {
+ participant->set_name("Changed Name");
+
+ THEN("the row's title reflects the change")
+ {
+ auto title = instance.get_widget<Gtk::Label>("title");
+ REQUIRE(title->get_text() == "Changed Name");
+ }
+ }
+
+ WHEN("the disposition of the participant is changed to friendly")
+ {
+ participant->set_disposition(Participant::Disposition::Friendly);
+
+ THEN("the row's toggle_defeated button has the CSS class disposition-friendly")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE(button->has_css_class("disposition-friendly"));
+ }
+ }
+
+ WHEN("the disposition of the participant is changed to hostile")
+ {
+ participant->set_disposition(Participant::Disposition::Hostile);
+
+ THEN("the row's toggle_defeated button has the CSS class disposition-hostile")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE(button->has_css_class("disposition-hostile"));
+ }
+ }
+
+ WHEN("the disposition of the participant is changed to secret")
+ {
+ participant->set_disposition(Participant::Disposition::Secret);
+
+ THEN("the row's toggle_defeated button has the CSS class disposition-secret")
+ {
+ auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
+ REQUIRE(button->has_css_class("disposition-secret"));
+ }
+ }
}
}
-} // namespace turns::ui::widgets::tests \ No newline at end of file
+} // namespace Turns::gui::tests \ No newline at end of file