Merge lp:~elopio/ubuntu-ui-toolkit/tabs_emulator-2 into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Merged
Approved by: Juhapekka Piiroinen
Approved revision: 625
Merged at revision: 645
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/tabs_emulator-2
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~elopio/ubuntu-ui-toolkit/toolbar_emulator-2
Diff against target: 316 lines (+220/-13)
2 files modified
tests/autopilot/UbuntuUiToolkit/emulators.py (+109/-11)
tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py (+111/-2)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/tabs_emulator-2
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Juhapekka Piiroinen (community) Approve
Review via email: mp+175738@code.launchpad.net

Description of the change

Added the Tabs autopilot emulator.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Juhapekka Piiroinen (juhapekka-piiroinen) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
625. By Leo Arias

Merged with trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (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/emulators.py'
2--- tests/autopilot/UbuntuUiToolkit/emulators.py 2013-07-19 06:08:14 +0000
3+++ tests/autopilot/UbuntuUiToolkit/emulators.py 2013-07-19 23:11:26 +0000
4@@ -14,12 +14,16 @@
5 # You should have received a copy of the GNU Lesser General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8+import time
9+
10 from autopilot import input, platform
11 from autopilot.introspection import dbus
12
13+_NO_TABS_ERROR = 'The MainView has no Tabs.'
14+
15
16 def get_pointing_device():
17- """Get the pointing device depending on the platform.
18+ """Return the pointing device depending on the platform.
19
20 If the platform is `Desktop`, the pointing device will be a `Mouse`.
21 If not, the pointing device will be `Touch`.
22@@ -44,17 +48,17 @@
23 self.pointing_device = get_pointing_device()
24
25 def get_header(self):
26- """Get the Header emulator of the MainView."""
27+ """Return the Header emulator of the MainView."""
28 return self.select_single('Header')
29
30 def get_toolbar(self):
31- """Get the Toolbar emulator of the MainView."""
32+ """Return the Toolbar emulator of the MainView."""
33 return self.select_single(Toolbar)
34
35 def open_toolbar(self):
36 """Open the toolbar if it's not already opened.
37
38- :return: the toolbar.
39+ :return: The toolbar.
40
41 """
42 toolbar = self.get_toolbar()
43@@ -65,8 +69,7 @@
44 return toolbar
45
46 def _drag_to_open_toolbar(self):
47- x = self.globalRect[0]
48- y = self.globalRect[1]
49+ x, y, _, _ = self.globalRect
50 line_x = x + self.width * 0.50
51 start_y = y + self.height - 1
52 stop_y = y + self.height * 0.95
53@@ -81,14 +84,97 @@
54 toolbar.opened.wait_for(False)
55
56 def _drag_to_close_toolbar(self):
57- x = self.globalRect[0]
58- y = self.globalRect[1]
59+ x, y, _, _ = self.globalRect
60 line_x = x + self.width * 0.50
61 start_y = y + self.height * 0.95
62 stop_y = y + self.height - 1
63
64 self.pointing_device.drag(line_x, start_y, line_x, stop_y)
65
66+ def get_tabs(self):
67+ """Return the Tabs emulator of the MainView."""
68+ tabs = self.select_single(Tabs)
69+ assert tabs is not None, _NO_TABS_ERROR
70+ return tabs
71+
72+ def switch_to_next_tab(self):
73+ """Open the next tab.
74+
75+ :return: The newly opened tab.
76+
77+ """
78+ self.get_header().switch_to_next_tab()
79+ current_tab = self.get_tabs().get_current_tab()
80+ current_tab.visible.wait_for(True)
81+ return current_tab
82+
83+ def switch_to_tab_by_index(self, index):
84+ """Open a tab.
85+
86+ :parameter index: The index of the tab to open.
87+ :return: The newly opened tab.
88+
89+ """
90+ tabs = self.get_tabs()
91+ if index >= tabs.get_number_of_tabs():
92+ raise IndexError('Tab index out of range.')
93+ current_tab = tabs.get_current_tab()
94+ while not tabs.selectedTabIndex == index:
95+ current_tab = self.switch_to_next_tab()
96+ return current_tab
97+
98+ def switch_to_previous_tab(self):
99+ """Open the previous tab.
100+
101+ :return: The newly opened tab.
102+
103+ """
104+ tabs = self.get_tabs()
105+ if tabs.selectedTabIndex == 0:
106+ previous_tab_index = tabs.get_number_of_tabs() - 1
107+ else:
108+ previous_tab_index = tabs.selectedTabIndex - 1
109+ return self.switch_to_tab_by_index(previous_tab_index)
110+
111+ def switch_to_tab(self, object_name):
112+ """Open a tab.
113+
114+ :parameter object_name: The QML objectName property of the tab.
115+ :return: The newly opened tab.
116+
117+ """
118+ tabs = self.get_tabs()
119+ for index, tab in enumerate(tabs.select_many('Tab')):
120+ if tab.objectName == object_name:
121+ return self.switch_to_tab_by_index(index)
122+ raise ValueError(
123+ 'Tab with objectName "{0}" not found.'.format(object_name))
124+
125+
126+class Header(UbuntuUIToolkitEmulatorBase):
127+ """Header Autopilot emulator."""
128+
129+ def __init__(self, *args):
130+ super(Header, self).__init__(*args)
131+ self.pointing_device = get_pointing_device()
132+
133+ def switch_to_next_tab(self):
134+ """Open the next tab."""
135+ tab_bar = self.select_single('NewTabBar')
136+ assert tab_bar is not None, _NO_TABS_ERROR
137+ tab_bar_x, tab_bar_y, _, _ = tab_bar.globalRect
138+ line_y = tab_bar_y + tab_bar.height * 0.5
139+ current_tab_x = tab_bar_x + tab_bar.width * 0.35
140+ next_tab_x = tab_bar_x + tab_bar.width * 0.65
141+
142+ self.pointing_device.move(current_tab_x, line_y)
143+ self.pointing_device.click()
144+ self.pointing_device.move(next_tab_x, line_y)
145+ self.pointing_device.click()
146+
147+ # Sleep while the animation finishes.
148+ time.sleep(tab_bar.buttonPositioningVelocity)
149+
150
151 class Toolbar(UbuntuUIToolkitEmulatorBase):
152 """Toolbar Autopilot emulator."""
153@@ -104,10 +190,22 @@
154
155 """
156 button = self._get_button(object_name)
157- not_found_error = 'Button with objectName "{0}" not found.'.format(
158- object_name)
159- assert button is not None, not_found_error
160+ if button is None:
161+ raise ValueError(
162+ 'Button with objectName "{0}" not found.'.format(object_name))
163 self.pointing_device.click_object(button)
164
165 def _get_button(self, object_name):
166 return self.select_single('ActionItem', objectName=object_name)
167+
168+
169+class Tabs(UbuntuUIToolkitEmulatorBase):
170+ """Tabs Autopilot emulator."""
171+
172+ def get_current_tab(self):
173+ """Return the currently selected tab."""
174+ return self.select_many('Tab')[self.selectedTabIndex]
175+
176+ def get_number_of_tabs(self):
177+ """Return the number of tabs."""
178+ return len(self.select_many('Tab'))
179
180=== modified file 'tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py'
181--- tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py 2013-07-19 06:17:46 +0000
182+++ tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py 2013-07-19 23:11:26 +0000
183@@ -44,6 +44,19 @@
184 self.assertIsInstance(toolbar, emulators.Toolbar)
185 self.assertFalse(toolbar.opened)
186
187+ def test_get_tabs_without_tabs(self):
188+ error = self.assertRaises(
189+ AssertionError, self.main_view.get_tabs)
190+ self.assertEqual(
191+ error.message, 'The MainView has no Tabs.')
192+
193+ def test_switch_to_next_tab_without_tabs(self):
194+ header = self.main_view.get_header()
195+ error = self.assertRaises(
196+ AssertionError, header.switch_to_next_tab)
197+ self.assertEqual(
198+ error.message, 'The MainView has no Tabs.')
199+
200
201 class PageTestCase(tests.UbuntuUiToolkitTestCase):
202
203@@ -61,8 +74,9 @@
204 }
205 """)
206
207- def test_get_header(self):
208+ def test_header_custom_emulator(self):
209 header = self.main_view.get_header()
210+ self.assertIsInstance(header, emulators.Header)
211 self.assertTrue(header.visible)
212 self.assertEqual(header.title, "Test title")
213
214@@ -137,6 +151,101 @@
215 def test_click_unexisting_button(self):
216 toolbar = self.main_view.open_toolbar()
217 error = self.assertRaises(
218- AssertionError, toolbar.click_button, 'unexisting')
219+ ValueError, toolbar.click_button, 'unexisting')
220 self.assertEqual(
221 error.message, 'Button with objectName "unexisting" not found.')
222+
223+
224+class TabsTestCase(tests.UbuntuUiToolkitTestCase):
225+
226+ test_qml = ("""
227+import QtQuick 2.0
228+import Ubuntu.Components 0.1
229+import Ubuntu.Components.ListItems 0.1 as ListItem
230+
231+MainView {
232+ width: units.gu(48)
233+ height: units.gu(60)
234+
235+ Tabs {
236+ id: tabs
237+ Tab {
238+ objectName: "tab1"
239+ title: "Test tab 1"
240+ }
241+ Tab {
242+ objectName: "tab2"
243+ title: "Test tab 2"
244+ }
245+ }
246+}
247+""")
248+
249+ def test_tabs_custom_emulator(self):
250+ self.assertIsInstance(self.main_view.get_tabs(), emulators.Tabs)
251+
252+ def test_get_current_tab(self):
253+ tabs = self.main_view.get_tabs()
254+ self.assertEqual(tabs.get_current_tab().title, 'Test tab 1')
255+
256+ def test_switch_to_next_tab_from_header(self):
257+ header = self.main_view.get_header()
258+ header.switch_to_next_tab()
259+ current_tab = self.main_view.get_tabs().get_current_tab()
260+ self.assertEqual(current_tab.title, 'Test tab 2')
261+
262+ def test_switch_to_next_tab_from_main_view(self):
263+ current_tab = self.main_view.switch_to_next_tab()
264+ self.assertEqual(current_tab.title, 'Test tab 2')
265+
266+ def test_switch_to_next_tab_from_last(self):
267+ last_tab_index = 1
268+ self.main_view.switch_to_tab_by_index(last_tab_index)
269+ current_tab = self.main_view.switch_to_next_tab()
270+ self.assertEqual(current_tab.title, 'Test tab 1')
271+
272+ def test_switch_to_tab_by_index(self):
273+ current_tab = self.main_view.switch_to_tab_by_index(1)
274+ self.assertEqual(current_tab.title, 'Test tab 2')
275+ current_tab = self.main_view.switch_to_tab_by_index(0)
276+ self.assertEqual(current_tab.title, 'Test tab 1')
277+
278+ def test_switch_to_opened_tab_is_not_opened_again(self):
279+ with mock.patch.object(
280+ emulators.Header, 'switch_to_next_tab') as mock_switch:
281+ current_tab = self.main_view.switch_to_tab_by_index(0)
282+
283+ self.assertFalse(mock_switch.called)
284+ self.assertEqual(current_tab.title, 'Test tab 1')
285+
286+ def test_get_number_of_tabs(self):
287+ tabs = self.main_view.get_tabs()
288+ self.assertEqual(tabs.get_number_of_tabs(), 2)
289+
290+ def test_swith_to_tab_by_index_out_of_range(self):
291+ last_tab_index = 1
292+ error = self.assertRaises(
293+ IndexError, self.main_view.switch_to_tab_by_index,
294+ last_tab_index + 1)
295+ self.assertEqual(error.message, 'Tab index out of range.')
296+
297+ def test_switch_to_previous_tab_from_first(self):
298+ current_tab = self.main_view.switch_to_previous_tab()
299+ self.assertEqual(current_tab.title, 'Test tab 2')
300+
301+ def test_switch_to_previous_tab_not_from_first(self):
302+ self.main_view.switch_to_tab_by_index(1)
303+ current_tab = self.main_view.switch_to_previous_tab()
304+ self.assertEqual(current_tab.title, 'Test tab 1')
305+
306+ def test_switch_to_tab_by_object_name(self):
307+ current_tab = self.main_view.switch_to_tab('tab2')
308+ self.assertEqual(current_tab.title, 'Test tab 2')
309+ current_tab = self.main_view.switch_to_tab('tab1')
310+ self.assertEqual(current_tab.title, 'Test tab 1')
311+
312+ def test_switch_to_unexisting_tab(self):
313+ error = self.assertRaises(
314+ ValueError, self.main_view.switch_to_tab, 'unexisting')
315+ self.assertEqual(
316+ error.message, 'Tab with objectName "unexisting" not found.')

Subscribers

People subscribed via source and target branches

to status/vote changes: