Merge lp:~canonical-platform-qa/ubuntu-ui-toolkit/fix1340227-expandable_autopilot_helper into lp:ubuntu-ui-toolkit/staging

Proposed by Leo Arias
Status: Merged
Approved by: Cris Dywan
Approved revision: 1277
Merged at revision: 1304
Proposed branch: lp:~canonical-platform-qa/ubuntu-ui-toolkit/fix1340227-expandable_autopilot_helper
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 235 lines (+173/-16)
3 files modified
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/listitems.py (+42/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.ExpandableTestCase.qml (+66/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.py (+65/-16)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-ui-toolkit/fix1340227-expandable_autopilot_helper
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Cris Dywan Approve
Thomi Richards (community) Approve
Review via email: mp+236770@code.launchpad.net

Commit message

Added an autopilot helper for expandable list items.

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

Reverted indentation.

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

Added the missing file.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

review: Approve
1275. By Leo Arias

Merged with staging.

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

Merged with staging.

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

17 + logger.debug('The item is already expanded.')
33 + logger.debug('The item is already collapsed.')

These should either be exceptions or go away - if we don't want to care about already expanded/ collpased cases there's no need to bloat the log.

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

Added comments for the two new methods.

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

Thank you for adding the documentation! As clarified in a face to face discussion this is indeed consistent with existing API, I was being confused by similarly but differently behaving API, so hopefully documentation can mitigate this whilst we're establishing a convention.

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

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/listitems.py'
2--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/listitems.py 2014-06-16 21:26:30 +0000
3+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/listitems.py 2014-10-22 19:20:56 +0000
4@@ -108,6 +108,48 @@
5 pass
6
7
8+class Expandable(Empty):
9+
10+ @autopilot_logging.log_action(logger.info)
11+ def expand(self):
12+ """Expand an expandable list item.
13+
14+ If the item is already expanded, no action will be executed.
15+ If you want to check if the item is expanded, you can use the
16+ ``expanded`` property.
17+
18+ """
19+ if not self.expanded:
20+ self._click_always_visible_section()
21+ self.expanded.wait_for(True)
22+ self.height.wait_for(self.expandedHeight)
23+ else:
24+ logger.debug('The item is already expanded.')
25+
26+ @autopilot_logging.log_action(logger.debug)
27+ def _click_always_visible_section(self):
28+ self.pointing_device.move(
29+ self.globalRect.x + self.globalRect.width // 2,
30+ self.globalRect.y + self.collapsedHeight // 2)
31+ self.pointing_device.click()
32+
33+ @autopilot_logging.log_action(logger.info)
34+ def collapse(self):
35+ """Collapse an expandable list item.
36+
37+ If the item is already collapsed, no action will be executed.
38+ If you want to check if the item is expanded, you can use the
39+ ``expanded`` property.
40+
41+ """
42+ if self.expanded:
43+ self._click_always_visible_section()
44+ self.expanded.wait_for(False)
45+ self.height.wait_for(self.collapsedHeight)
46+ else:
47+ logger.debug('The item is already collapsed.')
48+
49+
50 class Standard(Empty):
51 pass
52
53
54=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.ExpandableTestCase.qml'
55--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.ExpandableTestCase.qml 1970-01-01 00:00:00 +0000
56+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.ExpandableTestCase.qml 2014-10-22 19:20:56 +0000
57@@ -0,0 +1,66 @@
58+/*
59+ * Copyright 2014 Canonical Ltd.
60+ *
61+ * This program is free software; you can redistribute it and/or modify
62+ * it under the terms of the GNU Lesser General Public License as published by
63+ * the Free Software Foundation; version 3.
64+ *
65+ * This program is distributed in the hope that it will be useful,
66+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
67+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68+ * GNU Lesser General Public License for more details.
69+ *
70+ * You should have received a copy of the GNU Lesser General Public License
71+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
72+ */
73+
74+import QtQuick 2.0
75+import Ubuntu.Components 1.1
76+import Ubuntu.Components.ListItems 0.1
77+
78+
79+MainView {
80+ width: units.gu(48)
81+ height: units.gu(60)
82+
83+
84+ Column {
85+ anchors.fill: parent
86+
87+ Repeater {
88+ model: 2
89+ Expandable {
90+ id: expandingItem
91+ objectName: "expandable" + index
92+ expandedHeight: contentCol.height + units.gu(1)
93+
94+ onClicked: {
95+ expanded = !expanded;
96+ }
97+
98+ Column {
99+ id: contentCol
100+ anchors { left: parent.left; right: parent.right }
101+ Item {
102+ anchors { left: parent.left; right: parent.right}
103+ height: expandingItem.collapsedHeight
104+ Label {
105+ anchors {
106+ left: parent.left
107+ right: parent.right
108+ verticalCenter: parent.verticalCenter
109+ }
110+ text: "Item " + index
111+ }
112+ }
113+
114+ UbuntuShape {
115+ objectName: "shape" + index
116+ anchors { left: parent.left; right: parent.right }
117+ height: units.gu(6)
118+ }
119+ }
120+ }
121+ }
122+ }
123+}
124
125=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.py'
126--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.py 2014-06-12 22:56:48 +0000
127+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_listitems.py 2014-10-22 19:20:56 +0000
128@@ -14,15 +14,43 @@
129 # You should have received a copy of the GNU Lesser General Public License
130 # along with this program. If not, see <http://www.gnu.org/licenses/>.
131
132+try:
133+ from unittest import mock
134+except ImportError:
135+ import mock
136+
137 import logging
138+import os
139
140 import fixtures
141+import testtools
142 from testtools.matchers import Contains
143
144 import ubuntuuitoolkit
145 from ubuntuuitoolkit import listitems, tests
146
147
148+class ListItemsTestCase(testtools.TestCase):
149+
150+ def test_supported_class(self):
151+ self.assertTrue(issubclass(
152+ listitems.Base, listitems.Empty))
153+ self.assertTrue(issubclass(
154+ listitems.Expandable, listitems.Empty))
155+ self.assertTrue(issubclass(
156+ listitems.ItemSelector, listitems.Empty))
157+ self.assertTrue(issubclass(
158+ listitems.Standard, listitems.Empty))
159+ self.assertTrue(issubclass(
160+ listitems.SingleControl, listitems.Empty))
161+ self.assertTrue(issubclass(
162+ listitems.MultiValue, listitems.Base))
163+ self.assertTrue(issubclass(
164+ listitems.SingleValue, listitems.Base))
165+ self.assertTrue(issubclass(
166+ listitems.Subtitled, listitems.Base))
167+
168+
169 class SwipeToDeleteTestCase(tests.QMLStringAppTestCase):
170
171 test_qml = ("""
172@@ -97,22 +125,6 @@
173 listitems.Standard, objectName='listitem_standard')
174 self.assertTrue(self._item.exists())
175
176- def test_supported_class(self):
177- self.assertTrue(issubclass(
178- listitems.Base, listitems.Empty))
179- self.assertTrue(issubclass(
180- listitems.ItemSelector, listitems.Empty))
181- self.assertTrue(issubclass(
182- listitems.Standard, listitems.Empty))
183- self.assertTrue(issubclass(
184- listitems.SingleControl, listitems.Empty))
185- self.assertTrue(issubclass(
186- listitems.MultiValue, listitems.Base))
187- self.assertTrue(issubclass(
188- listitems.SingleValue, listitems.Base))
189- self.assertTrue(issubclass(
190- listitems.Subtitled, listitems.Base))
191-
192 def test_standard_custom_proxy_object(self):
193 self.assertIsInstance(self._item, listitems.Standard)
194
195@@ -185,3 +197,40 @@
196 objectName='listitem_destroyed_on_remove_without_confirm')
197 item.swipe_to_delete()
198 self.assertFalse(item.exists())
199+
200+
201+class ExpandableTestCase(tests.QMLFileAppTestCase):
202+
203+ path = os.path.abspath(__file__)
204+ dir_path = os.path.dirname(path)
205+ test_qml_file_path = os.path.join(
206+ dir_path, 'test_listitems.ExpandableTestCase.qml')
207+
208+ def setUp(self):
209+ super(ExpandableTestCase, self).setUp()
210+ self.test_expandable = self.main_view.select_single(
211+ listitems.Expandable, objectName='expandable0')
212+
213+ def test_expand_item(self):
214+ self.test_expandable.expand()
215+ self.assertTrue(self.test_expandable.expanded)
216+
217+ def test_expand_already_expanded_item_must_do_nothing(self):
218+ self.test_expandable.expand()
219+
220+ # Replace the pointer with None, so we make sure it's not being called.
221+ with mock.patch.object(self.test_expandable, 'pointing_device', None):
222+ self.test_expandable.expand()
223+
224+ def test_collapse_item(self):
225+ self.test_expandable.expand()
226+
227+ self.test_expandable.collapse()
228+ self.assertFalse(self.test_expandable.expanded)
229+
230+ def test_collapse_already_collapsed_item_must_do_nothing(self):
231+ self.test_expandable.collapse()
232+
233+ # Replace the pointer with None, so we make sure it's not being called.
234+ with mock.patch.object(self.test_expandable, 'pointing_device', None):
235+ self.test_expandable.collapse()

Subscribers

People subscribed via source and target branches