/* * SPDX-FileCopyrightText: 2025 Felix Morgner * SPDX-License-Identifier: LGPL-2.1-only */ #include "participant_row.hpp" #include "messages.hpp" #include #include #include #include #include #include #include #include #include #include #include namespace Turns::gui::tests { SCENARIO("Creating a participant row") { GIVEN("a participant row constructed without a participant") { auto instance = ParticipantRow{}; THEN("its title is empty") { auto title = instance.get_widget("title"); REQUIRE(title->get_text().empty()); } THEN("its subtitle is empty") { auto subtitle = instance.get_widget("subtitle"); REQUIRE(subtitle->get_text().empty()); } THEN("its delete button is sensitive") { auto button = instance.get_widget("delete"); REQUIRE(button->is_sensitive()); } THEN("its edit button is sensitive") { auto button = instance.get_widget("edit"); REQUIRE(button->is_sensitive()); } THEN("its toggle_defeated button is sensitive") { auto button = instance.get_widget("toggle_defeated"); REQUIRE(button->is_sensitive()); } THEN("its toggle_defeated button is not active") { auto button = instance.get_widget("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("toggle_defeated"); auto classes = button->get_css_classes(); REQUIRE_FALSE(std::ranges::any_of(classes, [](auto cls) { return cls.raw().starts_with("disposition-"); })); } } GIVEN("a participant row constructed with a participant") { 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("title"); REQUIRE(title->get_text() == participant->get_name()); } THEN("its subtitle is the participant's formatted priority") { auto subtitle = instance.get_widget("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("delete"); REQUIRE(button->is_sensitive()); } THEN("its edit button is sensitive") { auto button = instance.get_widget("edit"); REQUIRE(button->is_sensitive()); } THEN("its toggle_defeated button is sensitive") { auto button = instance.get_widget("toggle_defeated"); REQUIRE(button->is_sensitive()); } THEN("its toggle_defeated button is not active") { auto button = instance.get_widget("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("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("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("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("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("toggle_defeated"); REQUIRE(button->has_css_class("disposition-secret")); } } } } } // namespace Turns::gui::tests