diff options
-rw-r--r-- | README | 19 | ||||
-rw-r--r-- | include/datetime/actions-live.h | 19 | ||||
-rw-r--r-- | include/datetime/actions.h | 20 | ||||
-rw-r--r-- | src/actions-live.cpp | 53 | ||||
-rw-r--r-- | src/actions.cpp | 116 | ||||
-rw-r--r-- | src/menu.cpp | 56 | ||||
-rw-r--r-- | tests/actions-mock.h | 67 | ||||
-rw-r--r-- | tests/test-actions.cpp | 260 | ||||
-rw-r--r-- | tests/test-exporter.cpp | 13 | ||||
-rw-r--r-- | tests/test-live-actions.cpp | 91 | ||||
-rw-r--r-- | tests/test-menus.cpp | 31 |
11 files changed, 488 insertions, 257 deletions
@@ -1,19 +1,26 @@ ACTIONS ======= - * "phone.open-settings" - * "desktop.open-settings" - Description: opens a page for changing indicator-datetime's settings + * "desktop.open-settings-app" + * "phone.open-settings-app" + Description: open the settings application. State: None Parameter: None - * "activate-planner" - Description: opens an appointment editor. + * "desktop.open-alarm-app" + * "phone.open-alarm-app" + Description: open the application for creating new alarms. + State: None + Parameter: None + + * "desktop.open-calendar-app" + * "phone.open-calendar-app" State: None Parameter: int64, a time_t hinting which day/time to show in the planner, or 0 for the current day - * "activate-appointment" + * "desktop.open-appointment" + * "phone.open-appointment" Description: opens an appointment editor to the specified appointment. State: None Parameter: string, an opaque uid to specify which appointment to use. diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index a24b844..0bf48a8 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -39,15 +39,18 @@ public: LiveActions(const std::shared_ptr<State>& state_in); ~LiveActions() =default; - void open_desktop_settings(); - void open_phone_settings(); - void open_phone_clock_app(); - bool can_open_planner() const; - void open_planner(); - void open_planner_at(const DateTime&); - void open_appointment(const std::string& uid); + bool desktop_has_calendar_app() const; + void desktop_open_alarm_app(); + void desktop_open_appointment(const Appointment&); + void desktop_open_calendar_app(const DateTime&); + void desktop_open_settings_app(); + + void phone_open_alarm_app(); + void phone_open_appointment(const Appointment&); + void phone_open_calendar_app(const DateTime&); + void phone_open_settings_app(); + void set_location(const std::string& zone, const std::string& name); - void set_calendar_date(const DateTime&); protected: virtual void execute_command(const std::string& command); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 2c4217c..f59ef67 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -42,14 +42,20 @@ namespace datetime { class Actions { public: - virtual void open_desktop_settings() =0; - virtual void open_phone_settings() =0; - virtual void open_phone_clock_app() =0; - virtual bool can_open_planner() const = 0; - virtual void open_planner() =0; - virtual void open_planner_at(const DateTime&) =0; - virtual void open_appointment(const std::string& uid) =0; + + virtual bool desktop_has_calendar_app() const =0; + virtual void desktop_open_alarm_app() =0; + virtual void desktop_open_appointment(const Appointment&) =0; + virtual void desktop_open_calendar_app(const DateTime&) =0; + virtual void desktop_open_settings_app() =0; + + virtual void phone_open_alarm_app() =0; + virtual void phone_open_appointment(const Appointment&) =0; + virtual void phone_open_calendar_app(const DateTime&) =0; + virtual void phone_open_settings_app() =0; + virtual void set_location(const std::string& zone, const std::string& name)=0; + void set_calendar_date(const DateTime&); GActionGroup* action_group(); const std::shared_ptr<State> state() const; diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 97b12db..068abe7 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -51,6 +51,7 @@ void LiveActions::execute_command(const std::string& cmdstr) void LiveActions::dispatch_url(const std::string& url) { + g_debug("Dispatching url '%s'", url.c_str()); url_dispatch_send(url.c_str(), nullptr, nullptr); } @@ -58,7 +59,7 @@ void LiveActions::dispatch_url(const std::string& url) **** ***/ -void LiveActions::open_desktop_settings() +void LiveActions::desktop_open_settings_app() { auto path = g_find_program_in_path("unity-control-center"); @@ -74,7 +75,7 @@ void LiveActions::open_desktop_settings() g_free (path); } -bool LiveActions::can_open_planner() const +bool LiveActions::desktop_has_calendar_app() const { static bool inited = false; static bool have_calendar = false; @@ -98,22 +99,17 @@ bool LiveActions::can_open_planner() const return have_calendar; } -void LiveActions::open_planner() +void LiveActions::desktop_open_alarm_app() { execute_command("evolution -c calendar"); } -void LiveActions::open_phone_settings() +void LiveActions::desktop_open_appointment(const Appointment& appt) { - dispatch_url("settings:///system/time-date"); -} - -void LiveActions::open_phone_clock_app() -{ - dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); + desktop_open_calendar_app(appt.begin); } -void LiveActions::open_planner_at(const DateTime& dt) +void LiveActions::desktop_open_calendar_app(const DateTime& dt) { const auto day_begins = dt.add_full(0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds()); const auto gmt = day_begins.to_timezone("UTC"); @@ -121,17 +117,34 @@ void LiveActions::open_planner_at(const DateTime& dt) execute_command(cmd.c_str()); } -void LiveActions::open_appointment(const std::string& uid) +/*** +**** +***/ + +void LiveActions::phone_open_alarm_app() { - for(const auto& appt : state()->calendar_upcoming->appointments().get()) - { - if(appt.uid != uid) - continue; + dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); +} - if (!appt.url.empty()) - dispatch_url(appt.url); - break; - } +void LiveActions::phone_open_appointment(const Appointment& appt) +{ + if (!appt.url.empty()) + dispatch_url(appt.url); + else if (appt.has_alarms) + phone_open_alarm_app(); + else + phone_open_calendar_app(DateTime::NowLocal()); +} + +void LiveActions::phone_open_calendar_app(const DateTime&) +{ + // does calendar app have a mechanism for specifying dates? + dispatch_url("appid://com.ubuntu.calendar/calendar/current-user-version"); +} + +void LiveActions::phone_open_settings_app() +{ + dispatch_url("settings:///system/time-date"); } /*** diff --git a/src/actions.cpp b/src/actions.cpp index dc9a34b..31b3394 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -34,67 +34,81 @@ namespace datetime { namespace { -void on_desktop_settings_activated(GSimpleAction * /*action*/, - GVariant * /*param*/, - gpointer gself) +DateTime datetime_from_timet_variant(GVariant* v) { - static_cast<Actions*>(gself)->open_desktop_settings(); -} + int64_t t = 0; -void on_phone_settings_activated(GSimpleAction * /*action*/, - GVariant * /*param*/, - gpointer gself) -{ - static_cast<Actions*>(gself)->open_phone_settings(); -} + if (v != nullptr) + if (g_variant_type_equal(G_VARIANT_TYPE_INT64,g_variant_get_type(v))) + t = g_variant_get_int64(v); -void on_phone_clock_activated(GSimpleAction * /*action*/, - GVariant * /*param*/, - gpointer gself) -{ - static_cast<Actions*>(gself)->open_phone_clock_app(); + if (t != 0) + return DateTime(t); + else + return DateTime::NowLocal(); } -void on_activate_appointment(GSimpleAction * /*action*/, - GVariant * param, - gpointer gself) +bool lookup_appointment_by_uid_variant(const std::shared_ptr<State>& state, GVariant* vuid, Appointment& setme) { - const auto uid = g_variant_get_string(param, nullptr); - auto self = static_cast<Actions*>(gself); - - g_return_if_fail(uid && *uid); + g_return_val_if_fail(vuid != nullptr, false); + g_return_val_if_fail(g_variant_type_equal(G_VARIANT_TYPE_STRING,g_variant_get_type(vuid)), false); + const auto uid = g_variant_get_string(vuid, nullptr); + g_return_val_if_fail(uid && *uid, false); - // find url of the upcoming appointment with this uid - for (const auto& appt : self->state()->calendar_upcoming->appointments().get()) + for(const auto& appt : state->calendar_upcoming->appointments().get()) { if (appt.uid == uid) { - const auto url = appt.url; - g_debug("%s: uid[%s] -> url[%s]", G_STRFUNC, uid, url.c_str()); - self->open_appointment(url); - break; + setme = appt; + return true; } } + + return false; } -void on_activate_planner(GSimpleAction * /*action*/, - GVariant * param, - gpointer gself) +void on_desktop_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) { - const auto at = g_variant_get_int64(param); auto self = static_cast<Actions*>(gself); + Appointment appt; + if (lookup_appointment_by_uid_variant(self->state(), vuid, appt)) + self->desktop_open_appointment(appt); +} +void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) +{ + static_cast<Actions*>(gself)->desktop_open_alarm_app(); +} +void on_desktop_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) +{ + const auto dt = datetime_from_timet_variant(vt); + static_cast<Actions*>(gself)->desktop_open_calendar_app(dt); +} +void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) +{ + static_cast<Actions*>(gself)->desktop_open_settings_app(); +} - if (at) - { - auto gdt = g_date_time_new_from_unix_local(at); - self->open_planner_at(DateTime(gdt)); - g_date_time_unref(gdt); - } - else // no time specified... - { - self->open_planner(); - } +void on_phone_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) +{ + auto self = static_cast<Actions*>(gself); + Appointment appt; + if (lookup_appointment_by_uid_variant(self->state(), vuid, appt)) + self->phone_open_appointment(appt); +} +void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) +{ + static_cast<Actions*>(gself)->phone_open_alarm_app(); } +void on_phone_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) +{ + const auto dt = datetime_from_timet_variant(vt); + static_cast<Actions*>(gself)->phone_open_calendar_app(dt); +} +void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself) +{ + static_cast<Actions*>(gself)->phone_open_settings_app(); +} + void on_set_location(GSimpleAction * /*action*/, GVariant * param, @@ -183,11 +197,17 @@ Actions::Actions(const std::shared_ptr<State>& state): m_actions(g_simple_action_group_new()) { GActionEntry entries[] = { - { "desktop.open-settings", on_desktop_settings_activated }, - { "phone.open-settings", on_phone_settings_activated }, - { "activate-phone-clock-app", on_phone_clock_activated }, - { "activate-appointment", on_activate_appointment, "s", nullptr }, - { "activate-planner", on_activate_planner, "x", nullptr }, + + { "desktop.open-appointment", on_desktop_appointment_activated, "s", nullptr }, + { "desktop.open-alarm-app", on_desktop_alarm_activated }, + { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr }, + { "desktop.open-settings-app", on_desktop_settings_activated }, + + { "phone.open-appointment", on_phone_appointment_activated, "s", nullptr }, + { "phone.open-alarm-app", on_phone_alarm_activated }, + { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr }, + { "phone.open-settings-app", on_phone_settings_activated }, + { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } }; diff --git a/src/menu.cpp b/src/menu.cpp index 9091951..ff5b722 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -225,22 +225,28 @@ private: GMenuModel* create_calendar_section(Profile profile) { - const bool allow_activation = (profile == Desktop) - || (profile == Phone); const bool show_calendar = m_state->settings->show_calendar.get() && ((profile == Desktop) || (profile == DesktopGreeter)); auto menu = g_menu_new(); + const char * action_name; + + if (profile == Phone) + action_name = "indicator.phone.open-calendar-app"; + else if (profile == Desktop) + action_name = "indicator.desktop.open-calendar-app"; + else + action_name = nullptr; + // add a menuitem that shows the current date auto label = m_state->clock->localtime().format(_("%A, %e %B %Y")); auto item = g_menu_item_new (label.c_str(), nullptr); auto v = get_serialized_calendar_icon(); g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, v); - if (allow_activation) + if (action_name != nullptr) { v = g_variant_new_int64(0); - const char* action = "indicator.activate-planner"; - g_menu_item_set_action_and_target_value (item, action, v); + g_menu_item_set_action_and_target_value (item, action_name, v); } g_menu_append_item(menu, item); g_object_unref(item); @@ -253,11 +259,8 @@ private: g_menu_item_set_action_and_target_value (item, "indicator.calendar", v); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.calendar"); - if (allow_activation) - { - g_menu_item_set_attribute (item, "activation-action", - "s", "indicator.activate-planner"); - } + if (action_name != nullptr) + g_menu_item_set_attribute (item, "activation-action", "s", action_name); g_menu_append_item (menu, item); g_object_unref (item); } @@ -270,6 +273,15 @@ private: const int MAX_APPTS = 5; std::set<std::string> added; + const char * action_name; + + if (profile == Phone) + action_name = "indicator.phone.open-appointment"; + else if ((profile == Desktop) && m_actions->desktop_has_calendar_app()) + action_name = "indicator.desktop.open-appointment"; + else + action_name = nullptr; + for (const auto& appt : m_upcoming) { // don't show duplicates @@ -303,15 +315,11 @@ private: if (!appt.color.empty()) g_menu_item_set_attribute (menu_item, "x-canonical-color", "s", appt.color.c_str()); - - if (profile == Phone) - g_menu_item_set_action_and_target_value (menu_item, - "indicator.activate-appointment", - g_variant_new_string (appt.uid.c_str())); - else if (m_actions->can_open_planner()) - g_menu_item_set_action_and_target_value (menu_item, - "indicator.activate-planner", - g_variant_new_int64 (unix_time)); + + if (action_name != nullptr) + g_menu_item_set_action_and_target_value (menu_item, action_name, + g_variant_new_string (appt.uid.c_str())); + g_menu_append_item (menu, menu_item); g_object_unref (menu_item); } @@ -325,11 +333,11 @@ private: { add_appointments (menu, profile); - if (m_actions->can_open_planner()) + if (m_actions->desktop_has_calendar_app()) { // add the 'Add Event…' menuitem auto menu_item = g_menu_item_new(_("Add Event…"), nullptr); - const gchar* action_name = "indicator.activate-planner"; + const gchar* action_name = "indicator.desktop.open-calendar-app"; auto v = g_variant_new_int64(0); g_menu_item_set_action_and_target_value(menu_item, action_name, v); g_menu_append_item(menu, menu_item); @@ -338,7 +346,7 @@ private: } else if (profile==Phone) { - auto menu_item = g_menu_item_new (_("Clock"), "indicator.activate-phone-clock-app"); + auto menu_item = g_menu_item_new (_("Clock"), "indicator.phone.open-alarm-app"); g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon()); g_menu_append_item (menu, menu_item); g_object_unref (menu_item); @@ -383,11 +391,11 @@ private: if (profile == Desktop) { - g_menu_append (menu, _("Date & Time Settings…"), "indicator.desktop.open-settings"); + g_menu_append (menu, _("Date & Time Settings…"), "indicator.desktop.open-settings-app"); } else if (profile == Phone) { - g_menu_append (menu, _("Time & Date settings…"), "indicator.phone.open-settings"); + g_menu_append (menu, _("Time & Date settings…"), "indicator.phone.open-settings-app"); } return G_MENU_MODEL (menu); diff --git a/tests/actions-mock.h b/tests/actions-mock.h index ebd8a4d..77315c0 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -34,28 +34,54 @@ public: MockActions(std::shared_ptr<State>& state_in): Actions(state_in) {} ~MockActions() =default; - enum Action { OpenDesktopSettings, OpenPhoneSettings, OpenPhoneClockApp, - OpenPlanner, OpenPlannerAt, OpenAppointment, SetLocation }; + enum Action { DesktopOpenAlarmApp, + DesktopOpenAppt, + DesktopOpenCalendarApp, + DesktopOpenSettingsApp, + PhoneOpenAlarmApp, + PhoneOpenAppt, + PhoneOpenCalendarApp, + PhoneOpenSettingsApp, + SetLocation }; + const std::vector<Action>& history() const { return m_history; } const DateTime& date_time() const { return m_date_time; } const std::string& zone() const { return m_zone; } const std::string& name() const { return m_name; } - const std::string& url() const { return m_url; } + const Appointment& appointment() const { return m_appt; } void clear() { m_history.clear(); m_zone.clear(); m_name.clear(); } - void open_desktop_settings() { m_history.push_back(OpenDesktopSettings); } - - void open_phone_settings() { m_history.push_back(OpenPhoneSettings); } - - void open_phone_clock_app() { m_history.push_back(OpenPhoneClockApp); } - - bool can_open_planner() const { return m_can_open_planner; } - - void open_planner() { m_history.push_back(OpenPlanner); } + bool desktop_has_calendar_app() const { + return m_desktop_has_calendar_app; + } + void desktop_open_alarm_app() { + m_history.push_back(DesktopOpenAlarmApp); + } + void desktop_open_appointment(const Appointment& appt) { + m_appt = appt; + m_history.push_back(DesktopOpenAppt); + } + void desktop_open_calendar_app(const DateTime& dt) { + m_date_time = dt; + m_history.push_back(DesktopOpenCalendarApp); + } + void desktop_open_settings_app() { + m_history.push_back(DesktopOpenSettingsApp); + } - void open_planner_at(const DateTime& date_time_) { - m_history.push_back(OpenPlannerAt); - m_date_time = date_time_; + void phone_open_alarm_app() { + m_history.push_back(PhoneOpenAlarmApp); + } + void phone_open_appointment(const Appointment& appt) { + m_appt = appt; + m_history.push_back(PhoneOpenAppt); + } + void phone_open_calendar_app(const DateTime& dt) { + m_date_time = dt; + m_history.push_back(PhoneOpenCalendarApp); + } + void phone_open_settings_app() { + m_history.push_back(PhoneOpenSettingsApp); } void set_location(const std::string& zone_, const std::string& name_) { @@ -64,16 +90,13 @@ public: m_name = name_; } - void open_appointment(const std::string& url_) { - m_history.push_back(OpenAppointment); - m_url = url_; + void set_desktop_has_calendar_app(bool b) { + m_desktop_has_calendar_app = b; } - void set_can_open_planner(bool b) { m_can_open_planner = b; } - private: - bool m_can_open_planner = true; - std::string m_url; + bool m_desktop_has_calendar_app = true; + Appointment m_appt; std::string m_zone; std::string m_name; DateTime m_date_time; diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 105c850..252e192 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -23,7 +23,130 @@ using namespace unity::indicator::datetime; -typedef StateFixture ActionsFixture; +class ActionsFixture: public StateFixture +{ + typedef StateFixture super; + + std::vector<Appointment> build_some_appointments() + { + const auto now = m_state->clock->localtime(); + auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); + const auto tomorrow = DateTime(gdt_tomorrow); + g_date_time_unref(gdt_tomorrow); + + Appointment a1; // an alarm clock appointment + a1.color = "red"; + a1.summary = "Alarm"; + a1.summary = "http://www.example.com/"; + a1.uid = "example"; + a1.has_alarms = true; + a1.begin = a1.end = tomorrow; + + Appointment a2; // a non-alarm appointment + a2.color = "green"; + a2.summary = "Other Text"; + a2.summary = "http://www.monkey.com/"; + a2.uid = "monkey"; + a2.has_alarms = false; + a2.begin = a2.end = tomorrow; + + return std::vector<Appointment>({a1, a2}); + } + +protected: + + virtual void SetUp() + { + super::SetUp(); + } + + virtual void TearDown() + { + super::TearDown(); + } + + void test_action_with_no_args(const char * action_name, + MockActions::Action expected_action) + { + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // run the test + g_action_group_activate_action(action_group, action_name, nullptr); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + } + + void test_action_with_time_arg(const char * action_name, + MockActions::Action expected_action) + { + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // activate the action + const auto now = DateTime::NowLocal(); + auto v = g_variant_new_int64(now.to_unix()); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + EXPECT_EQ(now.format("%F %T"), + m_mock_actions->date_time().format("%F %T")); + } + + void test_action_with_appt_arg(const char * action_name, + MockActions::Action expected_action) + { + /// + /// Test 1: activate an appointment that we know about + /// + + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // init some appointments to the state + const auto appointments = build_some_appointments(); + m_mock_state->mock_range_planner->appointments().set(appointments); + + // activate the action + auto v = g_variant_new_string(appointments[0].uid.c_str()); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + EXPECT_EQ(appointments[0], + m_mock_actions->appointment()); + + /// + /// Test 2: activate an appointment we *don't* know about + /// + + // setup + m_mock_actions->clear(); + EXPECT_TRUE(m_mock_actions->history().empty()); + + // activate the action + v = g_variant_new_string("this-uid-is-not-one-that-we-have"); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_TRUE(m_mock_actions->history().empty()); + } +}; + +/*** +**** +***/ TEST_F(ActionsFixture, ActionsExist) { @@ -32,93 +155,81 @@ TEST_F(ActionsFixture, ActionsExist) const char* names[] = { "desktop-header", "calendar", "set-location", - "activate-planner", - "activate-appointment", - "activate-phone-clock-app", - "phone.open-settings", - "desktop.open-settings" }; + "desktop.open-appointment", + "desktop.open-alarm-app", + "desktop.open-calendar-app", + "desktop.open-settings-app", + "phone.open-appointment", + "phone.open-alarm-app", + "phone.open-calendar-app", + "phone.open-settings-app" }; + for(const auto& name: names) { EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), name)); } } -TEST_F(ActionsFixture, DesktopOpenSettings) -{ - const auto action_name = "desktop.open-settings"; - const auto expected_action = MockActions::OpenDesktopSettings; - - auto action_group = m_actions->action_group(); - auto history = m_mock_actions->history(); - EXPECT_EQ(0, history.size()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); +/*** +**** +***/ - g_action_group_activate_action(action_group, action_name, nullptr); - history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, DesktopOpenAlarmApp) +{ + test_action_with_no_args("desktop.open-alarm-app", + MockActions::DesktopOpenAlarmApp); } -TEST_F(ActionsFixture, PhoneOpenSettings) +TEST_F(ActionsFixture, DesktopOpenAppointment) { - const auto action_name = "phone.open-settings"; - const auto expected_action = MockActions::OpenPhoneSettings; - - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + test_action_with_appt_arg("desktop.open-appointment", + MockActions::DesktopOpenAppt); +} - g_action_group_activate_action(action_group, action_name, nullptr); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, DesktopOpenCalendarApp) +{ + test_action_with_time_arg("desktop.open-calendar-app", + MockActions::DesktopOpenCalendarApp); } -TEST_F(ActionsFixture, ActivatePhoneClockApp) +TEST_F(ActionsFixture, DesktopOpenSettingsApp) { - const auto action_name = "activate-phone-clock-app"; - const auto expected_action = MockActions::OpenPhoneClockApp; + test_action_with_no_args("desktop.open-settings-app", + MockActions::DesktopOpenSettingsApp); +} - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); +/*** +**** +***/ - g_action_group_activate_action(action_group, action_name, nullptr); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, PhoneOpenAlarmApp) +{ + test_action_with_no_args("phone.open-alarm-app", + MockActions::PhoneOpenAlarmApp); } -TEST_F(ActionsFixture, ActivatePlanner) +TEST_F(ActionsFixture, PhoneOpenAppointment) { - const auto action_name = "activate-planner"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); - - const auto expected_action = MockActions::OpenPlanner; - auto v = g_variant_new_int64(0); - g_action_group_activate_action(action_group, action_name, v); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); + test_action_with_appt_arg("phone.open-appointment", + MockActions::PhoneOpenAppt); } -TEST_F(ActionsFixture, ActivatePlannerAt) +TEST_F(ActionsFixture, PhoneOpenCalendarApp) { - const auto action_name = "activate-planner"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + test_action_with_time_arg("phone.open-calendar-app", + MockActions::PhoneOpenCalendarApp); +} - const auto now = DateTime::NowLocal(); - auto v = g_variant_new_int64(now.to_unix()); - g_action_group_activate_action(action_group, action_name, v); - const auto a = MockActions::OpenPlannerAt; - EXPECT_EQ(std::vector<MockActions::Action>({a}), m_mock_actions->history()); - EXPECT_EQ(now.to_unix(), m_mock_actions->date_time().to_unix()); +TEST_F(ActionsFixture, PhoneOpenSettingsApp) +{ + test_action_with_no_args("phone.open-settings-app", + MockActions::PhoneOpenSettingsApp); } +/*** +**** +***/ + TEST_F(ActionsFixture, SetLocation) { const auto action_name = "set-location"; @@ -209,26 +320,3 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) g_clear_pointer(&calendar_state, g_variant_unref); } - - -TEST_F(ActionsFixture, OpenAppointment) -{ - Appointment appt; - appt.uid = "some arbitrary uid"; - appt.url = "http://www.canonical.com/"; - appt.begin = m_state->clock->localtime(); - m_state->calendar_upcoming->appointments().set(std::vector<Appointment>({appt})); - - const auto action_name = "activate-appointment"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); - - auto v = g_variant_new_string(appt.uid.c_str()); - g_action_group_activate_action(action_group, action_name, v); - const auto a = MockActions::OpenAppointment; - ASSERT_EQ(1, m_mock_actions->history().size()); - ASSERT_EQ(a, m_mock_actions->history()[0]); - EXPECT_EQ(appt.url, m_mock_actions->url()); -} - diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index 104fb4b..a255ef9 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -104,11 +104,14 @@ TEST_F(ExporterFixture, Publish) names.insert(names_strv[i]); // confirm the actions that we expect - EXPECT_EQ(1, names.count("activate-appointment")); - EXPECT_EQ(1, names.count("activate-desktop-settings")); - EXPECT_EQ(1, names.count("activate-phone-clock-app")); - EXPECT_EQ(1, names.count("activate-phone-settings")); - EXPECT_EQ(1, names.count("activate-planner")); + EXPECT_EQ(1, names.count("desktop.open-alarm-app")); + EXPECT_EQ(1, names.count("desktop.open-appointment")); + EXPECT_EQ(1, names.count("desktop.open-calendar-app")); + EXPECT_EQ(1, names.count("desktop.open-settings-app")); + EXPECT_EQ(1, names.count("phone.open-alarm-app")); + EXPECT_EQ(1, names.count("phone.open-appointment")); + EXPECT_EQ(1, names.count("phone.open-calendar-app")); + EXPECT_EQ(1, names.count("phone.open-settings-app")); EXPECT_EQ(1, names.count("calendar")); EXPECT_EQ(1, names.count("desktop_greeter-header")); EXPECT_EQ(1, names.count("desktop-header")); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index d6ef424..c67b380 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -252,44 +252,95 @@ TEST_F(LiveActionsFixture, SetLocation) EXPECT_EQ(expected, m_state->settings->timezone_name.get()); } -TEST_F(LiveActionsFixture, OpenDesktopSettings) +/*** +**** +***/ + +TEST_F(LiveActionsFixture, DesktopOpenAlarmApp) +{ + m_actions->desktop_open_alarm_app(); + const std::string expected = "evolution -c calendar"; + EXPECT_EQ(expected, m_live_actions->last_cmd); +} + +TEST_F(LiveActionsFixture, DesktopOpenAppointment) +{ + Appointment a; + a.uid = "some-uid"; + a.begin = DateTime::NowLocal(); + m_actions->desktop_open_appointment(a); + const std::string expected_substr = "evolution \"calendar:///?startdate="; + EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); +} + +TEST_F(LiveActionsFixture, DesktopOpenCalendarApp) +{ + m_actions->desktop_open_calendar_app(DateTime::NowLocal()); + const std::string expected_substr = "evolution \"calendar:///?startdate="; + EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); +} + +TEST_F(LiveActionsFixture, DesktopOpenSettingsApp) { - m_actions->open_desktop_settings(); + m_actions->desktop_open_settings_app(); const std::string expected_substr = "control-center"; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } -TEST_F(LiveActionsFixture, OpenPlanner) +/*** +**** +***/ + +namespace { - m_actions->open_planner(); - const std::string expected = "evolution -c calendar"; - EXPECT_EQ(expected, m_live_actions->last_cmd); + const std::string clock_app_url = "appid://com.ubuntu.clock/clock/current-user-version"; + + const std::string calendar_app_url = "appid://com.ubuntu.calendar/calendar/current-user-version"; } -TEST_F(LiveActionsFixture, OpenPhoneSettings) +TEST_F(LiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->open_phone_settings(); - const std::string expected = "settings:///system/time-date"; - EXPECT_EQ(expected, m_live_actions->last_url); + m_actions->phone_open_alarm_app(); + EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(LiveActionsFixture, OpenPhoneClockApp) +TEST_F(LiveActionsFixture, PhoneOpenAppointment) { - m_actions->open_phone_clock_app(); - const std::string expected = "appid://com.ubuntu.clock/clock/current-user-version"; + Appointment a; + + a.uid = "some-uid"; + a.begin = DateTime::NowLocal(); + a.has_alarms = false; + m_actions->phone_open_appointment(a); + EXPECT_EQ(calendar_app_url, m_live_actions->last_url); + + a.has_alarms = true; + m_actions->phone_open_appointment(a); + EXPECT_EQ(clock_app_url, m_live_actions->last_url); + + a.url = "appid://blah"; + m_actions->phone_open_appointment(a); + EXPECT_EQ(a.url, m_live_actions->last_url); +} + +TEST_F(LiveActionsFixture, PhoneOpenCalendarApp) +{ + m_actions->phone_open_calendar_app(DateTime::NowLocal()); + const std::string expected = "appid://com.ubuntu.calendar/calendar/current-user-version"; EXPECT_EQ(expected, m_live_actions->last_url); } -TEST_F(LiveActionsFixture, OpenPlannerAt) +TEST_F(LiveActionsFixture, PhoneOpenSettingsApp) { - const auto now = DateTime::NowLocal(); - m_actions->open_planner_at(now); - const auto today_begins = now.add_full(0, 0, 0, -now.hour(), -now.minute(), -now.seconds()); - const auto gmt = today_begins.to_timezone("UTC"); - const auto expected = gmt.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - EXPECT_EQ(expected, m_live_actions->last_cmd); + m_actions->phone_open_settings_app(); + const std::string expected = "settings:///system/time-date"; + EXPECT_EQ(expected, m_live_actions->last_url); } +/*** +**** +***/ + TEST_F(LiveActionsFixture, CalendarState) { // init the clock diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index 29d86b3..b485037 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -92,7 +92,16 @@ protected: void InspectCalendar(GMenuModel* menu_model, Menu::Profile profile) { gchar* str = nullptr; - const auto actions_expected = (profile == Menu::Desktop) || (profile == Menu::Phone); + + const char * expected_action; + + if (profile == Menu::Desktop) + expected_action = "indicator.desktop.open-calendar-app"; + else if (profile == Menu::Phone) + expected_action = "indicator.phone.open-calendar-app"; + else + expected_action = nullptr; + const auto calendar_expected = ((profile == Menu::Desktop) || (profile == Menu::DesktopGreeter)) && (m_state->settings->show_calendar.get()); @@ -113,8 +122,8 @@ protected: g_clear_pointer(&str, g_free); g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &str); - if (actions_expected) - EXPECT_STREQ("indicator.activate-planner", str); + if (expected_action != nullptr) + EXPECT_STREQ(expected_action, str); else EXPECT_TRUE(str == nullptr); g_clear_pointer(&str, g_free); @@ -131,8 +140,8 @@ protected: g_clear_pointer(&str, g_free); g_menu_model_get_item_attribute(section, 1, "activation-action", "s", &str); - if (actions_expected) - EXPECT_STREQ("indicator.activate-planner", str); + if (expected_action != nullptr) + EXPECT_STREQ(expected_action, str); else EXPECT_TRUE(str == nullptr); g_clear_pointer(&str, g_free); @@ -297,7 +306,7 @@ private: // there should be an "add event" button even if there aren't any appointments gchar* action = nullptr; EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); - const char* expected_action = "activate-planner"; + const char* expected_action = "desktop.open-calendar-app"; EXPECT_EQ(std::string("indicator.")+expected_action, action); EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); g_free(action); @@ -328,7 +337,7 @@ private: // check that there's a "clock app" menuitem even when there are no appointments auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - const char* expected_action = "activate-phone-clock-app"; + const char* expected_action = "phone.open-alarm-app"; EXPECT_EQ(1, g_menu_model_get_n_items(section)); gchar* action = nullptr; EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); @@ -354,7 +363,7 @@ protected: void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile) { - const auto can_open_planner = m_actions->can_open_planner(); + const auto can_open_planner = m_actions->desktop_has_calendar_app(); switch (profile) { @@ -443,9 +452,9 @@ protected: std::string expected_action; if (profile == Menu::Desktop) - expected_action = "indicator.activate-desktop-settings"; + expected_action = "indicator.desktop.open-settings-app"; else if (profile == Menu::Phone) - expected_action = "indicator.activate-phone-settings"; + expected_action = "indicator.phone.open-settings-app"; // get the Settings section auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); @@ -520,7 +529,7 @@ TEST_F(MenuFixture, Appointments) // toggle can_open_planner() and test the desktop again // to confirm that the "Add Event…" menuitem appears iff // there's a calendar available user-agent - m_mock_actions->set_can_open_planner (!m_actions->can_open_planner()); + m_mock_actions->set_desktop_has_calendar_app (!m_actions->desktop_has_calendar_app()); std::shared_ptr<Menu> menu = m_menu_factory->buildMenu(Menu::Desktop); InspectAppointments(menu->menu_model(), menu->profile()); } |