← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nik90/ubuntu-clock-app/add-stopwatch-ap-tests into lp:ubuntu-clock-app

 

Nekhelesh Ramananthan has proposed merging lp:~nik90/ubuntu-clock-app/add-stopwatch-ap-tests into lp:ubuntu-clock-app with lp:~nik90/ubuntu-clock-app/fix-failing-ap-tests as a prerequisite.

Commit message:
Added stopwatch tests

Requested reviews:
  Ubuntu Clock Developers (ubuntu-clock-dev)
Related bugs:
  Bug #1490206 in Ubuntu Clock App: "[Autopilot] Test stopwatch feature"
  https://bugs.launchpad.net/ubuntu-clock-app/+bug/1490206

For more details, see:
https://code.launchpad.net/~nik90/ubuntu-clock-app/add-stopwatch-ap-tests/+merge/287919

Added stopwatch tests
-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~nik90/ubuntu-clock-app/add-stopwatch-ap-tests into lp:ubuntu-clock-app.
=== modified file 'app/MainPage.qml'
--- app/MainPage.qml	2016-03-03 00:28:40 +0000
+++ app/MainPage.qml	2016-03-03 12:07:39 +0000
@@ -107,13 +107,41 @@
         }
     }
 
+
+
     ListView {
         id: listview
+        objectName: "pageListView"
+
+        property alias isMoving: moveAnimation.running
+
+        function moveToStopwatchPage() {
+            moveAnimation.moveTo(listview.originX + listview.width)
+            listview.currentIndex = 1
+        }
+
+        function moveToClockPage() {
+            moveAnimation.moveTo(listview.originX)
+            listview.currentIndex = 0
+        }
+
+        UbuntuNumberAnimation {
+            id: moveAnimation
+            objectName: "pageListViewAnimation"
+
+            target: listview
+            property: "contentX"
+            function moveTo(contentX) {
+                from = listview.contentX
+                to = contentX
+                start()
+            }
+        }
 
         // Show the stopwatch page on app startup if it is running
         Component.onCompleted: {
             if (stopwatchPage.isRunning) {
-                positionViewAtIndex(1, ListView.SnapPosition)
+                moveToStopwatchPage()
             }
         }
 
@@ -126,9 +154,6 @@
 
         model: navigationModel
         orientation: ListView.Horizontal
-        snapMode: ListView.SnapOneItem
         interactive: false
-        highlightMoveDuration: UbuntuAnimation.BriskDuration
-        highlightRangeMode: ListView.StrictlyEnforceRange
     }
 }

=== modified file 'app/components/HeaderNavigation.qml'
--- app/components/HeaderNavigation.qml	2016-02-29 12:42:02 +0000
+++ app/components/HeaderNavigation.qml	2016-03-03 12:07:39 +0000
@@ -31,15 +31,21 @@
         spacing: units.gu(2)
 
         ActionIcon {
+            id: clockNavigationButton
+            objectName: "clockNavigationButton"
+
             icon.name: "clock"
             icon.color: listview.currentIndex === 0 ? "#19b6ee" : "#5d5d5d" // #TODO: Replace with UbuntuColors.Blue and UbuntuColors.Slate after OTA-10
-            onClicked: listview.currentIndex = 0
+            onClicked: listview.moveToClockPage()
         }
         
         ActionIcon {
+            id: stopwatchNavigationButton
+            objectName: "stopwatchNavigationButton"
+
             icon.name: "stopwatch"
             icon.color: listview.currentIndex === 1 ? "#19b6ee" : "#5d5d5d" // #TODO: Replace with UbuntuColors.Blue and UbuntuColors.Slate after OTA-10
-            onClicked: listview.currentIndex = 1
+            onClicked:  listview.moveToStopwatchPage()
         }
     }
     

