From df650bec0f1c634ee773c150b451c3bdd8ed4e65 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Mar 2014 17:54:57 -0600 Subject: =?UTF-8?q?In=20the=20Desktop=20profile,=20don't=20show=20the=20'A?= =?UTF-8?q?dd=20Event=E2=80=A6'=20button=20if=20evolution=20can't=20be=20l?= =?UTF-8?q?aunched.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test-menus.cpp | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'tests/test-menus.cpp') diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index 73d6036..452cbfc 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -252,7 +252,8 @@ private: void InspectAppointmentMenuItems(GMenuModel* section, int first_appt_index, - const std::vector& appointments) + const std::vector& appointments, + bool can_open_planner) { // try adding a few appointments and see if the menu updates itself m_state->planner->upcoming.set(appointments); @@ -260,7 +261,8 @@ private: //auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); //auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - EXPECT_EQ(appointments.size()+1, g_menu_model_get_n_items(section)); + const int n_add_event_buttons = can_open_planner ? 1 : 0; + EXPECT_EQ(n_add_event_buttons + appointments.size(), g_menu_model_get_n_items(section)); for (int i=0, n=appointments.size(); i appointments; m_state->settings->show_events.set(true); m_state->planner->upcoming.set(appointments); wait_msec(); section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - 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)); - const char* expected_action = "activate-planner"; - EXPECT_EQ(std::string("indicator.")+expected_action, action); - EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); - g_free(action); + EXPECT_EQ(n_add_event_buttons, g_menu_model_get_n_items(section)); + if (can_open_planner) + { + // when "show_events" is true, + // 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"; + EXPECT_EQ(std::string("indicator.")+expected_action, action); + EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); + g_free(action); + } g_clear_object(§ion); // try adding a few appointments and see if the menu updates itself @@ -302,15 +309,15 @@ private: m_state->planner->upcoming.set(appointments); wait_msec(); // wait a moment for the menu to update section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - EXPECT_EQ(3, g_menu_model_get_n_items(section)); - InspectAppointmentMenuItems(section, 0, appointments); + EXPECT_EQ(n_add_event_buttons + 2, g_menu_model_get_n_items(section)); + InspectAppointmentMenuItems(section, 0, appointments, can_open_planner); g_clear_object(§ion); // cleanup g_clear_object(&submenu); } - void InspectPhoneAppointments(GMenuModel* menu_model) + void InspectPhoneAppointments(GMenuModel* menu_model, bool can_open_planner) { auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); @@ -336,7 +343,7 @@ private: wait_msec(); // wait a moment for the menu to update section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); EXPECT_EQ(3, g_menu_model_get_n_items(section)); - InspectAppointmentMenuItems(section, 1, appointments); + InspectAppointmentMenuItems(section, 1, appointments, can_open_planner); g_clear_object(§ion); // cleanup @@ -347,10 +354,12 @@ protected: void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile) { + const auto can_open_planner = m_actions->can_open_planner(); + switch (profile) { case Menu::Desktop: - InspectDesktopAppointments(menu_model); + InspectDesktopAppointments(menu_model, can_open_planner); break; case Menu::DesktopGreeter: @@ -358,7 +367,7 @@ protected: break; case Menu::Phone: - InspectPhoneAppointments(menu_model); + InspectPhoneAppointments(menu_model, can_open_planner); break; case Menu::PhoneGreeter: @@ -507,6 +516,13 @@ TEST_F(MenuFixture, Appointments) { for(auto& menu : m_menus) InspectAppointments(menu->menu_model(), menu->profile()); + + // 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()); + std::shared_ptr menu = m_menu_factory->buildMenu(Menu::Desktop); + InspectAppointments(menu->menu_model(), menu->profile()); } TEST_F(MenuFixture, Locations) -- cgit v1.2.3