Merge lp:~carla-sella/ubuntu-calendar-app/new-event-test into lp:ubuntu-calendar-app

Proposed by Carla Sella on 2013-06-27
Status: Merged
Approved by: Michael Hall on 2013-07-10
Approved revision: 57
Merged at revision: 65
Proposed branch: lp:~carla-sella/ubuntu-calendar-app/new-event-test
Merge into: lp:ubuntu-calendar-app
Diff against target: 322 lines (+223/-40)
4 files modified
tests/autopilot/calendar_app/emulators/main_window.py (+3/-19)
tests/autopilot/calendar_app/emulators/ubuntusdk.py (+154/-0)
tests/autopilot/calendar_app/tests/__init__.py (+5/-10)
tests/autopilot/calendar_app/tests/test_calendar.py (+61/-11)
To merge this branch: bzr merge lp:~carla-sella/ubuntu-calendar-app/new-event-test
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-07-10
Michael Hall 2013-07-08 Approve on 2013-07-10
Nicholas Skaggs (community) 2013-06-27 Approve on 2013-07-08
Review via email: mp+171878@code.launchpad.net

Commit message

add event autopilot test

Description of the change

autopilot add event test

To post a comment you must log in.
Nicholas Skaggs (nskaggs) wrote :

I realize you are changing much of the current structure around, but it would still by helpful to get this merged rather than sitting out here deprecating in the meantime. It can be updated once the new views are created.

review: Approve
review: Needs Fixing (continuous-integration)
Michael Hall (mhall119) wrote :

Looks good

