From 873bf396b904ce477a238f22d1891e1b03f24eff Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 29 Apr 2025 15:55:30 +0200 Subject: ui: convert editor into a template_widget --- ui/tests/widgets/participant_editor.cpp | 108 ++++++++++++++++++++++++++++++ ui/tests/windows/participant_editor.cpp | 113 -------------------------------- ui/tests/windows/resources.cpp | 10 --- 3 files changed, 108 insertions(+), 123 deletions(-) create mode 100644 ui/tests/widgets/participant_editor.cpp delete mode 100644 ui/tests/windows/participant_editor.cpp (limited to 'ui/tests') diff --git a/ui/tests/widgets/participant_editor.cpp b/ui/tests/widgets/participant_editor.cpp new file mode 100644 index 0000000..41ba5bd --- /dev/null +++ b/ui/tests/widgets/participant_editor.cpp @@ -0,0 +1,108 @@ +#include "turns/ui/widgets/participant_editor.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" +#include "turns/lang/messages.hpp" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include + +namespace turns::ui::widgets::tests +{ + + TEST_CASE("A freshly constructed participant editor without a participant", "[windows]") + { + auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); + setlocale(LC_ALL, locale); + + auto instance = std::make_shared(nullptr); + 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::add_participant)); + } + + SECTION("has an empty name") + { + REQUIRE(instance->get_name().empty()); + } + + SECTION("has a zero priority") + { + REQUIRE(instance->get_priority() == 0); + } + + 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::ui::widgets::tests \ No newline at end of file diff --git a/ui/tests/windows/participant_editor.cpp b/ui/tests/windows/participant_editor.cpp deleted file mode 100644 index 02e387f..0000000 --- a/ui/tests/windows/participant_editor.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "turns/ui/windows/participant_editor.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" -#include "turns/lang/messages.hpp" - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include - -namespace turns::ui::windows::tests -{ - - TEST_CASE("A freshly constructed participant editor without a participant", "[windows]") - { - auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8"); - setlocale(LC_ALL, locale); - - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui"); - auto instance = Gtk::Builder::get_widget_derived(builder, "participant_editor"); - 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::add_participant)); - } - - SECTION("has an empty name field") - { - auto widget = builder->get_widget("name"); - REQUIRE(widget->get_text().empty()); - } - - SECTION("has a zero priority field") - { - auto widget = builder->get_widget("priority"); - REQUIRE(widget->get_value() == 0); - } - - 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 builder = Gtk::Builder::create_from_resource("/windows/participant_editor.ui"); - auto instance = Gtk::Builder::get_widget_derived(builder, "participant_editor", 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") - { - auto widget = builder->get_widget("name"); - REQUIRE(widget->get_text() == participant->property_name().get_value()); - } - - SECTION("has its priority field set according to its participant") - { - auto widget = builder->get_widget("priority"); - REQUIRE(widget->get_value() == participant->property_priority()); - } - - SECTION("allows binding to the finished signal") - { - REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected()); - } - } - -} // namespace turns::ui::windows::tests \ No newline at end of file diff --git a/ui/tests/windows/resources.cpp b/ui/tests/windows/resources.cpp index b9ac42e..022f3c4 100644 --- a/ui/tests/windows/resources.cpp +++ b/ui/tests/windows/resources.cpp @@ -12,13 +12,3 @@ TEST_CASE("GResource for tracker") REQUIRE(builder); } } - -TEST_CASE("GResource for participant_editor") -{ - auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/windows/participant_editor.ui"); - - SECTION("can create Gtk.Builder for the participant_editor window UI definition") - { - REQUIRE(builder); - } -} \ No newline at end of file -- cgit v1.2.3