From 3262b3a337759439f3049b9299be12baf8420750 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Jul 2024 22:26:12 +0200 Subject: turns: add more tests --- app/tests/windows/participant_editor.cpp | 112 +++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 app/tests/windows/participant_editor.cpp (limited to 'app/tests/windows/participant_editor.cpp') diff --git a/app/tests/windows/participant_editor.cpp b/app/tests/windows/participant_editor.cpp new file mode 100644 index 0000000..15c9975 --- /dev/null +++ b/app/tests/windows/participant_editor.cpp @@ -0,0 +1,112 @@ +#include "turns/app/windows/participant_editor.hpp" + +#include "turns/domain/participant.hpp" +#include "turns/lang/messages.hpp" + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace turns::app::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") + { + auto widget = ADW_DIALOG(instance->gobj()); + REQUIRE(adw_dialog_get_title(widget)); + } + + SECTION("has its title set according to the active language") + { + auto widget = ADW_DIALOG(instance->gobj()); + REQUIRE(adw_dialog_get_title(widget) == Glib::ustring{_(lang::add_participant)}); + } + + SECTION("has an empty name field") + { + auto widget = GTK_EDITABLE(builder->get_widget("name")->gobj()); + REQUIRE(Glib::ustring{gtk_editable_get_text(widget)}.empty()); + } + + SECTION("has a zero priority field") + { + auto widget = ADW_SPIN_ROW(builder->get_widget("priority")->gobj()); + REQUIRE(adw_spin_row_get_value(widget) == 0); + } + + SECTION("allows binding to the finished signal") + { + REQUIRE((instance->signal_finished().connect([](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 = domain::participant::create("Qibi Babblebranch", 12); + auto builder = Gtk::Builder::create_from_resource("/ch/arknet/Turns/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") + { + auto widget = ADW_DIALOG(instance->gobj()); + REQUIRE(adw_dialog_get_title(widget)); + } + + SECTION("has its title set according to the active language") + { + auto widget = ADW_DIALOG(instance->gobj()); + REQUIRE(adw_dialog_get_title(widget) == Glib::ustring{_(lang::edit_participant)}); + } + + SECTION("has its name field set according to its participant") + { + auto widget = GTK_EDITABLE(builder->get_widget("name")->gobj()); + REQUIRE(gtk_editable_get_text(widget) == participant->get_name()); + } + + SECTION("has its priority field set according to its participant") + { + auto widget = ADW_SPIN_ROW(builder->get_widget("priority")->gobj()); + REQUIRE(adw_spin_row_get_value(widget) == participant->get_priority()); + } + + SECTION("allows binding to the finished signal") + { + REQUIRE((instance->signal_finished().connect([](auto, auto){})).connected()); + } + } + +} // namespace turns::app::windows::tests \ No newline at end of file -- cgit v1.2.3