review: Approve
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/calendar_app/emulators/main_window.py'
2--- tests/autopilot/calendar_app/emulators/main_window.py 2013-05-29 16:38:15 +0000
3+++ tests/autopilot/calendar_app/emulators/main_window.py 2013-06-27 18:04:28 +0000
4@@ -16,25 +16,6 @@
5 def __init__(self, app):
6 self.app = app
7
8- def get_qml_view(self):
9- """Get the main QML view"""
10- return self.app.select_single("QQuickView")
11-
12- def get_panel(self):
13- return self.app.select_single("Toolbar")
14-
15- def get_toolbar_button(self, button_idx):
16- toolbar = self.app.select_single("Toolbar")
17- row = toolbar.select_single("QQuickRow")
18- buttons = row.select_many("Button")
19- return buttons[button_idx]
20-
21- def get_toolbar_new_event_button(self):
22- return self.get_toolbar_button(1)
23-
24- def get_toolbar_timeline_button(self):
25- return self.get_toolbar_button(2)
26-
27 def get_create_event_page(self):
28 return self.app.select_single("NewEvent")
29
30@@ -60,3 +41,6 @@
31
32 def get_event_view(self):
33 return self.app.select_single("EventView")
34+
35+ def get_title_label(self, title):
36+ return self.app.select_many("Label", text=title)
37
38=== added file 'tests/autopilot/calendar_app/emulators/ubuntusdk.py'
39--- tests/autopilot/calendar_app/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
40+++ tests/autopilot/calendar_app/emulators/ubuntusdk.py 2013-06-27 18:04:28 +0000
41@@ -0,0 +1,154 @@
42+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
43+#
44+# Copyright (C) 2013 Canonical Ltd
45+#
46+# This program is free software: you can redistribute it and/or modify
47+# it under the terms of the GNU General Public License version 3 as
48+# published by the Free Software Foundation.
49+#
50+# This program is distributed in the hope that it will be useful,
51+# but WITHOUT ANY WARRANTY; without even the implied warranty of
52+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53+# GNU General Public License for more details.
54+#
55+# You should have received a copy of the GNU General Public License
56+# along with this program. If not, see <http://www.gnu.org/licenses/>.
57+#
58+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
59+
60+from testtools.matchers import Equals, NotEquals, Not, Is
61+from autopilot.matchers import Eventually
62+
63+class ubuntusdk(object):
64+ """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
65+
66+ def __init__(self, autopilot, app):
67+ self.app = app
68+ self.autopilot = autopilot
69+
70+ def get_qml_view(self):
71+ """Get the main QML view"""
72+ return self.app.select_single("QQuickView")
73+
74+ def get_object(self, typeName, name):
75+ """Get a specific object"""
76+ return self.app.select_single(typeName, objectName=name)
77+
78+ def get_objects(self, typeName, name):
79+ """Get more than one object"""
80+ return self.app.select_many(typeName, objectName=name)
81+
82+ def switch_to_tab(self, tab):
83+ """Switch to the specified tab number"""
84+ tabs = self.get_tabs()
85+ currentTab = tabs.selectedTabIndex
86+
87+ #perform operations until tab == currentTab
88+ while tab != currentTab:
89+ if tab > currentTab:
90+ self._previous_tab()
91+ if tab < currentTab:
92+ self._next_tab()
93+ currentTab = tabs.selectedTabIndex
94+
95+ def toggle_toolbar(self):
96+ """Toggle the toolbar between revealed and hidden"""
97+ #check and see if the toolbar is open or not
98+ if self.get_toolbar().opened:
99+ self.hide_toolbar()
100+ else:
101+ self.open_toolbar()
102+
103+ def get_toolbar(self):
104+ """Returns the toolbar in the main events view."""
105+ return self.app.select_single("Toolbar")
106+
107+ def get_toolbar_button(self, buttonLabel):
108+ """Returns the toolbar button at position index"""
109+ toolbar = self.get_toolbar()
110+ if not toolbar.opened:
111+ self.open_toolbar()
112+ row = toolbar.select_single("QQuickRow")
113+ loaderList = row.select_many("QQuickLoader")
114+ for loader in loaderList:
115+ buttonList = loader.select_many("Button")
116+ for button in buttonList:
117+ if button.text == buttonLabel:
118+ return button
119+
120+ def click_toolbar_button(self, buttonLabel):
121+ """Clicks the toolbar button with buttonLabel"""
122+ #The toolbar button is assumed to be the following format
123+ #ToolbarActions {
124+ # Action {
125+ # objectName: "name"
126+ # text: value
127+ button = self.get_toolbar_button(buttonLabel)
128+ self.autopilot.pointing_device.click_object(button)
129+
130+ def open_toolbar(self):
131+ """Open the toolbar"""
132+ qmlView = self.get_qml_view()
133+
134+ lineX = qmlView.x + qmlView.width * 0.50
135+ startY = qmlView.y + qmlView.height - 1
136+ stopY = qmlView.y + qmlView.height * 0.95
137+
138+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
139+
140+ def hide_toolbar(self):
141+ """Hide the toolbar"""
142+ qmlView = self.get_qml_view()
143+
144+ lineX = qmlView.x + qmlView.width * 0.50
145+ startY = qmlView.y + qmlView.height * 0.95
146+ stopY = qmlView.y + qmlView.height - 1
147+
148+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
149+
150+ def set_popup_value(self, popover, button, value):
151+ """Changes the given popover selector to the request value
152+ At the moment this only works for values that are currently visible. To
153+ access the remaining items, a help method to drag and recheck is needed."""
154+ #The popover is assumed to be the following format
155+ # Popover {
156+ # Column {
157+ # ListView {
158+ # delegate: Standard {
159+ # objectName: "name"
160+ # text: value
161+
162+ self.autopilot.pointing_device.click_object(button)
163+ #we'll get all matching objects, incase the popover is reused between buttons
164+ itemList = lambda: self.get_objects("Standard", popover)
165+
166+ for item in itemList():
167+ if item.get_properties()['text'] == value:
168+ self.autopilot.pointing_device.click_object(item)
169+
170+ def get_tabs(self):
171+ """Return all tabs"""
172+ return self.get_object("Tabs", "rootTabs")
173+
174+ def _previous_tab(self):
175+ """Switch to the previous tab"""
176+ qmlView = self.get_qml_view()
177+
178+ startX = qmlView.x + qmlView.width * 0.35
179+ stopX = qmlView.x + qmlView.width * 0.50
180+ lineY = qmlView.y + qmlView.height * 0.05
181+
182+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
183+ self.autopilot.pointing_device.click()
184+ self.autopilot.pointing_device.click()
185+
186+ def _next_tab(self):
187+ """Switch to the next tab"""
188+ qmlView = self.get_qml_view()
189+
190+ startX = qmlView.x + qmlView.width * 0.50
191+ stopX = qmlView.x + qmlView.width * 0.35
192+ lineY = qmlView.y + qmlView.height * 0.05
193+
194+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
195+ self.autopilot.pointing_device.click()
196
197=== modified file 'tests/autopilot/calendar_app/tests/__init__.py'
198--- tests/autopilot/calendar_app/tests/__init__.py 2013-06-12 15:47:15 +0000
199+++ tests/autopilot/calendar_app/tests/__init__.py 2013-06-27 18:04:28 +0000
200@@ -16,6 +16,7 @@
201 from testtools.matchers import Equals
202
203 from calendar_app.emulators.main_window import MainWindow
204+from calendar_app.emulators.ubuntusdk import ubuntusdk
205
206
207 class CalendarTestCase(AutopilotTestCase):
208@@ -52,16 +53,10 @@
209 "--desktop_file_hint=/usr/share/applications/calendar-app.desktop",
210 app_type='qt')
211
212- def reveal_toolbar(self):
213- toolbar = self.main_window.get_panel()
214-
215- x, y, w, h = toolbar.globalRect
216- tx = x + (w / 2)
217- ty = y + (h - 2)
218-
219- self.pointing_device.drag(tx, ty, tx, ty - h)
220- self.assertThat(toolbar.state, Eventually(Equals("spread")))
221-
222 @property
223 def main_window(self):
224 return MainWindow(self.app)
225+
226+ @property
227+ def ubuntusdk(self):
228+ return ubuntusdk(self, self.app)
229
230=== modified file 'tests/autopilot/calendar_app/tests/test_calendar.py'
231--- tests/autopilot/calendar_app/tests/test_calendar.py 2013-06-12 15:47:15 +0000
232+++ tests/autopilot/calendar_app/tests/test_calendar.py 2013-06-27 18:04:28 +0000
233@@ -10,28 +10,78 @@
234 from __future__ import absolute_import
235
236 from autopilot.matchers import Eventually
237-from testtools.matchers import Equals
238+from testtools.matchers import Equals, NotEquals
239
240 from calendar_app.tests import CalendarTestCase
241
242+import time
243
244 class TestMainWindow(CalendarTestCase):
245
246 def setUp(self):
247 super(TestMainWindow, self).setUp()
248 self.assertThat(
249- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
250+ self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
251
252 def tearDown(self):
253 super(TestMainWindow, self).tearDown()
254
255 def test_timeline_view_shows(self):
256- timeline_button = self.main_window.get_toolbar_timeline_button()
257- event_view = self.main_window.get_event_view()
258- self.reveal_toolbar()
259-
260- self.assertThat(event_view.eventViewType, Eventually(Equals("DiaryView.qml")))
261- self.pointing_device.click_object(timeline_button)
262- self.assertThat(event_view.eventViewType, Eventually(Equals("TimeLineView.qml")))
263- self.pointing_device.click_object(timeline_button)
264- self.assertThat(event_view.eventViewType, Eventually(Equals("DiaryView.qml")))
265+ event_view = lambda: self.main_window.get_event_view().eventViewType
266+
267+ self.ubuntusdk.click_toolbar_button('Timeline')
268+ self.assertThat(event_view, Eventually(Equals("TimeLineView.qml")))
269+ self.ubuntusdk.click_toolbar_button('Diary')
270+ self.assertThat(event_view, Eventually(Equals("DiaryView.qml")))
271+ self.ubuntusdk.click_toolbar_button('Timeline')
272+ self.assertThat(event_view, Eventually(Equals("TimeLineView.qml")))
273+
274+ def test_new_event(self):
275+ #click on new event button
276+ self.ubuntusdk.click_toolbar_button('New Event')
277+
278+ #grab all the fields
279+ #event_view = self.main_window.get_event_view()
280+ event_name_field = self.main_window.get_new_event_name_input_box()
281+ start_time_field = self.main_window.get_event_start_time_field()
282+ end_time_field = self.main_window.get_event_end_time_field()
283+ location_field = self.main_window.get_event_location_field()
284+ people_field = self.main_window.get_event_people_field()
285+ save_button = self.main_window.get_event_save_button()
286+
287+ #input a new event name
288+ eventTitle = "Test event" + str(time.time())
289+
290+ self.pointing_device.click_object(event_name_field)
291+ self.keyboard.type(eventTitle)
292+ self.assertThat(event_name_field.text, Eventually(Equals(eventTitle)))
293+
294+ #input start time
295+ self.pointing_device.click_object(start_time_field)
296+ self.keyboard.press_and_release("Ctrl+a")
297+ self.keyboard.type("11")
298+ self.assertThat(start_time_field.text, Eventually(Equals("11")))
299+
300+ #input end time
301+ self.pointing_device.click_object(end_time_field)
302+ self.keyboard.press_and_release("Ctrl+a")
303+ self.keyboard.type("00")
304+ self.assertThat(end_time_field.text, Eventually(Equals("00")))
305+
306+ #input location
307+ self.pointing_device.click_object(location_field)
308+ self.keyboard.type("My location")
309+ self.assertThat(location_field.text, Eventually(Equals("My location")))
310+
311+ #input people
312+ self.pointing_device.click_object(people_field)
313+ self.keyboard.type("Me")
314+ self.assertThat(people_field.text, Eventually(Equals("Me")))
315+
316+ #click save button
317+ self.pointing_device.click_object(save_button)
318+
319+ #verify that the event has been created in timeline
320+ title_label = lambda: self.main_window.get_title_label(eventTitle)
321+ self.assertThat(title_label, Eventually(NotEquals(None)))
322+

Subscribers

People subscribed via source and target branches

to status/vote changes: