Merge lp:~elopio/ubuntu-ui-toolkit/datepicker-autopilot_helper into lp:ubuntu-ui-toolkit/staging

Proposed by Leo Arias
Status: Merged
Approved by: Cris Dywan
Approved revision: 1049
Merged at revision: 1064
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/datepicker-autopilot_helper
Merge into: lp:ubuntu-ui-toolkit/staging
Prerequisite: lp:~elopio/ubuntu-ui-toolkit/swipe_into_view
Diff against target: 611 lines (+419/-37)
9 files modified
modules/Ubuntu/Components/Pickers/DatePicker.qml (+3/-5)
modules/Ubuntu/Components/Pickers/PickerRow.qml (+1/-1)
tests/autopilot/ubuntuuitoolkit/__init__.py (+2/-0)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py (+2/-0)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py (+30/-20)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py (+27/-10)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/pickers.py (+206/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_date_picker.py (+147/-0)
tests/unit_x11/tst_components/tst_datepicker.qml (+1/-1)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/datepicker-autopilot_helper
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Allan LeSage Pending
Review via email: mp+218909@code.launchpad.net

This proposal supersedes a proposal from 2014-05-07.

Commit message

Added autopilot helpers to pick a date from a date picker.

Description of the change

Next branch will add support for picking a time.

To post a comment you must log in.
Revision history for this message
Allan LeSage (allanlesage) wrote : Posted in a previous version of this proposal

Ok I think understand this change, appears thoroughly tested, nice work :) . I'm assuming that the comment on l.535 doesn't apply to the present merge proposal.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote : Posted in a previous version of this proposal

> Ok I think understand this change, appears thoroughly tested, nice work :) .
> I'm assuming that the comment on l.535 doesn't apply to the present merge
> proposal.

It does. I was just trying to test it the wrong way. Now I added a couple of tests for that.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

8 - Qt.formatDate(datePicker.date, "dddd, dd-mmmm-yyyy")
9 + Qt.formatDate(datePicker.date, "dddd, dd-MMMM-yyyy")

Why is this change needed?

It looks overall nice.

review: Needs Information
Revision history for this message
Leo Arias (elopio) wrote :

that's because there's no such thing as mmmm. http://qt-project.org/doc/qt-5/qml-qtqml-date.html
the example doesn't work.

Revision history for this message
Cris Dywan (kalikiana) wrote :

Nice catch! Thanks

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

FAIL! : tst_UCAlarms::test_updateAlarm_Repeating() 'containsAlarm(&alarm)' returned FALSE. ()
   Loc: [tst_alarms.cpp(356)]

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1046
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/235/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/269
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/244
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/67
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/67
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/67/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/67
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/757
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/549
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/549/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7254
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/220
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/308
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/308/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/235/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-autolanding/93/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/318
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/283
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-autolanding/37
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-autolanding/37
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-autolanding/37/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-autolanding/37
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/798
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/629
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/629/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7339
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/255
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/357
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/357/artifact/work/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1047
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/247/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/322
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/287
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/79
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/79
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/79/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/79
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/801
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/635
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/635/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7346
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/257
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/362
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/362/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/247/rebuild

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1049
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/252/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/335
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/296
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/84
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/84
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/84/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/84
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/812
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/665
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/665/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7376
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/263
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/372
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/372/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/252/rebuild

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

