/* * SPDX-FileCopyrightText: 2025 Felix Morgner * SPDX-License-Identifier: LGPL-2.1-only */ #include "participant_editor.hpp" #include "gtk-test.hpp" #include "messages.hpp" #include #include #include #include #include #include #include #include #include #include #include namespace Turns::gui::tests { namespace { auto constexpr static default_name{"Test Participant"}; auto constexpr static default_priority{5.15f}; auto constexpr static default_disposition{Participant::Disposition::Friendly}; } // namespace SCENARIO("Creating a participant editor", "[gui][windows][lifetime]") { auto window = Adwaita::ApplicationWindow{gtk_test::application}; auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8", "de_DE.UTF-8", "de_AT.UTF-8"); GIVEN(std::format("An active locale of {}", locale)) { setlocale(LC_ALL, locale); AND_GIVEN("a participant editor constructed without a participant") { auto instance = ParticipantEditor{nullptr}; instance.present(&window); THEN("its title is message::add_participant") { REQUIRE(instance.get_title() == _(message::add_participant)); } THEN("its name is empty") { REQUIRE(instance.get_name().empty()); } THEN("its priority is 0") { REQUIRE(instance.get_priority() == 0.0f); } THEN("its disposition is neutral") { REQUIRE(instance.get_disposition() == Participant::Disposition::Neutral); } THEN("its participant is NULL") { REQUIRE(instance.get_participant() == nullptr); } THEN("its disposition combo row has 4 elements") { auto row = instance.get_widget("disposition"); REQUIRE(row->get_model()->get_n_items() == 4); auto model = row->get_model(); auto index = GENERATE(0, 1, 2, 3); AND_THEN(std::format("the row's entry at index {} is translated accordingly", index)) { auto object = model->get_typed_object(index); auto text = object->get_string(); switch (static_cast(index)) { case Participant::Disposition::Neutral: REQUIRE(text == _("Neutral")); break; case Participant::Disposition::Friendly: REQUIRE(text == _("Friendly")); break; case Participant::Disposition::Hostile: REQUIRE(text == _("Hostile")); break; case Participant::Disposition::Secret: REQUIRE(text == _("Secret")); break; } } } WHEN("a participant is set") { auto participant = Participant::create(default_name, default_priority, default_disposition); instance.set_participant(participant); THEN("its title is message::edit_participant") { REQUIRE(instance.get_title() == _(message::edit_participant)); } THEN("its name is the same as the participant's") { REQUIRE(instance.get_name() == participant->get_name()); } THEN("its priority is the same as the participant's") { REQUIRE(instance.get_priority() == participant->get_priority()); } THEN("its disposition is the same as the participant's") { REQUIRE(instance.get_disposition() == participant->get_disposition()); } THEN("its participant is the participant") { REQUIRE(instance.get_participant() == participant); } THEN("changing the participant's name also changes the name in the editor") { auto new_value = "Changed Name"; participant->set_name(new_value); REQUIRE(instance.get_name() == new_value); } THEN("changing the participant's disposition also changes the disposition in the editor") { auto new_value = Participant::Disposition::Hostile; participant->set_disposition(new_value); REQUIRE(instance.get_disposition() == new_value); } THEN("changing the participant's priority also changes the priority in the editor") { auto new_value = -10.0f; participant->set_priority(new_value); REQUIRE(instance.get_priority() == new_value); } THEN("changing the name in the editor also changes the participant's name") { auto new_value = "Editor Changed Name"; instance.set_name(new_value); REQUIRE(participant->get_name() == new_value); } THEN("changing the disposition in the editor also changes the participant's disposition") { auto new_value = Participant::Disposition::Secret; instance.set_disposition(new_value); REQUIRE(participant->get_disposition() == new_value); } THEN("changing the priority in the editor also changes the participant's priority") { auto new_value = 100.0f; instance.set_priority(new_value); REQUIRE(participant->get_priority() == new_value); } } instance.close(); } } } // auto participant = Participant::create(default_name, default_priority, default_disposition); // auto instance = std::make_shared(nullptr); // auto window = Gtk::Window{}; // SECTION("allows binding to the finished signal") // { // REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); // } // }