24
24
using namespace unity::indicator::datetime;
26
typedef StateFixture ActionsFixture;
26
class ActionsFixture: public StateFixture
28
typedef StateFixture super;
30
std::vector<Appointment> build_some_appointments()
32
const auto now = m_state->clock->localtime();
33
auto gdt_tomorrow = g_date_time_add_days(now.get(), 1);
34
const auto tomorrow = DateTime(gdt_tomorrow);
35
g_date_time_unref(gdt_tomorrow);
37
Appointment a1; // an alarm clock appointment
40
a1.summary = "http://www.example.com/";
43
a1.begin = a1.end = tomorrow;
45
Appointment a2; // a non-alarm appointment
47
a2.summary = "Other Text";
48
a2.summary = "http://www.monkey.com/";
50
a2.has_alarms = false;
51
a2.begin = a2.end = tomorrow;
53
return std::vector<Appointment>({a1, a2});
63
virtual void TearDown()
68
void test_action_with_no_args(const char * action_name,
69
MockActions::Action expected_action)
72
EXPECT_TRUE(m_mock_actions->history().empty());
73
auto action_group = m_actions->action_group();
74
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
77
g_action_group_activate_action(action_group, action_name, nullptr);
80
EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
81
m_mock_actions->history());
84
void test_action_with_time_arg(const char * action_name,
85
MockActions::Action expected_action)
88
EXPECT_TRUE(m_mock_actions->history().empty());
89
auto action_group = m_actions->action_group();
90
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
92
// activate the action
93
const auto now = DateTime::NowLocal();
94
auto v = g_variant_new_int64(now.to_unix());
95
g_action_group_activate_action(action_group, action_name, v);
98
EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
99
m_mock_actions->history());
100
EXPECT_EQ(now.format("%F %T"),
101
m_mock_actions->date_time().format("%F %T"));
104
void test_action_with_appt_arg(const char * action_name,
105
MockActions::Action expected_action)
108
/// Test 1: activate an appointment that we know about
112
EXPECT_TRUE(m_mock_actions->history().empty());
113
auto action_group = m_actions->action_group();
114
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
116
// init some appointments to the state
117
const auto appointments = build_some_appointments();
118
m_mock_state->mock_range_planner->appointments().set(appointments);
120
// activate the action
121
auto v = g_variant_new_string(appointments[0].uid.c_str());
122
g_action_group_activate_action(action_group, action_name, v);
125
EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
126
m_mock_actions->history());
127
EXPECT_EQ(appointments[0],
128
m_mock_actions->appointment());
131
/// Test 2: activate an appointment we *don't* know about
135
m_mock_actions->clear();
136
EXPECT_TRUE(m_mock_actions->history().empty());
138
// activate the action
139
v = g_variant_new_string("this-uid-is-not-one-that-we-have");
140
g_action_group_activate_action(action_group, action_name, v);
143
EXPECT_TRUE(m_mock_actions->history().empty());
28
151
TEST_F(ActionsFixture, ActionsExist)
32
155
const char* names[] = { "desktop-header",
36
"activate-appointment",
37
"activate-phone-clock-app",
38
"phone.open-settings",
39
"desktop.open-settings" };
158
"desktop.open-appointment",
159
"desktop.open-alarm-app",
160
"desktop.open-calendar-app",
161
"desktop.open-settings-app",
162
"phone.open-appointment",
163
"phone.open-alarm-app",
164
"phone.open-calendar-app",
165
"phone.open-settings-app" };
40
167
for(const auto& name: names)
42
169
EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), name));
46
TEST_F(ActionsFixture, DesktopOpenSettings)
48
const auto action_name = "desktop.open-settings";
49
const auto expected_action = MockActions::OpenDesktopSettings;
51
auto action_group = m_actions->action_group();
52
auto history = m_mock_actions->history();
53
EXPECT_EQ(0, history.size());
54
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
56
g_action_group_activate_action(action_group, action_name, nullptr);
57
history = m_mock_actions->history();
58
EXPECT_EQ(1, history.size());
59
EXPECT_EQ(expected_action, history[0]);
62
TEST_F(ActionsFixture, PhoneOpenSettings)
64
const auto action_name = "phone.open-settings";
65
const auto expected_action = MockActions::OpenPhoneSettings;
67
auto action_group = m_actions->action_group();
68
EXPECT_TRUE(m_mock_actions->history().empty());
69
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
71
g_action_group_activate_action(action_group, action_name, nullptr);
72
auto history = m_mock_actions->history();
73
EXPECT_EQ(1, history.size());
74
EXPECT_EQ(expected_action, history[0]);
77
TEST_F(ActionsFixture, ActivatePhoneClockApp)
79
const auto action_name = "activate-phone-clock-app";
80
const auto expected_action = MockActions::OpenPhoneClockApp;
82
auto action_group = m_actions->action_group();
83
EXPECT_TRUE(m_mock_actions->history().empty());
84
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
86
g_action_group_activate_action(action_group, action_name, nullptr);
87
auto history = m_mock_actions->history();
88
EXPECT_EQ(1, history.size());
89
EXPECT_EQ(expected_action, history[0]);
92
TEST_F(ActionsFixture, ActivatePlanner)
94
const auto action_name = "activate-planner";
95
auto action_group = m_actions->action_group();
96
EXPECT_TRUE(m_mock_actions->history().empty());
97
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
99
const auto expected_action = MockActions::OpenPlanner;
100
auto v = g_variant_new_int64(0);
101
g_action_group_activate_action(action_group, action_name, v);
102
auto history = m_mock_actions->history();
103
EXPECT_EQ(1, history.size());
104
EXPECT_EQ(expected_action, history[0]);
107
TEST_F(ActionsFixture, ActivatePlannerAt)
109
const auto action_name = "activate-planner";
110
auto action_group = m_actions->action_group();
111
EXPECT_TRUE(m_mock_actions->history().empty());
112
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
114
const auto now = DateTime::NowLocal();
115
auto v = g_variant_new_int64(now.to_unix());
116
g_action_group_activate_action(action_group, action_name, v);
117
const auto a = MockActions::OpenPlannerAt;
118
EXPECT_EQ(std::vector<MockActions::Action>({a}), m_mock_actions->history());
119
EXPECT_EQ(now.to_unix(), m_mock_actions->date_time().to_unix());
177
TEST_F(ActionsFixture, DesktopOpenAlarmApp)
179
test_action_with_no_args("desktop.open-alarm-app",
180
MockActions::DesktopOpenAlarmApp);
183
TEST_F(ActionsFixture, DesktopOpenAppointment)
185
test_action_with_appt_arg("desktop.open-appointment",
186
MockActions::DesktopOpenAppt);
189
TEST_F(ActionsFixture, DesktopOpenCalendarApp)
191
test_action_with_time_arg("desktop.open-calendar-app",
192
MockActions::DesktopOpenCalendarApp);
195
TEST_F(ActionsFixture, DesktopOpenSettingsApp)
197
test_action_with_no_args("desktop.open-settings-app",
198
MockActions::DesktopOpenSettingsApp);
205
TEST_F(ActionsFixture, PhoneOpenAlarmApp)
207
test_action_with_no_args("phone.open-alarm-app",
208
MockActions::PhoneOpenAlarmApp);
211
TEST_F(ActionsFixture, PhoneOpenAppointment)
213
test_action_with_appt_arg("phone.open-appointment",
214
MockActions::PhoneOpenAppt);
217
TEST_F(ActionsFixture, PhoneOpenCalendarApp)
219
test_action_with_time_arg("phone.open-calendar-app",
220
MockActions::PhoneOpenCalendarApp);
223
TEST_F(ActionsFixture, PhoneOpenSettingsApp)
225
test_action_with_no_args("phone.open-settings-app",
226
MockActions::PhoneOpenSettingsApp);
122
233
TEST_F(ActionsFixture, SetLocation)
209
320
g_clear_pointer(&calendar_state, g_variant_unref);
214
TEST_F(ActionsFixture, OpenAppointment)
217
appt.uid = "some arbitrary uid";
218
appt.url = "http://www.canonical.com/";
219
appt.begin = m_state->clock->localtime();
220
m_state->calendar_upcoming->appointments().set(std::vector<Appointment>({appt}));
222
const auto action_name = "activate-appointment";
223
auto action_group = m_actions->action_group();
224
EXPECT_TRUE(m_mock_actions->history().empty());
225
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
227
auto v = g_variant_new_string(appt.uid.c_str());
228
g_action_group_activate_action(action_group, action_name, v);
229
const auto a = MockActions::OpenAppointment;
230
ASSERT_EQ(1, m_mock_actions->history().size());
231
ASSERT_EQ(a, m_mock_actions->history()[0]);
232
EXPECT_EQ(appt.url, m_mock_actions->url());