summaryrefslogtreecommitdiff
path: root/gui/tests/participant_row.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/tests/participant_row.cpp')
-rw-r--r--gui/tests/participant_row.cpp164
1 files changed, 151 insertions, 13 deletions
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