Merge lp:~elopio/ubuntu-ui-toolkit/pullToRefresh-test1 into lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/pullToRefresh

Proposed by Leo Arias
Status: Merged
Merged at revision: 946
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/pullToRefresh-test1
Merge into: lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/pullToRefresh
Diff against target: 235 lines (+194/-2)
4 files modified
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py (+41/-1)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py (+1/-1)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.py (+50/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.qml (+102/-0)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/pullToRefresh-test1
Reviewer Review Type Date Requested Status
Zsombor Egri Approve
Julia Palandri (community) Approve
Review via email: mp+220439@code.launchpad.net

Commit message

Added a test for the pull to refresh with autopilot.

To post a comment you must log in.
944. By Leo Arias

Fixed identation.

945. By Leo Arias

Added the missing files.

Revision history for this message
Julia Palandri (julia-palandri) wrote :

Looks good as far as I can tell; please have someone else to review it as well.

review: Approve
Revision history for this message
Zsombor Egri (zsombi) wrote :

All good, thx!!!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py'
2--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-04-30 00:46:11 +0000
3+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-05-21 12:15:40 +0000
4@@ -16,6 +16,7 @@
5
6 import logging
7
8+import autopilot.exceptions
9 from autopilot import logging as autopilot_logging
10
11 from ubuntuuitoolkit._custom_proxy_objects import _common
12@@ -156,8 +157,47 @@
13 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate=5)
14
15 @autopilot_logging.log_action(logger.info)
16- def _scroll_to_top(self):
17+ def _swipe_to_top(self):
18 if not self.atYBeginning:
19 containers = self._get_containers()
20 while not self.atYBeginning:
21 self._swipe_to_show_more_above(containers)
22+
23+ @autopilot_logging.log_action(logger.info)
24+ def pull_to_refresh(self):
25+ """Pulls the flickable down and triggers a refresh on it.
26+
27+ :raises ubuntuuitoolkit.ToolkitException: If the flickable has no pull
28+ to release functionality.
29+
30+ """
31+ try:
32+ pull_to_refresh = self.select_single(PullToRefresh)
33+ except autopilot.exceptions.StateNotFoundError:
34+ raise _common.ToolkitException(
35+ 'The flickable has no pull to refresh functionality.')
36+ self._swipe_to_top()
37+ self._swipe_to_middle()
38+ pull_to_refresh.wait_for_refresh()
39+
40+ @autopilot_logging.log_action(logger.info)
41+ def _swipe_to_middle(self):
42+ start_x = stop_x = self.globalRect.x + (self.globalRect.width // 2)
43+ # Start and stop just a little under the top.
44+ containers = self._get_containers()
45+ top = _get_visible_container_top(containers) + 5
46+ bottom = _get_visible_container_bottom(containers)
47+
48+ start_y = top
49+ stop_y = bottom // 2
50+ self._slow_drag(start_x, stop_x, start_y, stop_y)
51+ self.dragging.wait_for(False)
52+ self.moving.wait_for(False)
53+
54+
55+class PullToRefresh(_common.UbuntuUIToolkitCustomProxyObjectBase):
56+ """Autopilot helper for the PullToRefresh component."""
57+
58+ def wait_for_refresh(self):
59+ activity_indicator = self.select_single('ActivityIndicator')
60+ activity_indicator.running.wait_for(False)
61
62=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py'
63--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py 2014-04-30 00:46:11 +0000
64+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_qquicklistview.py 2014-05-21 12:15:40 +0000
65@@ -48,7 +48,7 @@
66
67 @autopilot_logging.log_action(logger.info)
68 def _find_element(self, object_name):
69- self._scroll_to_top()
70+ self._swipe_to_top()
71 while not self.atYEnd:
72 containers = self._get_containers()
73 self._swipe_to_show_more_below(containers)
74
75=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.py'
76--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.py 1970-01-01 00:00:00 +0000
77+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.py 2014-05-21 12:15:40 +0000
78@@ -0,0 +1,50 @@
79+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
80+#
81+# Copyright (C) 2014 Canonical Ltd.
82+#
83+# This program is free software; you can redistribute it and/or modify
84+# it under the terms of the GNU Lesser General Public License as published by
85+# the Free Software Foundation; version 3.
86+#
87+# This program is distributed in the hope that it will be useful,
88+# but WITHOUT ANY WARRANTY; without even the implied warranty of
89+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+# GNU Lesser General Public License for more details.
91+#
92+# You should have received a copy of the GNU Lesser General Public License
93+# along with this program. If not, see <http://www.gnu.org/licenses/>.
94+
95+import os
96+
97+import ubuntuuitoolkit
98+from ubuntuuitoolkit import tests
99+
100+
101+class PullToRefreshTestCase(tests.QMLFileAppTestCase):
102+
103+ path = os.path.abspath(__file__)
104+ dir_path = os.path.dirname(path)
105+ test_qml_file_path = os.path.join(dir_path, 'test_pull_to_refresh.qml')
106+
107+ def setUp(self):
108+ super(PullToRefreshTestCase, self).setUp()
109+ self.label = self.main_view.select_single(
110+ 'Label', objectName='refreshedLabel')
111+ self.assertEqual(self.label.text, 'Not refreshed.')
112+
113+ def test_pull_to_refresh_on_a_flickable_without_it_must_raise_error(self):
114+ flickable = self.main_view.select_single(
115+ ubuntuuitoolkit.QQuickFlickable,
116+ objectName='flickableWithoutPullToRefresh')
117+ error = self.assertRaises(
118+ ubuntuuitoolkit.ToolkitException, flickable.pull_to_refresh)
119+ self.assertEqual(
120+ str(error), 'The flickable has no pull to refresh functionality.')
121+
122+ def test_pull_to_refresh_must_refresh_model(self):
123+ flickable = self.main_view.select_single(
124+ ubuntuuitoolkit.QQuickFlickable,
125+ objectName='flickableWithPullToRefresh')
126+ flickable.pull_to_refresh()
127+
128+ self.assertEqual(self.label.text, 'Refreshed.')
129
130=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.qml'
131--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.qml 1970-01-01 00:00:00 +0000
132+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_pull_to_refresh.qml 2014-05-21 12:15:40 +0000
133@@ -0,0 +1,102 @@
134+/*
135+ * Copyright 2014 Canonical Ltd.
136+ *
137+ * This program is free software; you can redistribute it and/or modify
138+ * it under the terms of the GNU Lesser General Public License as published by
139+ * the Free Software Foundation; version 3.
140+ *
141+ * This program is distributed in the hope that it will be useful,
142+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
143+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144+ * GNU Lesser General Public License for more details.
145+ *
146+ * You should have received a copy of the GNU Lesser General Public License
147+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
148+ */
149+
150+import QtQuick 2.0
151+import Ubuntu.Components 1.1
152+import Ubuntu.Components.ListItems 1.0 as ListItem
153+
154+MainView {
155+ id: root
156+ width: units.gu(48)
157+ height: units.gu(60)
158+
159+ ListModel {
160+ id: listModel
161+ property bool refreshing: refreshComplete.running
162+
163+ function modelData(index) {
164+ return {'name': 'line #' + index}
165+ }
166+
167+ function reload() {
168+ refreshComplete.restart();
169+ refreshedLabel.text = 'Refreshed.'
170+ }
171+
172+ function fillModel() {
173+ clear();
174+ for (var i = 0; i < 50; i++) {
175+ append(modelData(i));
176+ }
177+ }
178+
179+ Component.onCompleted: fillModel()
180+ }
181+
182+ Timer {
183+ id: refreshComplete
184+ interval: 1000
185+ onTriggered: {
186+ listModel.fillModel();
187+ }
188+ }
189+
190+ Column {
191+
192+ anchors.fill: parent
193+ Label {
194+ id: refreshedLabel
195+ objectName: 'refreshedLabel'
196+ text: 'Not refreshed.'
197+ }
198+
199+ Flickable {
200+ id: view
201+ objectName: 'flickableWithPullToRefresh'
202+ width: parent.width
203+ height: parent.height - refreshedLabel.paintedHeight
204+ clip: true
205+ contentWidth: column.childrenRect.width
206+ contentHeight: column.childrenRect.height
207+ Column {
208+ id: column
209+ Repeater {
210+ model: listModel
211+ ListItem.Standard {
212+ width: root.width
213+ height: units.gu(5)
214+ text: index + ' - ' + modelData
215+ onClicked: {
216+ listModel.reload();
217+ }
218+ }
219+ }
220+ }
221+
222+ PullToRefresh {
223+ id: pullToRefresh
224+ objectName: 'InFlickable'
225+ parent: view
226+ refreshing: listModel.refreshing
227+ onRefresh: listModel.reload()
228+ }
229+ }
230+
231+ Flickable {
232+ objectName: 'flickableWithoutPullToRefresh'
233+ }
234+ }
235+}

Subscribers

People subscribed via source and target branches

to all changes: