aboutsummaryrefslogtreecommitdiff
path: root/ui/tests/windows/participant_editor.cpp
blob: 2b3f5dadb46850661de015cc4415ec1a0bdf46cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#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>
#include <gtk/gtk.h>

#include <clocale>

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("/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::ui::windows::tests