=== modified file 'app/stopwatch/StopwatchFace.qml'
--- app/stopwatch/StopwatchFace.qml	2016-03-02 12:04:48 +0000
+++ app/stopwatch/StopwatchFace.qml	2016-03-03 12:07:39 +0000
@@ -35,6 +35,7 @@
 
     Label {
         id: time
+        objectName: "stopwatchTime"
 
         text: stopwatchFormatTime.millisToTimeString(milliseconds, true)
         font.pixelSize: units.dp(36)
@@ -44,6 +45,7 @@
 
     Label {
         id: miliseconds
+        objectName: "stopwatchMilliseconds"
 
         text: stopwatchFormatTime.millisToString(milliseconds)
         textSize: Label.Large

=== modified file 'app/stopwatch/StopwatchPage.qml'
--- app/stopwatch/StopwatchPage.qml	2016-02-25 22:16:54 +0000
+++ app/stopwatch/StopwatchPage.qml	2016-03-03 12:07:39 +0000
@@ -71,7 +71,8 @@
         }
 
         Button {
-            id: stopButton
+            id: startStopButton
+            objectName: "startAndStopButton"
 
             width: parent.width / 2 - units.gu(1)
             height: units.gu(4)
@@ -94,6 +95,7 @@
 
         Button {
             id: lapButton
+            objectName: "lapAndClearButton"
 
             text: stopwatchEngine.running ? i18n.tr("Lap") : i18n.tr("Clear")
             width: parent.width / 2 - units.gu(1)

=== modified file 'debian/changelog'
--- debian/changelog	2016-03-03 11:58:53 +0000
+++ debian/changelog	2016-03-03 12:07:39 +0000
@@ -4,6 +4,7 @@
   * Dynamic loading of ListView in ExpandableListItem
   * Removed all vertical positioning overrides of trailing icon in ListItem.
   * Fixed failing autopilot tests in trunk (LP: #1552489)
+  * Added Stopwatch autopilot tests (LP: #1490206)
 
  -- Nekhelesh <krnekhelesh@nik90-laptop>  Wed, 02 Mar 2016 19:30:48 +0100
 

=== modified file 'tests/autopilot/ubuntu_clock_app/__init__.py'
--- tests/autopilot/ubuntu_clock_app/__init__.py	2016-03-03 07:02:42 +0000
+++ tests/autopilot/ubuntu_clock_app/__init__.py	2016-03-03 12:07:39 +0000
@@ -20,7 +20,7 @@
 
 from autopilot import logging as autopilot_logging
 from autopilot.introspection import dbus
-from testtools.matchers import GreaterThan
+from testtools.matchers import (NotEquals, Equals, GreaterThan)
 
 from ubuntuuitoolkit import (
     MainView, UbuntuUIToolkitCustomProxyObjectBase, pickers, UCListItem)
@@ -83,6 +83,18 @@
         return self.wait_select_single("WorldCityList",
                                        objectName="worldCityList")
 
+    @autopilot_logging.log_action(logger.info)
+    def open_stopwatch(self):
+        """Open the Stopwatch Page.
+
+        :return: the Stopwatch Page.
+
+        """
+        mainPage = self.get_main_page()
+        mainPage.press_header_navigation_button(
+            'stopwatchNavigationButton')
+        return self.wait_select_single(StopwatchPage)
+
 
 class Page(UbuntuUIToolkitCustomProxyObjectBase):
     """Autopilot helper for Pages."""
@@ -120,6 +132,97 @@
             logger.error('BottomEdge element not found.')
             raise
 
+    def press_header_navigation_button(self, button_object_name):
+        """Press the passed custom navigation button
+
+        :param button_object_name: Object name of navigation button
+
+        """
+        navigation_button = self.wait_select_single(
+            'ActionIcon', objectName=button_object_name)
+        self.pointing_device.click_object(navigation_button)
+        page_list_view = self.wait_select_single(
+            'QQuickListView', objectName="pageListView")
+        page_list_view.isMoving.wait_for(False)
+
+
+class StopwatchPage(Page):
+    """Autopilot helper for the Stopwatch page."""
+
+    @autopilot_logging.log_action(logger.info)
+    def start_stopwatch(self):
+        self._click_start_stop_button()
+
+        try:
+            self._get_start_stop_button().text.wait_for("Stop")
+            self._get_lap_clear_button().text.wait_for("Lap")
+            self._get_stopwatch_time().text.wait_for(
+                NotEquals("00:00:00"))
+            self._get_stopwatch_milliseconds().text.wait_for(
+                NotEquals("000"))
+        except AssertionError:
+            raise ClockEmulatorException(
+                'Incorrect stopwatch run state')
+
+    @autopilot_logging.log_action(logger.info)
+    def stop_stopwatch(self):
+        self._click_start_stop_button()
+
+        try:
+            self._get_start_stop_button().text.wait_for("Resume")
+            self._get_lap_clear_button().text.wait_for("Clear")
+        except AssertionError:
+            raise ClockEmulatorException(
+                'Incorrect stopwatch pause state')
+
+    @autopilot_logging.log_action(logger.info)
+    def clear_stopwatch(self):
+        self._click_lap_clear_button()
+
+        try:
+            self._get_start_stop_button().text.wait_for("Start")
+            self._get_stopwatch_time().text.wait_for(
+                Equals("00:00:00"))
+            self._get_stopwatch_milliseconds().text.wait_for(
+                Equals("000"))
+        except AssertionError:
+            raise ClockEmulatorException(
+                'Invalid stopwatch clear state')
+
+    def _get_stopwatch_time(self):
+        """Return the stopwatch time object"""
+        stopwatch_time = self.wait_select_single(
+            "UCLabel", objectName="stopwatchTime")
+        return stopwatch_time
+
+    def _get_stopwatch_milliseconds(self):
+        """Return the stopwatch milliseconds object"""
+        stopwatch_milliseconds = self.wait_select_single(
+            "UCLabel", objectName="stopwatchMilliseconds")
+        return stopwatch_milliseconds
+
+    def _get_start_stop_button(self):
+        """Return the start/stop button"""
+        start_stop_button = self.wait_select_single(
+            "Button", objectName="startAndStopButton")
+        return start_stop_button
+
+    def _get_lap_clear_button(self):
+        """Return the lap/clear button"""
+        lap_clear_button = self.wait_select_single(
+            "Button", objectName="lapAndClearButton")
+        return lap_clear_button
+
+    def _click_start_stop_button(self):
+        """Press the start/stop button"""
+        start_stop_button = self._get_start_stop_button()
+        self.pointing_device.click_object(start_stop_button)
+
+    def _click_lap_clear_button(self):
+        """Press the lap/clear button"""
+        lap_clear_button = self._get_lap_clear_button()
+        self.pointing_device.click_object(lap_clear_button)
+
 
 class ClockPage(Page):
     """Autopilot helper for the Clock page."""

=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_alarm.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_alarm.py	2016-03-03 07:02:42 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_alarm.py	2016-03-03 12:07:39 +0000
@@ -22,12 +22,13 @@
 
 from autopilot.matchers import Eventually
 from testtools.matchers import Equals
+
 from ubuntu_clock_app.tests import ClockAppTestCase
 
 
 class TestAlarm(ClockAppTestCase):
-
     """Tests the alarm page features"""
+
     scenarios = [
         ('random',
             {'alarm_name': 'Random days Alarm Test',
@@ -55,7 +56,7 @@
     ]
 
     def setUp(self):
-        """ This is needed to wait for the application to start.
+        """This is needed to wait for the application to start.
 
         In the testfarm, the application may take some time to show up.
 

=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_clock.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_clock.py	2016-03-03 00:28:40 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_clock.py	2016-03-03 12:07:39 +0000
@@ -27,7 +27,6 @@
 
 
 class TestClock(ClockAppTestCase):
-
     """Test the clock page features."""
 
     def setUp(self):

=== added file 'tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py	1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py	2016-03-03 12:07:39 +0000
@@ -0,0 +1,50 @@
+# Copyright (C) 2016 Canonical Ltd
+#
+# This file is part of Ubuntu Clock App
+#
+# Ubuntu Clock App is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Ubuntu Clock App is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Tests for the Clock App, stopwatch page.
+"""
+
+from __future__ import absolute_import
+
+from autopilot.matchers import Eventually
+from testtools.matchers import Equals
+
+from ubuntu_clock_app.tests import ClockAppTestCase
+
+
+class TestStopwatch(ClockAppTestCase):
+    """Tests the stopwatch feature"""
+
+    def setUp(self):
+        """This is needed to wait for the application to start.
+
+        In the testfarm, the application may take some time to show up.
+
+        """
+        super(TestStopwatch, self).setUp()
+        self.assertThat(
+            self.app.main_view.visible, Eventually(Equals(True)))
+
+        self.page = self.app.main_view.open_stopwatch()
+
+    def test_pressing_start_stop_button_starts_stops_stopwatch(self):
+        """Test to check if stopwatch can be started and stopped using
+        the UI buttons"""
+
+        self.page.start_stopwatch()
+        self.page.stop_stopwatch()
+        self.page.clear_stopwatch()


Follow ups