FAIL! : tst_UCAlarms::test_updateAlarm_Repeating() 'containsAlarm(&alarm)' returned FALSE. ()
   Loc: [tst_alarms.cpp(356)]

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/Pickers/DatePicker.qml'
--- modules/Ubuntu/Components/Pickers/DatePicker.qml 2014-04-23 08:50:20 +0000
+++ modules/Ubuntu/Components/Pickers/DatePicker.qml 2014-05-20 07:32:50 +0000
@@ -42,7 +42,7 @@
42 Column {42 Column {
43 Label {43 Label {
44 text: "Selected date: W" + datePicker.week + " - " +44 text: "Selected date: W" + datePicker.week + " - " +
45 Qt.formatDate(datePicker.date, "dddd, dd-mmmm-yyyy")45 Qt.formatDate(datePicker.date, "dddd, dd-MMMM-yyyy")
46 }46 }
47 DatePicker {47 DatePicker {
48 id: datePicker48 id: datePicker
@@ -61,7 +61,7 @@
6161
62 Column {62 Column {
63 Label {63 Label {
64 text: "Selected month: " + Qt.formatDate(datePicker.date, "mmmm-yyyy")64 text: "Selected month: " + Qt.formatDate(datePicker.date, "MMMM-yyyy")
65 }65 }
66 DatePicker {66 DatePicker {
67 id: datePicker67 id: datePicker
@@ -117,7 +117,7 @@
117117
118 Column {118 Column {
119 Label {119 Label {
120 text: "Selected date: " + Qt.formatDate(datePicker.date, "dddd, dd-mmmm-yyyy")120 text: "Selected date: " + Qt.formatDate(datePicker.date, "dddd, dd-MMMM-yyyy")
121 }121 }
122 DatePicker {122 DatePicker {
123 id: datePicker123 id: datePicker
@@ -667,5 +667,3 @@
667 }667 }
668 }668 }
669}669}
670
671
672670
=== modified file 'modules/Ubuntu/Components/Pickers/PickerRow.qml'
--- modules/Ubuntu/Components/Pickers/PickerRow.qml 2014-04-23 08:50:20 +0000
+++ modules/Ubuntu/Components/Pickers/PickerRow.qml 2014-05-20 07:32:50 +0000
@@ -96,7 +96,7 @@
96 }96 }
97 delegate: PickerDelegate {97 delegate: PickerDelegate {
98 Label {98 Label {
99 objectName: "PickerRow_PickerLabel"99 objectName: "PickerRow_PickerLabel" + (pickerModel ? modelData : "")
100 text: pickerModel ? pickerModel.text(modelData) : ""100 text: pickerModel ? pickerModel.text(modelData) : ""
101 anchors.fill: parent101 anchors.fill: parent
102 verticalAlignment: Text.AlignVCenter102 verticalAlignment: Text.AlignVCenter
103103
=== modified file 'tests/autopilot/ubuntuuitoolkit/__init__.py'
--- tests/autopilot/ubuntuuitoolkit/__init__.py 2014-04-30 00:46:11 +0000
+++ tests/autopilot/ubuntuuitoolkit/__init__.py 2014-05-20 07:32:50 +0000
@@ -30,6 +30,7 @@
30 'listitems',30 'listitems',
31 'MainView',31 'MainView',
32 'OptionSelector',32 'OptionSelector',
33 'pickers',
33 'popups',34 'popups',
34 'QQuickFlickable',35 'QQuickFlickable',
35 'QQuickListView',36 'QQuickListView',
@@ -59,6 +60,7 @@
59 listitems,60 listitems,
60 MainView,61 MainView,
61 OptionSelector,62 OptionSelector,
63 pickers,
62 popups,64 popups,
63 QQuickFlickable,65 QQuickFlickable,
64 QQuickListView,66 QQuickListView,
6567
=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py'
--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2014-04-30 00:46:11 +0000
+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2014-05-20 07:32:50 +0000
@@ -26,6 +26,7 @@
26 'listitems',26 'listitems',
27 'MainView',27 'MainView',
28 'OptionSelector',28 'OptionSelector',
29 'pickers',
29 'popups',30 'popups',
30 'QQuickFlickable',31 'QQuickFlickable',
31 'QQuickListView',32 'QQuickListView',
@@ -52,6 +53,7 @@
52from ubuntuuitoolkit._custom_proxy_objects._optionselector import (53from ubuntuuitoolkit._custom_proxy_objects._optionselector import (
53 OptionSelector54 OptionSelector
54)55)
56from ubuntuuitoolkit._custom_proxy_objects import pickers
55from ubuntuuitoolkit._custom_proxy_objects import popups57from ubuntuuitoolkit._custom_proxy_objects import popups
56from ubuntuuitoolkit._custom_proxy_objects._qquicklistview import (58from ubuntuuitoolkit._custom_proxy_objects._qquicklistview import (
57 QQuickListView59 QQuickListView
5860
=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py'
--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-04-30 00:46:11 +0000
+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-05-20 07:32:50 +0000
@@ -38,21 +38,7 @@
38 return min(containers_bottom)38 return min(containers_bottom)
3939
4040
41class QQuickFlickable(_common.UbuntuUIToolkitCustomProxyObjectBase):41class Scrollable(_common.UbuntuUIToolkitCustomProxyObjectBase):
42
43 @autopilot_logging.log_action(logger.info)
44 def swipe_child_into_view(self, child):
45 """Make the child visible.
46
47 Currently it works only when the object needs to be swiped vertically.
48 TODO implement horizontal swiping. --elopio - 2014-03-21
49
50 """
51 containers = self._get_containers()
52 if not self._is_child_visible(child, containers):
53 self._swipe_non_visible_child_into_view(child, containers)
54 else:
55 logger.debug('The element is already visible.')
5642
57 def _get_containers(self):43 def _get_containers(self):
58 """Return a list with the containers to take into account when swiping.44 """Return a list with the containers to take into account when swiping.
@@ -94,6 +80,35 @@
94 return (object_center >= visible_top and80 return (object_center >= visible_top and
95 object_center <= visible_bottom)81 object_center <= visible_bottom)
9682
83 def _slow_drag(self, start_x, stop_x, start_y, stop_y):
84 # If we drag too fast, we end up scrolling more than what we
85 # should, sometimes missing the element we are looking for.
86 # I found that when the flickDeceleration is 1500, the rate should be
87 # 5 and that when it's 100, the rate should be 1. With those two points
88 # we can get that the following equation.
89 # XXX The deceleration might not be linear with respect to the rate,
90 # but this works for the two types of scrollables we have for now.
91 # --elopio - 2014-05-08
92 rate = (self.flickDeceleration + 250) / 350
93 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate=rate)
94
95
96class QQuickFlickable(Scrollable):
97
98 @autopilot_logging.log_action(logger.info)
99 def swipe_child_into_view(self, child):
100 """Make the child visible.
101
102 Currently it works only when the object needs to be swiped vertically.
103 TODO implement horizontal swiping. --elopio - 2014-03-21
104
105 """
106 containers = self._get_containers()
107 if not self._is_child_visible(child, containers):
108 self._swipe_non_visible_child_into_view(child, containers)
109 else:
110 logger.debug('The element is already visible.')
111
97 @autopilot_logging.log_action(logger.info)112 @autopilot_logging.log_action(logger.info)
98 def _swipe_non_visible_child_into_view(self, child, containers):113 def _swipe_non_visible_child_into_view(self, child, containers):
99 original_content_y = self.contentY114 original_content_y = self.contentY
@@ -150,11 +165,6 @@
150 self.dragging.wait_for(False)165 self.dragging.wait_for(False)
151 self.moving.wait_for(False)166 self.moving.wait_for(False)
152167
153 def _slow_drag(self, start_x, stop_x, start_y, stop_y):
154 # If we drag too fast, we end up scrolling more than what we
155 # should, sometimes missing the element we are looking for.
156 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate=5)
157
158 @autopilot_logging.log_action(logger.info)168 @autopilot_logging.log_action(logger.info)
159 def _scroll_to_top(self):169 def _scroll_to_top(self):
160 if not self.atYBeginning:170 if not self.atYBeginning:
161171
=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py'
--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py 2014-04-30 00:46:11 +0000
+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py 2014-05-20 07:32:50 +0000
@@ -19,9 +19,7 @@
19from autopilot import logging as autopilot_logging19from autopilot import logging as autopilot_logging
20from autopilot.introspection import dbus20from autopilot.introspection import dbus
2121
22from ubuntuuitoolkit._custom_proxy_objects import _flickable22from ubuntuuitoolkit._custom_proxy_objects import _common, _flickable
23from ubuntuuitoolkit._custom_proxy_objects import _common
24
2523
26logger = logging.getLogger(__name__)24logger = logging.getLogger(__name__)
2725
@@ -29,12 +27,16 @@
29class QQuickListView(_flickable.QQuickFlickable):27class QQuickListView(_flickable.QQuickFlickable):
3028
31 @autopilot_logging.log_action(logger.info)29 @autopilot_logging.log_action(logger.info)
32 def click_element(self, object_name):30 def click_element(self, object_name, direction=None):
33 """Click an element from the list.31 """Click an element from the list.
3432
35 It swipes the element into view if it's center is not visible.33 It swipes the element into view if it's center is not visible.
3634
37 :parameter objectName: The objectName property of the element to click.35 :parameter objectName: The objectName property of the element to click.
36 :parameter direction: The direction where the element is, it can be
37 either 'above' or 'below'. Default value is None, which means we
38 don't know where the object is and we will need to search the full
39 list.
3840
39 """41 """
40 try:42 try:
@@ -42,16 +44,31 @@
42 except dbus.StateNotFoundError:44 except dbus.StateNotFoundError:
43 # The element might be on a part of the list that hasn't been45 # The element might be on a part of the list that hasn't been
44 # created yet. We have to search for it scrolling the entire list.46 # created yet. We have to search for it scrolling the entire list.
45 element = self._find_element(object_name)47 element = self._find_element(object_name, direction)
46 self.swipe_child_into_view(element)48 self.swipe_child_into_view(element)
47 self.pointing_device.click_object(element)49 self.pointing_device.click_object(element)
4850
49 @autopilot_logging.log_action(logger.info)51 @autopilot_logging.log_action(logger.info)
50 def _find_element(self, object_name):52 def _find_element(self, object_name, direction=None):
51 self._scroll_to_top()53 if direction is None:
52 while not self.atYEnd:54 # We don't know where the object is so we start looking for it from
53 containers = self._get_containers()55 # the top.
54 self._swipe_to_show_more_below(containers)56 self._scroll_to_top()
57 direction = 'below'
58
59 if direction == 'below':
60 fail_condition = lambda: self.atYEnd
61 swipe_method = self._swipe_to_show_more_below
62 elif direction == 'above':
63 fail_condition = lambda: self.atYBeginning
64 swipe_method = self._swipe_to_show_more_above
65 else:
66 raise _common.ToolkitException(
67 'Invalid direction: {}'.format(direction))
68
69 containers = self._get_containers()
70 while not fail_condition():
71 swipe_method(containers)
55 try:72 try:
56 return self.select_single(objectName=object_name)73 return self.select_single(objectName=object_name)
57 except dbus.StateNotFoundError:74 except dbus.StateNotFoundError:
5875
=== added file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/pickers.py'
--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/pickers.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/pickers.py 2014-05-20 07:32:50 +0000
@@ -0,0 +1,206 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import datetime
18import logging
19
20from autopilot import logging as autopilot_logging
21from autopilot.introspection import dbus
22
23from ubuntuuitoolkit._custom_proxy_objects import (
24 _common,
25 _flickable,
26 _qquicklistview
27)
28
29
30logger = logging.getLogger(__name__)
31
32
33class DatePicker(_common.UbuntuUIToolkitCustomProxyObjectBase):
34 """Autopilot helper for the DatePicker component."""
35
36 @autopilot_logging.log_action(logger.info)
37 def pick_date(self, date):
38 """Pick a date from the date picker.
39
40 :parameter date: The date to pick.
41 :type date: An object with year, month and day attributes, like
42 python's datetime.date.
43 :raises ubuntuuitoolkit.ToolkitException if the mode of the picker
44 doesn't let select a date.
45
46 """
47 if not self._is_date_picker():
48 raise _common.ToolkitException(
49 "Can't pick date. The picker mode is: {!r}.".format(self.mode))
50 if 'Years' in self.mode:
51 self._pick_year(date.year)
52 self.year.wait_for(date.year)
53 if 'Month' in self.mode:
54 # Python's date object starts at one. The model in the date picker
55 # at 0.
56 self._pick_month(date.month - 1)
57 self.month.wait_for(date.month - 1)
58 if 'Day' in self.mode:
59 self._pick_day(date.day)
60 self.day.wait_for(date.day)
61
62 def _is_date_picker(self):
63 mode = self.mode
64 if 'Years' in mode or 'Months' in mode or 'Days' in mode:
65 return True
66 else:
67 return False
68
69 @autopilot_logging.log_action(logger.info)
70 def _pick_year(self, year):
71 picker = self.select_single(
72 'Picker', objectName='PickerRow_YearPicker')
73 list_view = picker.select_single(
74 _qquicklistview.QQuickListView, objectName='Picker_Linear')
75 self._pick_date_value(self.year, year, list_view)
76
77 @autopilot_logging.log_action(logger.info)
78 def _pick_month(self, month):
79 picker = self.select_single(
80 'Picker', objectName='PickerRow_MonthPicker')
81 path_view = picker.select_single(
82 QQuickPathView, objectName='Picker_WrapAround')
83 self._pick_date_value(self.month, month, path_view)
84
85 @autopilot_logging.log_action(logger.info)
86 def _pick_day(self, day):
87 picker = self.select_single(
88 'Picker', objectName='PickerRow_DayPicker')
89 path_view = picker.select_single(
90 QQuickPathView, objectName='Picker_WrapAround')
91 # Python's date object starts at one. The model in the date picker
92 # at 0.
93 self._pick_date_value(self.get_date().day - 1, day - 1, path_view)
94
95 def _pick_date_value(self, current_value, new_value, scrollable):
96 if new_value > current_value:
97 direction = 'below'
98 elif new_value < current_value:
99 direction = 'above'
100 else:
101 logger.debug('The value is already selected.')
102 return
103 scrollable.click_element(
104 object_name='PickerRow_PickerLabel{}'.format(new_value),
105 direction=direction)
106
107 def get_date(self):
108 """Return the currently selected date.
109
110 :return: a python datetime.date object with the selected date.
111
112 """
113 # Python's date object starts at one. The model in the date picker
114 # at 0.
115 return datetime.date(
116 self.year, self.month + 1, self.day)
117
118
119class QQuickPathView(_flickable.Scrollable):
120
121 # TODO make it more general and move it to its own module.
122 # --elopio - 2014-05-06
123
124 @autopilot_logging.log_action(logger.info)
125 def click_element(self, object_name, direction='below'):
126 try:
127 element = self.select_single(objectName=object_name)
128 except dbus.StateNotFoundError:
129 # The element might be on a part of the list that hasn't been
130 # created yet. We have to search for it scrolling.
131 element = self._find_element(object_name, direction)
132 self.swipe_child_into_view(element)
133 self.pointing_device.click_object(element)
134
135 @autopilot_logging.log_action(logger.info)
136 def _find_element(self, object_name, direction):
137 containers = self._get_containers()
138 for index in range(self.count):
139 if direction == 'below':
140 swipe_method = self._swipe_to_show_one_more_below
141 elif direction == 'above':
142 swipe_method = self._swipe_to_show_one_more_above
143 else:
144 raise _common.ToolkitException(
145 'Invalid direction: {}'.format(direction))
146
147 swipe_method(containers)
148
149 try:
150 return self.select_single(objectName=object_name)
151 except dbus.StateNotFoundError:
152 pass
153 raise _common.ToolkitException(
154 'List element with objectName "{}" not found.'.format(object_name))
155
156 @autopilot_logging.log_action(logger.info)
157 def _swipe_to_show_one_more_above(self, containers):
158 self._swipe_to_show_one_more('above', containers)
159
160 @autopilot_logging.log_action(logger.info)
161 def _swipe_to_show_one_more_below(self, containers):
162 self._swipe_to_show_one_more('below', containers)
163
164 def _swipe_to_show_one_more(self, direction, containers):
165 start_x = stop_x = self.globalRect.x + (self.globalRect.width // 2)
166 center_y = self.globalRect.y + (self.globalRect.height // 2)
167 # XXX This assumes all the children are of the same height
168 child = self.get_children_by_type('PickerDelegate')[0]
169 top = center_y - (child.globalRect.height // 2)
170 bottom = center_y + (child.globalRect.height // 2)
171 if direction == 'below':
172 start_y = bottom
173 stop_y = top
174 elif direction == 'above':
175 start_y = top
176 stop_y = bottom
177 else:
178 raise _common.ToolkitException(
179 'Invalid direction {}.'.format(direction))
180 self._slow_drag(start_x, stop_x, start_y, stop_y)
181 self.dragging.wait_for(False)
182 self.moving.wait_for(False)
183
184 @autopilot_logging.log_action(logger.info)
185 def swipe_child_into_view(self, child):
186 """Make the child visible.
187
188 Currently it works only when the object needs to be swiped vertically.
189 TODO implement horizontal swiping. --elopio - 2014-03-21
190
191 """
192 containers = self._get_containers()
193 if not self._is_child_visible(child, containers):
194 self._swipe_non_visible_child_into_view(child, containers)
195 else:
196 logger.debug('The element is already visible.')
197
198 @autopilot_logging.log_action(logger.info)
199 def _swipe_non_visible_child_into_view(self, child, containers):
200 while not self._is_child_visible(child, containers):
201 # Check the direction of the swipe based on the position of the
202 # child relative to the immediate flickable container.
203 if child.globalRect.y < self.globalRect.y:
204 self._swipe_to_show_one_more_above(containers)
205 else:
206 self._swipe_to_show_one_more_below(containers)
0207
=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_date_picker.py'
--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_date_picker.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_date_picker.py 2014-05-20 07:32:50 +0000
@@ -0,0 +1,147 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import datetime
18
19import ubuntuuitoolkit
20from ubuntuuitoolkit import pickers, tests
21
22
23class DatePickerBaseTestCase(tests.QMLStringAppTestCase):
24
25 test_qml = ("""
26import QtQuick 2.0
27import Ubuntu.Components 1.1
28import Ubuntu.Components.Pickers 1.0
29
30MainView {
31 width: units.gu(48)
32 height: units.gu(60)
33
34 Column {
35 DatePicker {
36 id: datePicker
37 objectName: 'datePicker'
38 mode: 'Years|Months|Days'
39 date: {
40 var d = new Date()
41 // Make sure that the picker will have higher and lower values
42 // to select.
43 d.setFullYear(d.getFullYear() + 25)
44 d.setMonth('5')
45 d.setDate('15')
46 return d
47 }
48 }
49 DatePicker {
50 id: timePicker
51 objectName: 'timePicker'
52 mode: 'Hours|Minutes|Seconds'
53 }
54 }
55}
56""")
57
58 def setUp(self):
59 super(DatePickerBaseTestCase, self).setUp()
60 self.date_picker = self.main_view.select_single(
61 pickers.DatePicker, objectName='datePicker')
62
63
64class DatePickerTestCase(DatePickerBaseTestCase):
65
66 def test_select_date_picker_must_return_custom_proxy_object(self):
67 self.assertIsInstance(
68 self.date_picker, pickers.DatePicker)
69
70 def test_pick_date_on_time_picker_must_raise_exception(self):
71 time_picker = self.main_view.select_single(
72 pickers.DatePicker, objectName='timePicker')
73 error = self.assertRaises(
74 ubuntuuitoolkit.ToolkitException, time_picker.pick_date, 'dummy')
75 self.assertEqual(
76 str(error),
77 "Can't pick date. The picker mode is: {!r}.".format(
78 time_picker.mode))
79
80 def test_swipe_to_show_one_more_below_must_select_next_index(self):
81 """Test that we don't end up swiping more than needed.
82
83 This would cause us to miss the element we are looking for, and to have
84 to swipe many times in order to finally click it.
85
86 """
87 picker = self.main_view.select_single(
88 'Picker', objectName='PickerRow_DayPicker')
89 path_view = picker.select_single(
90 pickers.QQuickPathView, objectName='Picker_WrapAround')
91 current_index = path_view.currentIndex
92
93 path_view._swipe_to_show_one_more_below(path_view._get_containers())
94
95 self.assertEqual(path_view.currentIndex, current_index + 1)
96
97 def test_swipe_to_show_one_more_above_must_select_previous_index(self):
98 """Test that we don't end up swiping more than needed.
99
100 This would cause us to miss the element we are looking for, and to have
101 to swipe many times in order to finally click it.
102
103 """
104 picker = self.main_view.select_single(
105 'Picker', objectName='PickerRow_DayPicker')
106 path_view = picker.select_single(
107 pickers.QQuickPathView, objectName='Picker_WrapAround')
108 current_index = path_view.currentIndex
109
110 path_view._swipe_to_show_one_more_above(path_view._get_containers())
111
112 self.assertEqual(path_view.currentIndex, current_index - 1)
113
114
115class PickDateFromDatePickerTestCase(DatePickerBaseTestCase):
116
117 SELECTED_YEAR = datetime.date.today().year + 25
118 SELECTED_MONTH = 6 # June
119 SELECTED_DAY = 15
120
121 scenarios = [
122 ('higher year', {
123 'date_to_pick': datetime.date(
124 SELECTED_YEAR + 10, SELECTED_MONTH, SELECTED_DAY)}),
125 ('lower year', {
126 'date_to_pick': datetime.date(
127 SELECTED_YEAR - 10, SELECTED_MONTH, SELECTED_DAY)}),
128 ('higher month', {
129 'date_to_pick': datetime.date(
130 SELECTED_YEAR, SELECTED_MONTH + 4, SELECTED_DAY)}),
131 ('lower month', {
132 'date_to_pick': datetime.date(
133 SELECTED_YEAR, SELECTED_MONTH - 4, SELECTED_DAY)}),
134 ('higher day', {
135 'date_to_pick': datetime.date(
136 SELECTED_YEAR, SELECTED_MONTH, SELECTED_DAY + 10)}),
137 ('lower day', {
138 'date_to_pick': datetime.date(
139 SELECTED_YEAR, SELECTED_MONTH, SELECTED_DAY - 10)}),
140 ('change all value', {
141 'date_to_pick': datetime.date(
142 SELECTED_YEAR - 10, SELECTED_MONTH + 4, SELECTED_DAY - 10)}),
143 ]
144
145 def test_pick_date(self):
146 self.date_picker.pick_date(self.date_to_pick)
147 self.assertEqual(self.date_picker.get_date(), self.date_to_pick)
0148
=== modified file 'tests/unit_x11/tst_components/tst_datepicker.qml'
--- tests/unit_x11/tst_components/tst_datepicker.qml 2014-05-05 17:45:45 +0000
+++ tests/unit_x11/tst_components/tst_datepicker.qml 2014-05-20 07:32:50 +0000
@@ -59,7 +59,7 @@
59 function getPickerLabel(picker, name) {59 function getPickerLabel(picker, name) {
60 var pickerItem = findChild(picker, name);60 var pickerItem = findChild(picker, name);
61 var pickerCurrent = findChild(pickerItem, "Picker_ViewLoader");61 var pickerCurrent = findChild(pickerItem, "Picker_ViewLoader");
62 return findChild(pickerCurrent.item.currentItem, "PickerRow_PickerLabel");62 return pickerCurrent.item.currentItem.children[2];
63 }63 }
64 function getPickerModel(picker, name) {64 function getPickerModel(picker, name) {
65 var pickerItem = findInvisibleChild(picker, name);65 var pickerItem = findInvisibleChild(picker, name);

Subscribers

People subscribed via source and target branches