/* * SPDX-FileCopyrightText: 2025 Felix Morgner * SPDX-License-Identifier: LGPL-2.1-only */ #include "participant_editor.hpp" #include "messages.hpp" #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 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}; 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); } AND_WHEN("a new name is set on the participant") { participant->set_name("Changed Name"); THEN("the editor's name is equal to the new name") { REQUIRE(instance.get_name() == "Changed Name"); } } } } } } // auto participant = Participant::create(default_name, default_priority, default_disposition); // auto instance = std::make_shared(nullptr); // auto window = Gtk::Window{}; // WHEN("setting a new participant") // { // instance->set_participant(participant); // THEN("changes to the name propagate to the participant") // { // CHECK(participant->get_name() != "REPLACED"); // instance->set_name("REPLACED"); // REQUIRE(participant->get_name() == "REPLACED"); // } // THEN("changes to the priority propagate to the participant") // { // CHECK(participant->get_priority() != 0); // instance->set_priority(0); // REQUIRE(participant->get_priority() == 0); // } // THEN("changes to the disposition propagate to the participant") // { // CHECK(participant->get_disposition() != core::Disposition::Secret); // instance->set_disposition(core::Disposition::Secret); // REQUIRE(participant->get_disposition() == core::Disposition::Secret); // } // } // SECTION("allows binding to the finished signal") // { // REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); // } // } // TEST_CASE("A freshly constructed participant editor with a participant", "[windows]") // { // auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); // setlocale(LC_ALL, locale); // auto participant = core::Participant::create("Qibi Babblebranch", 12, core::Disposition::Neutral); // auto instance = std::make_shared(participant); // auto window = Gtk::Window{}; // SECTION("was successfully constructed") // { // REQUIRE(instance); // } // SECTION("has a non-empty title") // { // REQUIRE_FALSE(instance->get_title().empty()); // } // SECTION("has its title set according to the active language") // { // REQUIRE(instance->get_title() == _(lang::edit_participant)); // } // SECTION("has its name field set according to its participant") // { // REQUIRE(instance->get_name() == participant->property_name().get_value()); // } // SECTION("has its priority field set according to its participant") // { // REQUIRE(instance->get_priority() == participant->property_priority()); // } // SECTION("allows binding to the finished signal") // { // REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); // } // } } // namespace Turns::gui::tests