blob: 1ab67af91cf08f82e54b2d372d4f3d4827f89a52 (
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
* SPDX-License-Identifier: LGPL-2.1-only
*/
#include "participant_row.hpp"
#include "messages.hpp"
#include <turnsmm/participant.hpp>
#include <catch2/catch_test_macros.hpp>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/widget.h>
#include <algorithm>
#include <format>
namespace Turns::gui::tests
{
SCENARIO("Creating a participant row")
{
GIVEN("a participant row constructed without a participant")
{
auto instance = ParticipantRow{nullptr};
THEN("its title is empty")
{
auto title = instance.get_widget<Gtk::Label>("title");
REQUIRE(title->get_text().empty());
}
THEN("its subtitle is empty")
{
auto subtitle = instance.get_widget<Gtk::Label>("subtitle");
REQUIRE(subtitle->get_text().empty());
}
THEN("its delete button is sensitive")
{
auto button = instance.get_widget<Gtk::Button>("delete");
REQUIRE(button->is_sensitive());
}
THEN("its edit button is sensitive")
{
auto button = instance.get_widget<Gtk::Button>("edit");
REQUIRE(button->is_sensitive());
}
THEN("its toggle_defeated button is sensitive")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE(button->is_sensitive());
}
THEN("its toggle_defeated button is not active")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE_FALSE(button->get_active());
}
THEN("the CSS classes of the toggle_defeated button do not contain any starting with disposition-")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
auto classes = button->get_css_classes();
REQUIRE_FALSE(std::ranges::any_of(classes, [](auto cls) { return cls.raw().starts_with("disposition-"); }));
}
}
GIVEN("a participant row constructed with a participant")
{
auto participant = Participant::create("Test Participant #1", 5.2f, Participant::Disposition::Neutral);
auto instance = ParticipantRow{participant};
THEN("its title is the participant's name")
{
auto title = instance.get_widget<Gtk::Label>("title");
REQUIRE(title->get_text() == participant->get_name());
}
THEN("its subtitle is the participant's formatted priority")
{
auto subtitle = instance.get_widget<Gtk::Label>("subtitle");
auto priority = participant->get_priority();
REQUIRE(subtitle->get_text() == std::vformat(_(message::priority_number), std::make_format_args(priority)));
}
THEN("its delete button is sensitive")
{
auto button = instance.get_widget<Gtk::Button>("delete");
REQUIRE(button->is_sensitive());
}
THEN("its edit button is sensitive")
{
auto button = instance.get_widget<Gtk::Button>("edit");
REQUIRE(button->is_sensitive());
}
THEN("its toggle_defeated button is sensitive")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE(button->is_sensitive());
}
THEN("its toggle_defeated button is not active")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE_FALSE(button->get_active());
}
THEN("the CSS classes of the toggle_defeated button do not contain any starting with disposition-")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
auto classes = button->get_css_classes();
REQUIRE_FALSE(std::ranges::any_of(classes, [](auto cls) { return cls.raw().starts_with("disposition-"); }));
}
WHEN("the name of the participant is changed")
{
participant->set_name("Changed Name");
THEN("the row's title reflects the change")
{
auto title = instance.get_widget<Gtk::Label>("title");
REQUIRE(title->get_text() == "Changed Name");
}
}
WHEN("the disposition of the participant is changed to friendly")
{
participant->set_disposition(Participant::Disposition::Friendly);
THEN("the row's toggle_defeated button has the CSS class disposition-friendly")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE(button->has_css_class("disposition-friendly"));
}
}
WHEN("the disposition of the participant is changed to hostile")
{
participant->set_disposition(Participant::Disposition::Hostile);
THEN("the row's toggle_defeated button has the CSS class disposition-hostile")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE(button->has_css_class("disposition-hostile"));
}
}
WHEN("the disposition of the participant is changed to secret")
{
participant->set_disposition(Participant::Disposition::Secret);
THEN("the row's toggle_defeated button has the CSS class disposition-secret")
{
auto button = instance.get_widget<Gtk::ToggleButton>("toggle_defeated");
REQUIRE(button->has_css_class("disposition-secret"));
}
}
}
}
} // namespace Turns::gui::tests
|