summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/CMakeLists.txt1
-rw-r--r--gui/src/participant_editor.cpp2
-rw-r--r--gui/tests/participant_editor.cpp323
3 files changed, 197 insertions, 129 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index 9ae29c2..111a870 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -159,6 +159,7 @@ install(TARGETS "gui")
add_executable("gui-tests"
"tests/gtk-test.cpp"
"tests/messages.cpp"
+ "tests/participant_editor.cpp"
"tests/participant_row.cpp"
"tests/resources.cpp"
)
diff --git a/gui/src/participant_editor.cpp b/gui/src/participant_editor.cpp
index e8b9ff0..193bbe9 100644
--- a/gui/src/participant_editor.cpp
+++ b/gui/src/participant_editor.cpp
@@ -73,7 +73,7 @@ namespace Turns::gui
{
m_finish->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantEditor::handle_finish_clicked));
- for (auto n : std::views::iota(std::uint8_t{}, static_cast<std::uint8_t>(Participant::Disposition::Secret)))
+ for (auto n : std::views::iota(std::uint8_t{}, static_cast<std::uint8_t>(Participant::Disposition::Secret) + 1u))
{
m_disposition_model->append(presentation_name_for(Participant::Disposition{n}));
}
diff --git a/gui/tests/participant_editor.cpp b/gui/tests/participant_editor.cpp
index b5ddb9f..44b2ca4 100644
--- a/gui/tests/participant_editor.cpp
+++ b/gui/tests/participant_editor.cpp
@@ -3,153 +3,220 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
-#include "turns/ui/participant_editor.hpp"
+#include "participant_editor.hpp"
-#include "turns/core/disposition.hpp"
-#include "turns/core/participant.hpp"
-#include "turns/lang/messages.hpp"
+#include "messages.hpp"
+
+#include <turnsmm/participant.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
+#include <glib/gi18n.h>
+
+#include <adwaitamm/comborow.hpp>
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
-#include <glibmm/wrap.h>
-
-#include <gtkmm/builder.h>
-#include <gtkmm/listboxrow.h>
-#include <gtkmm/window.h>
-
-#include <adwaitamm/entryrow.hpp>
-#include <adwaitamm/spinrow.hpp>
-
-#include <gtk/gtk.h>
+#include <gtkmm/stringobject.h>
#include <clocale>
-#include <memory>
+#include <format>
-namespace turns::ui::tests
+namespace Turns::gui::tests
{
- TEST_CASE("A freshly constructed participant editor without a participant", "[windows]")
+ namespace
{
- auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8");
- setlocale(LC_ALL, locale);
-
- auto participant = core::Participant::create("Frederick Thumblewackle", 7.2, core::Disposition::Friendly);
- auto instance = std::make_shared<ParticipantEditor>(nullptr);
- auto window = Gtk::Window{};
-
- SECTION("was successfully constructed")
- {
- REQUIRE(instance);
- }
-
- SECTION("has a non-empty title")
- {
- REQUIRE_FALSE(instance->get_title().empty());
- }
+ auto constexpr static default_name{"Test Participant"};
+ auto constexpr static default_priority{5.15f};
+ auto constexpr static default_disposition{Participant::Disposition::Friendly};
+ } // namespace
- SECTION("has its title set according to the active language")
- {
- REQUIRE(instance->get_title() == _(lang::add_participant));
- }
-
- SECTION("has an empty name")
- {
- REQUIRE(instance->get_name().empty());
- }
-
- SECTION("has a zero priority")
- {
- REQUIRE(instance->get_priority() == 0);
- }
-
- SECTION("has neutral disposition")
- {
- REQUIRE(instance->get_disposition() == core::Disposition::Neutral);
- }
-
- SECTION("has a null participant")
- {
- REQUIRE_FALSE(instance->get_participant());
- }
+ 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");
- WHEN("setting a new participant")
+ GIVEN(std::format("An active locale of {}", locale))
{
- instance->set_participant(participant);
+ setlocale(LC_ALL, locale);
- THEN("getting the participant returns the new one")
+ AND_GIVEN("a participant editor constructed without a participant")
{
- REQUIRE(instance->get_participant() == 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<Adwaita::ComboRow>("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<Gtk::StringObject>(index);
+ auto text = object->get_string();
+
+ switch (static_cast<Participant::Disposition>(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");
+ }
+ }
+ }
}
-
- 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<ParticipantEditor>(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::ui::tests \ No newline at end of file
+ // auto participant = Participant::create(default_name, default_priority, default_disposition);
+ // auto instance = std::make_shared<ParticipantEditor>(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<ParticipantEditor>(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 \ No newline at end of file