← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~ahayzen/ubuntu-weather-app/reboot-1452497-add-location-from-home into lp:ubuntu-weather-app/reboot

 

Andrew Hayzen has proposed merging lp:~ahayzen/ubuntu-weather-app/reboot-1452497-add-location-from-home into lp:ubuntu-weather-app/reboot.

Commit message:
* Add autopilot test which adds a location the from home page via searching

Requested reviews:
  Ubuntu Weather Developers (ubuntu-weather-dev)
Related bugs:
  Bug #1452497 in Ubuntu Weather App: "[reboot] Autopilot Testcase Needed: Test adding a location"
  https://bugs.launchpad.net/ubuntu-weather-app/+bug/1452497

For more details, see:
https://code.launchpad.net/~ahayzen/ubuntu-weather-app/reboot-1452497-add-location-from-home/+merge/266051

* Add autopilot test which adds a location the from home page via searching

This tests that you can add a location from the home page via using the bottom edge, header action and then searching for a location.
-- 
Your team Ubuntu Weather Developers is requested to review the proposed merge of lp:~ahayzen/ubuntu-weather-app/reboot-1452497-add-location-from-home into lp:ubuntu-weather-app/reboot.
=== modified file 'app/ui/AddLocationPage.qml'
--- app/ui/AddLocationPage.qml	2015-06-28 23:37:10 +0000
+++ app/ui/AddLocationPage.qml	2015-07-27 23:15:14 +0000
@@ -48,6 +48,7 @@
             actions: [
                 Action {
                     iconName: "search"
+                    objectName: "search"
                     text: i18n.tr("City")
                     onTriggered: {
                         addLocationPage.state = "search"
@@ -206,6 +207,7 @@
 
         delegate: ListItem {
             divider.visible: false
+            objectName: "addLocation" + index
             Column {
                 anchors {
                     left: parent.left

=== modified file 'app/ui/LocationsPage.qml'
--- app/ui/LocationsPage.qml	2015-07-27 00:57:57 +0000
+++ app/ui/LocationsPage.qml	2015-07-27 23:15:14 +0000
@@ -27,6 +27,7 @@
     id: locationsPage
     // Set to null otherwise the first delegate appears +header.height down the page
     flickable: null
+    objectName: "locationsPage"
     title: i18n.tr("Locations")
 
     state: locationsListView.state === "multiselectable" ? "selection" : "default"
@@ -37,6 +38,7 @@
             actions: [
                 Action {
                     iconName: "add"
+                    objectName: "addLocation"
                     onTriggered: mainPageStack.push(Qt.resolvedUrl("AddLocationPage.qml"))
                 }
             ]

=== modified file 'debian/changelog'
--- debian/changelog	2015-07-26 15:24:27 +0000
+++ debian/changelog	2015-07-27 23:15:14 +0000
@@ -12,6 +12,7 @@
   * Add mocked locations for autopilot and add a test using the data
   * Add setting to disable auto detecting location
   * When running under autopilot do not auto detect location
+  * Add autopilot test which adds a location the from home page via searching
 
  -- Victor Thompson <victor.thompson@xxxxxxxxx>  Mon, 01 Jun 2015 20:11:23 -0500
 

=== modified file 'tests/autopilot/ubuntu_weather_app/__init__.py'
--- tests/autopilot/ubuntu_weather_app/__init__.py	2015-07-23 00:36:06 +0000
+++ tests/autopilot/ubuntu_weather_app/__init__.py	2015-07-27 23:15:14 +0000
@@ -5,8 +5,13 @@
 # under the terms of the GNU General Public License version 3, as published
 # by the Free Software Foundation.
 
+import logging
+
 """ubuntu-weather-app tests and emulators - top level package."""
 from ubuntuuitoolkit import MainView, UbuntuUIToolkitCustomProxyObjectBase
+from autopilot.introspection import dbus
+
+logger = logging.getLogger(__name__)
 
 
 class UbuntuWeatherAppException(Exception):
@@ -39,6 +44,10 @@
         return self.main_view.wait_select_single(
             HomePage, objectName="homePage")
 
+    def get_locations_page(self):
+        return self.main_view.wait_select_single(
+            LocationsPage, objectName="locationsPage")
+
     def click_add_location_button(self):
         add_location_button = self.main_view.wait_select_single(
             "Button", objectName="emptyStateButton")
@@ -47,32 +56,92 @@
 
 class Page(UbuntuUIToolkitCustomProxyObjectBase):
     """Autopilot helper for Pages."""
-    def __init__(self, *args):
-        super(Page, self).__init__(*args)
+    def __init__(self, *args, **kwargs):
+        super(Page, self).__init__(*args, **kwargs)
+
+        # XXX we need a better way to keep reference to the main view.
+        # --elopio - 2014-01-31
+
+        # Use only objectName due to bug 1350532 as it is MainView12
+        self.main_view = self.get_root_instance().select_single(
+            objectName="weather")
+
+    def click_back(self):
+        return self.main_view.get_header().click_back_button()
 
 
 class PageWithBottomEdge(Page):
-    """Autopilot helper for PageWithBottomEdge."""
-    def __init__(self, *args):
-        super(PageWithBottomEdge, self).__init__(*args)
+    """
+    An emulator class that makes it easy to interact with the bottom edge
+    swipe page
+    """
+    def __init__(self, *args, **kwargs):
+        super(PageWithBottomEdge, self).__init__(*args, **kwargs)
+
+    def reveal_bottom_edge_page(self):
+        """Bring the bottom edge page to the screen"""
+        self.bottomEdgePageLoaded.wait_for(True)
+
+        try:
+            action_item = self.wait_select_single(objectName='bottomEdgeTip')
+            action_item.visible.wait_for(True)
+            start_x = (action_item.globalRect.x +
+                       (action_item.globalRect.width * 0.5))
+            start_y = (action_item.globalRect.y +
+                       (action_item.height * 0.5))
+            stop_y = start_y - (self.height * 0.7)
+            self.pointing_device.drag(start_x, start_y,
+                                      start_x, stop_y, rate=2)
+            self.isReady.wait_for(True)
+        except dbus.StateNotFoundError:
+            logger.error('BottomEdge element not found.')
+            raise
 
 
 class AddLocationPage(Page):
     """Autopilot helper for AddLocationPage."""
-    def __init__(self, *args):
-        super(AddLocationPage, self).__init__(*args)
-
-
-class HomePage(Page):
+    def __init__(self, *args, **kwargs):
+        super(AddLocationPage, self).__init__(*args, **kwargs)
+
+    @click_object
+    def click_location(self, index):
+        return self.select_single("UCListItem",
+                                  objectName="addLocation" + str(index))
+
+    def click_search_action(self):
+        self.main_view.get_header().click_action_button("search")
+
+    def get_search_field(self):
+        header = self.main_view.get_header()
+
+        return header.select_single("TextField", objectName="searchField")
+
+    def search(self, value):
+        self.click_search_action()
+
+        search_field = self.get_search_field()
+        search_field.write(value)
+
+
+class HomePage(PageWithBottomEdge):
     """Autopilot helper for HomePage."""
-    def __init__(self, *args):
-        super(HomePage, self).__init__(*args)
+    def __init__(self, *args, **kwargs):
+        super(HomePage, self).__init__(*args, **kwargs)
 
     def get_location_count(self):
         return self.wait_select_single(
             "QQuickListView", objectName="locationPages").count
 
 
+class LocationsPage(Page):
+    """Autopilot helper for LocationsPage."""
+    def __init__(self, *args, **kwargs):
+        super(LocationsPage, self).__init__(*args, **kwargs)
+
+    def click_add_location_action(self):
+        self.main_view.get_header().click_action_button("addLocation")
+
+
 class MainView(MainView):
     """Autopilot custom proxy object for the MainView."""
     retry_delay = 0.2

=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_home_page.py'
--- tests/autopilot/ubuntu_weather_app/tests/test_home_page.py	2015-07-18 19:08:21 +0000
+++ tests/autopilot/ubuntu_weather_app/tests/test_home_page.py	2015-07-27 23:15:14 +0000
@@ -24,6 +24,43 @@
     def setUp(self):
         super(TestHomePage, self).setUp()
 
+    def test_add_location(self):
+        """ tests adding a location via header action and selecting via
+            searching for the location """
+
+        # Get the start count of the homepage
+        home_page = self.app.get_home_page()
+        start_count = home_page.get_location_count()
+
+        # Open the locations page from bottom edge
+        home_page.reveal_bottom_edge_page()
+
+        locations_page = self.app.get_locations_page()
+        locations_page.visible.wait_for(True)
+
+        # Select the add header action and get the add locations page
+        locations_page.click_add_location_action()
+
+        add_location_page = self.app.get_add_location_page()
+        add_location_page.visible.wait_for(True)
+
+        # Perform search
+        add_location_page.search("Paris")
+
+        # Select the location
+        add_location_page.click_location(0)
+
+        # Check locations page is now visible and go back
+        self.assertThat(locations_page.visible, Eventually(Equals(True)))
+        locations_page.click_back()
+
+        # Check that the location was added
+        self.assertThat(home_page.get_location_count,
+                        Eventually(Equals(start_count + 1)))
+
+        # Check homepage is now visible
+        self.assertThat(home_page.visible, Eventually(Equals(True)))
+
     def test_locations_count_startup(self):
         """ tests that the correct number of locations appear at startup """
 


Follow ups