summaryrefslogtreecommitdiff
path: root/ui/tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-24 13:23:55 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-24 13:23:55 +0200
commit4d0a7d99ebf55ad2d0e583759699b8b4d77a7907 (patch)
tree302a2661c5ae099129db40c75cbadf6b5e8c9bd4 /ui/tests
parentf3317ddcaa8af0fb7b4be475dc97ef0649d1975b (diff)
downloadturns-4d0a7d99ebf55ad2d0e583759699b8b4d77a7907.tar.xz
turns-4d0a7d99ebf55ad2d0e583759699b8b4d77a7907.zip
app: move ui code to ui library
Diffstat (limited to 'ui/tests')
-rw-r--r--ui/tests/widgets/participant_row.cpp24
-rw-r--r--ui/tests/windows/participant_editor.cpp111
-rw-r--r--ui/tests/windows/resources.cpp13
-rw-r--r--ui/tests/windows/tracker.cpp75
4 files changed, 223 insertions, 0 deletions
diff --git a/ui/tests/widgets/participant_row.cpp b/ui/tests/widgets/participant_row.cpp
new file mode 100644
index 0000000..f2af510
--- /dev/null
+++ b/ui/tests/widgets/participant_row.cpp
@@ -0,0 +1,24 @@
+#include "turns/ui/widgets/participant_row.hpp"
+
+#include "turns/core/disposition.hpp"
+#include "turns/core/participant.hpp"
+
+#include <catch2/catch_test_macros.hpp>
+
+namespace turns::app::widgets::tests
+{
+
+ TEST_CASE("A freshly constructed participant row")
+ {
+ SECTION("can be created without a participant")
+ {
+ REQUIRE(Gtk::make_managed<participant_row>(Glib::RefPtr<core::participant>{}));
+ }
+
+ SECTION("can be created with a participant")
+ {
+ REQUIRE(Gtk::make_managed<participant_row>(core::participant::create("Tazmyla Fireforge", 13, core::disposition::secret)));
+ }
+ }
+
+} // namespace turns::app::widgets::tests \ No newline at end of file
diff --git a/ui/tests/windows/participant_editor.cpp b/ui/tests/windows/participant_editor.cpp
new file mode 100644
index 0000000..99a4ded
--- /dev/null
+++ b/ui/tests/windows/participant_editor.cpp
@@ -0,0 +1,111 @@
+#include "turns/ui/windows/participant_editor.hpp"
+
+#include "turns/core/disposition.hpp"
+#include "turns/core/participant.hpp"
+#include "turns/lang/messages.hpp"
+
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/generators/catch_generators.hpp>
+
+#include <glibmm/i18n.h>
+#include <glibmm/ustring.h>
+
+#include <gtkmm/builder.h>
+#include <gtkmm/listboxrow.h>
+#include <gtkmm/window.h>
+
+#include <adwaita.h>
+
+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("/windows/participant_editor.ui");
+ auto instance = Gtk::Builder::get_widget_derived<participant_editor>(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<Gtk::ListBoxRow>("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<Gtk::ListBoxRow>("priority")->gobj());
+ REQUIRE(adw_spin_row_get_value(widget) == 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<participant_editor>(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<Gtk::ListBoxRow>("name")->gobj());
+ REQUIRE(gtk_editable_get_text(widget) == participant->name().get_value());
+ }
+
+ SECTION("has its priority field set according to its participant")
+ {
+ auto widget = ADW_SPIN_ROW(builder->get_widget<Gtk::ListBoxRow>("priority")->gobj());
+ REQUIRE(adw_spin_row_get_value(widget) == participant->priority());
+ }
+
+ SECTION("allows binding to the finished signal")
+ {
+ REQUIRE((instance->signal_finished().connect([](auto, auto, auto) {})).connected());
+ }
+ }
+
+} // namespace turns::app::windows::tests \ No newline at end of file
diff --git a/ui/tests/windows/resources.cpp b/ui/tests/windows/resources.cpp
new file mode 100644
index 0000000..315181a
--- /dev/null
+++ b/ui/tests/windows/resources.cpp
@@ -0,0 +1,13 @@
+#include <catch2/catch_test_macros.hpp>
+
+#include <gtkmm/builder.h>
+
+TEST_CASE("GResource for tracker")
+{
+ auto builder = Gtk::Builder::create_from_resource("/windows/tracker.ui");
+
+ SECTION("can create Gtk.Builder for the main window UI definition")
+ {
+ REQUIRE(builder);
+ }
+} \ No newline at end of file
diff --git a/ui/tests/windows/tracker.cpp b/ui/tests/windows/tracker.cpp
new file mode 100644
index 0000000..3ec5658
--- /dev/null
+++ b/ui/tests/windows/tracker.cpp
@@ -0,0 +1,75 @@
+#include "turns/ui/windows/tracker.hpp"
+
+#include "turns/lang/messages.hpp"
+
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/generators/catch_generators.hpp>
+
+#include <glibmm/i18n.h>
+#include <glibmm/ustring.h>
+
+#include <gtkmm/builder.h>
+#include <gtkmm/button.h>
+#include <gtkmm/menubutton.h>
+#include <gtkmm/widget.h>
+
+#include <adwaita.h>
+
+namespace turns::app::windows::tests
+{
+
+ TEST_CASE("A freshly constructed tracker window", "[windows]")
+ {
+ auto locale = GENERATE("en_US.UTF-8", "de_CH.UTF-8");
+ setlocale(LC_ALL, locale);
+
+ auto builder = Gtk::Builder::create_from_resource("/windows/tracker.ui");
+ auto instance = Gtk::Builder::get_widget_derived<tracker>(builder, "tracker");
+
+ SECTION("was successfully constructed")
+ {
+ REQUIRE(instance);
+ }
+
+ SECTION("has a non-empty subtitle")
+ {
+ auto widget = builder->get_widget<Gtk::Widget>("title");
+ auto adw = ADW_WINDOW_TITLE(widget->gobj());
+ REQUIRE(adw_window_title_get_subtitle(adw));
+ }
+
+ SECTION("has its subtitle set according to the active language")
+ {
+ auto widget = builder->get_widget<Gtk::Widget>("title");
+ auto adw = ADW_WINDOW_TITLE(widget->gobj());
+ REQUIRE(adw_window_title_get_subtitle(adw) == Glib::ustring{_(lang::no_active_turn_order)});
+ }
+
+ SECTION("has a non-empty title")
+ {
+ auto widget = builder->get_widget<Gtk::Widget>("title");
+ auto adw = ADW_WINDOW_TITLE(widget->gobj());
+ REQUIRE(adw_window_title_get_title(adw));
+ }
+
+ SECTION("has its title set according to the active language")
+ {
+ auto widget = builder->get_widget<Gtk::Widget>("title");
+ auto adw = ADW_WINDOW_TITLE(widget->gobj());
+ REQUIRE(adw_window_title_get_title(adw) == Glib::ustring{_(lang::turns)});
+ }
+
+ SECTION("has its add_participant button's tooltip set according to the active language")
+ {
+ auto widget = builder->get_widget<Gtk::Button>("add_participant");
+ REQUIRE(widget->get_tooltip_text() == Glib::ustring{_(lang::add_participant)});
+ }
+
+ SECTION("as its open_main_menu button's tooltip set according to the active language")
+ {
+ auto widget = builder->get_widget<Gtk::MenuButton>("open_main_menu");
+ REQUIRE(widget->get_tooltip_text() == Glib::ustring{_(lang::main_menu)});
+ }
+ }
+
+} // namespace turns::app::windows::tests \ No newline at end of file