Merge lp:~elopio/ubuntu-clock-app/refactor_timer_tests into lp:ubuntu-clock-app/saucy

Proposed by Leo Arias
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 337
Merged at revision: 350
Proposed branch: lp:~elopio/ubuntu-clock-app/refactor_timer_tests
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 602 lines (+249/-160)
7 files modified
alarm/AddAlarmPage.qml (+1/-0)
alarm/AlarmPage.qml (+1/-0)
stopwatch/StopwatchPage.qml (+1/-0)
tests/autopilot/ubuntu_clock_app/emulators.py (+193/-46)
tests/autopilot/ubuntu_clock_app/tests/test_clock.py (+1/-0)
tests/autopilot/ubuntu_clock_app/tests/test_timer.py (+43/-106)
timer/PresetList.qml (+9/-8)
To merge this branch: bzr merge lp:~elopio/ubuntu-clock-app/refactor_timer_tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nekhelesh Ramananthan Approve
Nicholas Skaggs (community) Approve
Review via email: mp+207307@code.launchpad.net

This proposal supersedes a proposal from 2014-01-31.

Commit message

Refactored the timer autopilot tests.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) 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

I fixed pep8 and pyflakes, because I'm a freak and can't live without that.
Then, I encapsulated the actions of the timer page in the TimerPage class, making public only the methods that represent action users. All internal things, like _get_X_element, or _click_something are private details of the emulators.

With this we make sure that the tests are high level user stories. They are short, and use the user language.

Lets say that in the future, designers decide that it's best if we add a button to add timers instead of doing that from the toolbar. In that case, we don't have to modify the test case, we only have to modify the _click_add_timer_button method.

On the prerequisite branch, nik added a check that the name of the timer was properly written. I moved it to
260 + if name_label.text != name:
but, the right thing to do is to have the textfield emulator making the check for us. I reported that as bug https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1275078

Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

So most of this is actually pep8 and pyflakes. Don't worry Leo, it bothers me as well (even though I don't like pep8 in some cases).

Most of the restructuring is straightforward; really nothing crazy. It gets my +1. I will say, it's difficult to read the diff because of the pep8 and pyflakes changes, but I understand the desire to lump them.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

I had started on this at one point; glad you've seen it through :-)

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

I think you will need to another massive trunk merge since we just landed the convergence layout design into trunk few minutes ago. This means that the test will need to adapt if it is running the phone or tablet interface. I have already accounted for this in trunk. You will need to merge trunk to get those important AP fixes.

review: Needs Fixing
324. By Leo Arias

Merged with trunk.

325. By Leo Arias

Revert the extra changes.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

547 - // TODO: Fix autopilot test first before enabling this change in another MP
548 - //PropertyChanges { target: namePreset; text: "Timer #" + (listPreset.listCount + 1) }
549 + PropertyChanges { target: namePreset; text: "Timer #" + (listPreset.listCount + 1) }

This fix is not present in the trunk. I believe this is an old remaining part from the add-timer-placeholder-text MP. Please revert this.

189 + self.drag_page_up()

I see this code in several places. It won't work for the following reasons,
a) You need a condition to check if dragging the page action is necessary in the first place since in the tablet interface there is dragging page up/down actions. This is why I added the if condition, if not(self.wideAspect) wherever I made the drag_page function calls. I don't see it in this MP.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

In my comment above I meant that there are *no* dragging the page up/down actions.

326. By Leo Arias

Reverted change from other branch.

327. By Leo Arias

Drag only if we are not on maguro.

328. By Leo Arias

Fixed.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
329. By Leo Arias

Use the object name.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
330. By Leo Arias

Added another wait.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
331. By Leo Arias

Added another wait.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
332. By Leo Arias

fix

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
333. By Leo Arias

Added the object name to the flickables.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
334. By Leo Arias

Added the objectName.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
335. By Leo Arias

Removed the unused imports.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Wow! Well organised and look awesome. It just needs two small fixes.

521 + self.page.drag_page_up()
534 + self.page.drag_page_up()

In these two lines in test_timer.py you can the function drag_page_up() without checking if the interface is phone or tablet. As a result when I tested on my desktop using tablet interface, AP tried dragging the page up, however there was nothing to drag up. The test did still pass, but it would be nice to check the interface before doing this step.

A if loop like below should fix it.

if not self.main_view.wideAspect:
    + self.drag_page_up()

Otherwise this commit is ready for merge.

review: Needs Fixing
336. By Leo Arias

Drag only when we are nto on wide mode, as suggested by nik.

337. By Leo Arias

Fixed comment.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

lgtm!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'alarm/AddAlarmPage.qml'
--- alarm/AddAlarmPage.qml 2014-02-19 17:43:14 +0000
+++ alarm/AddAlarmPage.qml 2014-02-24 16:24:49 +0000
@@ -324,6 +324,7 @@
324324
325 Flickable {325 Flickable {
326 id: addAlarmPageAnimationContainer326 id: addAlarmPageAnimationContainer
327 objectName: "animationContainer"
327328
328 anchors.fill: parent329 anchors.fill: parent
329 contentWidth: addAlarmPage.width330 contentWidth: addAlarmPage.width
330331
=== modified file 'alarm/AlarmPage.qml'
--- alarm/AlarmPage.qml 2014-02-19 17:43:14 +0000
+++ alarm/AlarmPage.qml 2014-02-24 16:24:49 +0000
@@ -199,6 +199,7 @@
199199
200 Flickable {200 Flickable {
201 id: alarmAnimationContainer201 id: alarmAnimationContainer
202 objectName: "animationContainer"
202203
203 Component.onCompleted: alarmPageFlickable = alarmAnimationContainer204 Component.onCompleted: alarmPageFlickable = alarmAnimationContainer
204205
205206
=== modified file 'stopwatch/StopwatchPage.qml'
--- stopwatch/StopwatchPage.qml 2014-02-19 17:43:14 +0000
+++ stopwatch/StopwatchPage.qml 2014-02-24 16:24:49 +0000
@@ -197,6 +197,7 @@
197197
198 Flickable {198 Flickable {
199 id: stopwatchAnimationContainer199 id: stopwatchAnimationContainer
200 objectName: "animationContainer"
200201
201 Component.onCompleted: stopwatchPageFlickable = stopwatchAnimationContainer202 Component.onCompleted: stopwatchPageFlickable = stopwatchAnimationContainer
202203
203204
=== modified file 'tests/autopilot/ubuntu_clock_app/emulators.py'
--- tests/autopilot/ubuntu_clock_app/emulators.py 2014-02-19 18:04:36 +0000
+++ tests/autopilot/ubuntu_clock_app/emulators.py 2014-02-24 16:24:49 +0000
@@ -21,8 +21,11 @@
21from time import sleep21from time import sleep
2222
23from autopilot import logging as autopilot_logging23from autopilot import logging as autopilot_logging
24
25
24from ubuntuuitoolkit import emulators as toolkit_emulators26from ubuntuuitoolkit import emulators as toolkit_emulators
2527
28
26logger = logging.getLogger(__name__)29logger = logging.getLogger(__name__)
2730
2831
@@ -32,6 +35,16 @@
3235
33class MainView(toolkit_emulators.MainView):36class MainView(toolkit_emulators.MainView):
3437
38 @autopilot_logging.log_action(logger.info)
39 def open_timer(self):
40 """Open the Timer tab.
41
42 :return: the Timer page.
43
44 """
45 self.switch_to_tab('TimerTab')
46 return self.wait_select_single(TimerPage)
47
35 # Common Emulator Functions48 # Common Emulator Functions
36 def _drag_page(self, page, direction):49 def _drag_page(self, page, direction):
37 """Function to drag the page up/down"""50 """Function to drag the page up/down"""
@@ -65,7 +78,9 @@
65 self.pointing_device.release()78 self.pointing_device.release()
6679
67 def _wait_to_stop_moving(self, page):80 def _wait_to_stop_moving(self, page):
68 page.select_single("QQuickFlickable").moving.wait_for(False)81 page.select_single(
82 'QQuickFlickable',
83 objectName='animationContainer').moving.wait_for(False)
6984
70 # CLOCK Page Emulator Functions85 # CLOCK Page Emulator Functions
71 def get_clock_page(self):86 def get_clock_page(self):
@@ -74,7 +89,8 @@
7489
75 def get_time_label(self):90 def get_time_label(self):
76 """Return the label with the timer countdown"""91 """Return the label with the timer countdown"""
77 return self.select_single("ClockPage").wait_select_single("Label", objectName="label")92 return self.select_single("ClockPage").wait_select_single(
93 "Label", objectName="label")
7894
79 # WORLD CLOCK Page Emulator Functions95 # WORLD CLOCK Page Emulator Functions
80 def get_world_cities_page(self):96 def get_world_cities_page(self):
@@ -83,10 +99,11 @@
8399
84 def get_search_box(self):100 def get_search_box(self):
85 """Returns the search box used to search for world cities online."""101 """Returns the search box used to search for world cities online."""
86 return self.wait_select_single('SearchBox', objectName="worldSearchBox")102 return self.wait_select_single(
103 'SearchBox', objectName="worldSearchBox")
87104
88 def get_world_cities_list(self):105 def get_world_cities_list(self):
89 """Return the component containing the list of available world cities."""106 """Return the component of the list of available world cities."""
90 return self.wait_select_single(objectName="worldList")107 return self.wait_select_single(objectName="worldList")
91108
92 def get_city_name(self, city):109 def get_city_name(self, city):
@@ -94,11 +111,15 @@
94 return city.wait_select_single('Label', objectName='city_name').text111 return city.wait_select_single('Label', objectName='city_name').text
95112
96 def get_saved_cities_list(self):113 def get_saved_cities_list(self):
97 """Return the component containing list of user saved world city locations."""114 """Return the component of the user saved world city locations."""
98 return self.wait_select_single(objectName="listWorldClocks")115 return self.wait_select_single(objectName="listWorldClocks")
99116
100 def grab_first_listed_city(self):117 def grab_first_listed_city(self):
101 """Return the first city from the available world cities list (both local and online)"""118 """Return the first city from the available world cities.
119
120 It returns both local and online.
121
122 """
102 return self.wait_select_single("Base", objectName="worldcity0")123 return self.wait_select_single("Base", objectName="worldcity0")
103124
104 def select_city(self, city):125 def select_city(self, city):
@@ -107,53 +128,19 @@
107128
108 def grab_first_saved_city(self):129 def grab_first_saved_city(self):
109 """Return the first city from the user saved world cities list"""130 """Return the first city from the user saved world cities list"""
110 return self.wait_select_single("Standard", objectName="savedworldcity0")131 return self.wait_select_single(
111132 "Standard", objectName="savedworldcity0")
112 # TIMER Page Emulator Functions
113 def get_timer_reset_button(self):
114 """Returns the select for the reset button"""
115 return self.select_single("ImageButton", objectName="resetButtonTimer")
116
117 def get_timer_name_preset(self):
118 """Returns the TextField where insert the name of the preset"""
119 return self.wait_select_single(LabelDots, objectName="namePreset")
120
121 def get_timer_minute_hand(self):
122 """Returns the hour hand of clock in timer tab"""
123 return self.select_single("TimerPage").wait_select_single("DialerHand", objectName="minuteHand")
124
125 def get_preset_label_text(self):
126 """Returns the label with the preset text"""
127 preset = self.select_many("Label", objectName="presetTextLabel")
128 return preset[0] # last preset, the one created by autopilot
129
130 def get_preset_label_timer(self):
131 """Returns the label with the preset timer"""
132 preset = self.select_many("Label", objectName="presetTimerLabel")
133 return preset[0] # last preset, the one created by autopilot
134
135 def get_label_timer(self):
136 """Return the label with the timer countdown"""
137 return self.select_single("TimerPage").wait_select_single("Label", objectName="label")
138
139 def get_first_preset_list_item(self):
140 """Returns the first preset list item in the timer page."""
141 return self.wait_select_single("Standard", objectName="preset0")
142
143 def get_num_of_presets(self):
144 """Returns the number of presets in the timer page."""
145 timer_page = self.select_single("TimerPage")
146 return int(timer_page.wait_select_single("QQuickListView").count)
147133
148 # STOPWATCH Page Emulator Functions134 # STOPWATCH Page Emulator Functions
149 def get_stopwatch_label(self):135 def get_stopwatch_label(self):
150 """Returns the select for the stopwatch label"""136 """Returns the select for the stopwatch label"""
151 return self.select_single("StopwatchPage").wait_select_single("Label", objectName="label")137 return self.select_single(
138 "StopwatchPage").wait_select_single("Label", objectName="label")
152139
153 def get_stopwatch_button(self):140 def get_stopwatch_button(self):
154 """Returns the select for the stopwatch button"""141 """Returns the select for the stopwatch button"""
155 return self.wait_select_single("StopwatchFace",142 return self.wait_select_single(
156 objectName="stopwatchFace")143 "StopwatchFace", objectName="stopwatchFace")
157144
158 def get_lap_button(self):145 def get_lap_button(self):
159 """Returns the select for the lap button"""146 """Returns the select for the lap button"""
@@ -350,5 +337,165 @@
350 self.pointing_device.click_object(alarm)337 self.pointing_device.click_object(alarm)
351338
352339
340class Page(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
341 """Autopilot helper for Pages."""
342
343 def drag_page_up(self):
344 """Drag the given page up."""
345 self._drag_page(direction='up')
346
347 def drag_page_down(self):
348 """Drag the given page down."""
349 self._drag_page(direction='down')
350
351 def _drag_page(self, direction):
352 """Function to drag the page up/down."""
353 self._wait_to_stop_moving()
354
355 x, y, w, h = self.globalRect
356 start_x = stop_x = x + (w / 2)
357 start_y = y + (h / 2)
358
359 if direction == "down":
360 stop_y = start_y + h / 3
361 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
362 else:
363 stop_y = start_y - h / 3
364 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
365
366 self._wait_to_stop_moving()
367
368 def _wait_to_stop_moving(self):
369 self.select_single(
370 'QQuickFlickable',
371 objectName='animationContainer').moving.wait_for(False)
372
373
374class TimerPage(Page):
375 """Autopilot helper for the Timer page."""
376
377 def __init__(self, *args):
378 super(Page, self).__init__(*args)
379 # XXX we need a better way to keep reference to the main view.
380 # --elopio - 2014-01-31
381 self.main_view = self.get_root_instance().select_single(MainView)
382
383 def get_num_of_presets(self):
384 """Return the number of presets in the timer page."""
385 return int(self.wait_select_single('QQuickListView').count)
386
387 @autopilot_logging.log_action(logger.info)
388 def add_timer(self, name, set_time=False):
389 self._click_add_timer_button()
390 self._wait_to_stop_moving()
391 if not self.main_view.wideAspect:
392 self.drag_page_up()
393 self._set_timer_name(name)
394 if not self.main_view.wideAspect:
395 self.drag_page_down()
396 if set_time:
397 self._set_time()
398 self._click_save()
399
400 def _click_add_timer_button(self):
401 toolbar = self.main_view.open_toolbar()
402 toolbar.click_button('addPresetButton')
403
404 def _set_timer_name(self, name):
405 name_label = self.wait_select_single(
406 LabelDots, objectName='namePreset')
407 name_label.write(name)
408 if name_label.text != name:
409 raise ClockEmulatorException('Failed to write the timer name.')
410
411 def _set_time(self):
412 # Set timer minute
413 logger.debug('Grabbing minute hand')
414
415 timeout = 0
416 timer_face = self.select_single('TimerFace')
417 #need to select clock in order to set time
418 while not timer_face.focus and timeout < 10:
419 logger.debug('Timerlabel loop')
420 self._click_timer_label()
421 sleep(1)
422 timeout += 1
423
424 # TODO we need a dialer hand emulator, with proper self-tests.
425 # --elopio -2014-01-31
426 minute = self._get_timer_minute_hand()
427 #make sure timer is set
428 x, y, w, h = minute.globalRect
429 tx = x + (w / 2)
430 ty = y + (h / 2.5)
431 timeout = 0
432 reset_button = self._get_timer_reset_button()
433 logger.debug('reset_button %s' % reset_button.visible)
434
435 #Try again if we failed at first
436 while not reset_button.visible and timeout < 10:
437 logger.debug('Dragging minute hand')
438 self.pointing_device.drag(
439 tx, ty - (h / 4), tx + (w / 2), ty + (h / 2))
440 sleep(1)
441 timeout += 1
442
443 def _get_timer_minute_hand(self):
444 """Return the hour hand of clock in timer tab."""
445 return self.wait_select_single('DialerHand', objectName='minuteHand')
446
447 def _click_timer_label(self):
448 timer_label = self._get_label_timer()
449 self.pointing_device.click_object(timer_label)
450
451 def _get_label_timer(self):
452 """Return the label with the timer countdown."""
453 return self.select_single('Label', objectName='label')
454
455 def _get_timer_reset_button(self):
456 """Return the select for the reset button."""
457 return self.select_single('ImageButton', objectName='resetButtonTimer')
458
459 def _click_save(self):
460 toolbar = self.main_view.open_toolbar()
461 toolbar.click_button('savePresetButton')
462
463 def get_presets(self):
464 """Return a list with the information of the presets.
465
466 Each item of the returned list is a tuple of (name, time).
467
468 """
469 presets = []
470 for index in range(self.get_num_of_presets()):
471 text = self.select_single(
472 'Label', objectName='presetTextLabel{}'.format(index)).text
473 time = self.select_single(
474 'Label', objectName='presetTimerLabel{}'.format(index)).text
475 presets.append((text, time))
476 return presets
477
478 @autopilot_logging.log_action(logger.info)
479 def run_preset_timer(self, index):
480 self._select_preset(index)
481 self._click_timer_label()
482
483 def _select_preset(self, index):
484 presets_list = self.select_single(
485 toolkit_emulators.QQuickListView, objectName='listTimerPreset')
486 presets_list.click_element('preset{}'.format(index))
487
488 def get_current_time(self):
489 """Return the time of the currently selected timer."""
490 self._get_label_timer().text
491
492 @autopilot_logging.log_action(logger.info)
493 def delete_preset_timer(self, index):
494 preset = self.select_single(
495 toolkit_emulators.Standard, objectName='preset{}'.format(index))
496 preset.swipe_to_delete()
497 preset.confirm_removal()
498
499
353class LabelDots(toolkit_emulators.TextField):500class LabelDots(toolkit_emulators.TextField):
354 """Autopilot helper for the LabelDots component."""501 """Autopilot helper for the LabelDots component."""
355502
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_clock.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2014-02-19 12:03:16 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2014-02-24 16:24:49 +0000
@@ -95,6 +95,7 @@
95 # Get the saved world city and swipe to delete95 # Get the saved world city and swipe to delete
96 old_saved_city_count = self.main_view.get_saved_cities_list().count96 old_saved_city_count = self.main_view.get_saved_cities_list().count
97 saved_city = self.main_view.grab_first_saved_city()97 saved_city = self.main_view.grab_first_saved_city()
98 self.main_view._wait_to_stop_moving(self.main_view.get_clock_page())
98 saved_city.swipe_to_delete()99 saved_city.swipe_to_delete()
99 saved_city.confirm_removal()100 saved_city.confirm_removal()
100101
101102
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_timer.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2014-02-19 18:04:36 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2014-02-24 16:24:49 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd3# Copyright (C) 2013, 2014 Canonical Ltd
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as6# it under the terms of the GNU General Public License version 3 as
@@ -21,9 +21,8 @@
2121
22from __future__ import absolute_import22from __future__ import absolute_import
2323
24from testtools.matchers import Equals, NotEquals, Is, Not24from testtools.matchers import Equals, NotEquals
25from autopilot.matchers import Eventually25from autopilot.matchers import Eventually
26from time import sleep
2726
28from ubuntu_clock_app.tests import ClockAppTestCase27from ubuntu_clock_app.tests import ClockAppTestCase
29import logging28import logging
@@ -34,120 +33,58 @@
34class TestTimer(ClockAppTestCase):33class TestTimer(ClockAppTestCase):
35 """Tests the timer page features"""34 """Tests the timer page features"""
3635
37 """ This is needed to wait for the application to start.
38 In the testfarm, the application may take some time to show up."""
39 def setUp(self):36 def setUp(self):
37 """This is needed to wait for the application to start.
38
39 In the testfarm, the application may take some time to show up.
40
41 """
40 super(TestTimer, self).setUp()42 super(TestTimer, self).setUp()
41 self.assertThat(43 self.assertThat(
42 self.main_view.visible, Eventually(Equals(True)))44 self.main_view.visible, Eventually(Equals(True)))
4345
44 # Move to Timer tab46 self.page = self.main_view.open_timer()
45 self.main_view.switch_to_tab("TimerTab")47
4648 def test_add_timer_must_add_timer_to_presets_lists(self):
47 def delete_first_preset(self):49 """Test to check if button to add a preset working."""
48 if not(self.main_view.wideAspect):50 num_of_presets_old = self.page.get_num_of_presets()
49 self.main_view.drag_page_up("TimerPage")51 self.page.add_timer('test', set_time=True)
50
51 # Delete the preset
52 first_preset = self.main_view.get_first_preset_list_item()
53 first_preset.swipe_to_delete()
54 first_preset.confirm_removal()
55
56 def add_preset(self, setTime=0):
57 # Show the toolbar
58 self.main_view.open_toolbar()
59
60 # Click the add preset button
61 self.main_view.get_toolbar().click_button('addPresetButton')
62
63 # Set Timer label as "test"
64 if not(self.main_view.wideAspect):
65 self.main_view.drag_page_up("TimerPage")
66 label = self.main_view.get_timer_name_preset()
67 label.write("AutopilotTimer")
68 self.assertThat(label.text, Eventually(Equals("AutopilotTimer")))
69 if not(self.main_view.wideAspect):
70 self.main_view.drag_page_down("TimerPage")
71
72 if setTime:
73 # Set timer minute
74 logger.debug("Grabbing minute hand")
75 minute = self.main_view.get_timer_minute_hand()
76 timeout = 0
77
78 #need to select clock in order to set time
79 while label.focus and timeout < 10:
80 logger.debug("Timerlabel loop")
81 TimerLabel = self.main_view.get_label_timer()
82 self.pointing_device.click_object(TimerLabel)
83 sleep(1)
84 timeout += 1
85
86 #make sure timer is set
87 x, y, w, h = minute.globalRect
88 tx = x + (w / 2)
89 ty = y + (h / 2.5)
90 timeout = 0
91 reset_button = self.main_view.get_timer_reset_button()
92 logger.debug("reset_button %s" % reset_button.visible)
93
94 #Try again if we failed at first
95 while not reset_button.visible and timeout < 10:
96 logger.debug("Dragging minute hand")
97 self.pointing_device.drag(tx, ty - (h / 4), tx + (w / 2), ty + (h / 2))
98 sleep(1)
99 timeout += 1
100
101 self.main_view.open_toolbar()
102 self.main_view.get_toolbar().click_button('savePresetButton')
103
104 def test_add_preset(self):
105 """Test to check if button to add a preset working"""
106 num_of_presets_old = self.main_view.get_num_of_presets()
107 self.add_preset(1)
10852
109 # check that the timer preset has been added.53 # check that the timer preset has been added.
110 self.assertThat(54 self.assertThat(
111 self.main_view.get_num_of_presets,55 self.page.get_num_of_presets,
112 Eventually(Equals(num_of_presets_old + 1)))56 Eventually(Equals(num_of_presets_old + 1)))
11357
114 def test_run_preset(self):58 last_preset_name, _ = self.page.get_presets()[0]
115 """Tests if a preset can runs"""59 self.assertEqual('test', last_preset_name)
11660
117 # Create a new preset61 def test_run_preset_must_update_timer(self):
118 self.add_preset()62 """Tests if a preset can run."""
11963 # FIXME: Instead of always running the first preset, run the preset
120 if not(self.main_view.wideAspect):64 # which was created. To do this in a nice way, we should use the
121 self.main_view.drag_page_up("TimerPage")65 # QQuickListView but it has a bug that makes it fail in this case:
12266 # http://pad.lv/1275060 --elopio - 2014-01-31
123 # Click to select the preset67 timer_index = 0
124 # FIXME: Instead of always running the first preset, run the preset which was created68 _, initial_time = self.page.get_presets()[timer_index]
125 first_preset = self.main_view.get_first_preset_list_item()69 if not self.main_view.wideAspect:
126 self.pointing_device.click_object(first_preset)70 self.page.drag_page_up()
12771 self.page.run_preset_timer(index=timer_index)
128 if not(self.main_view.wideAspect):72
129 self.main_view.drag_page_down("TimerPage")73 self.assertThat(
13074 self.page.get_current_time, Eventually(NotEquals(initial_time)))
131 # Click to start the preset75
132 label = self.main_view.get_label_timer()76 def test_delete_preset_must_remove_from_presets_list(self):
133 self.pointing_device.click_object(label)77 """Test if the swipe of a preset deletes it."""
13478 # FIXME: Instead of always running the first preset, run the preset
135 # Check if timer is started79 # which was created. To do this in a nice way, we should use the
136 self.assertThat(label.text, Eventually(NotEquals("03:00")))80 # QQuickListView but it has a bug that makes it fail in this case:
13781 # http://pad.lv/1275060 --elopio - 2014-01-31
138 def test_delete_preset(self):82 num_of_presets_old = self.page.get_num_of_presets()
139 """Test if the swipe of a preset deletes it"""83 if not self.main_view.wideAspect:
14084 self.page.drag_page_up()
141 # Create a new preset85 self.page.delete_preset_timer(index=0)
142 self.add_preset()
143
144 num_of_presets_old = self.main_view.get_num_of_presets()
145
146 #delete preset
147 self.delete_first_preset()
14886
149 # Check that the timer preset has been deleted87 # Check that the timer preset has been deleted
150 self.assertThat(88 self.assertThat(
151 self.main_view.get_num_of_presets,89 self.page.get_num_of_presets,
152 Eventually(Equals(num_of_presets_old - 1)))90 Eventually(Equals(num_of_presets_old - 1)))
153
15491
=== modified file 'timer/PresetList.qml'
--- timer/PresetList.qml 2014-02-19 14:17:38 +0000
+++ timer/PresetList.qml 2014-02-24 16:24:49 +0000
@@ -54,7 +54,7 @@
5454
55 return Utils.zeroleft(minutes, 1) + ":" + Utils.zeroleft(seconds, 2);55 return Utils.zeroleft(minutes, 1) + ":" + Utils.zeroleft(seconds, 2);
56 }56 }
57 57
58 ListItem.ThinDivider {58 ListItem.ThinDivider {
59 id: divider59 id: divider
60 }60 }
@@ -68,15 +68,16 @@
68 fontSize: "medium"68 fontSize: "medium"
69 }69 }
70 }70 }
71 71
72 ListView {72 ListView {
73 id: listTimerPreset73 id: listTimerPreset
74 74 objectName: "listTimerPreset"
75
75 clip: true76 clip: true
76 currentIndex: -177 currentIndex: -1
77 height: maxItemsVisible * units.gu(6)78 height: maxItemsVisible * units.gu(6)
78 anchors { left: parent.left; right: parent.right }79 anchors { left: parent.left; right: parent.right }
79 80
80 delegate: ListItem.Standard {81 delegate: ListItem.Standard {
81 objectName: "preset" + index82 objectName: "preset" + index
82 Label {83 Label {
@@ -88,20 +89,20 @@
88 color: Theme.palette.normal.baseText89 color: Theme.palette.normal.baseText
89 anchors { verticalCenter: parent.verticalCenter; left: parent.left; right: presetTimeLabel.left; rightMargin: units.gu(2); leftMargin: units.gu(3) }90 anchors { verticalCenter: parent.verticalCenter; left: parent.left; right: presetTimeLabel.left; rightMargin: units.gu(2); leftMargin: units.gu(3) }
90 }91 }
91 92
92 Label {93 Label {
93 id: presetTimeLabel94 id: presetTimeLabel
94 objectName: "presetTimerLabel"95 objectName: "presetTimerLabel" + index
95 fontSize: "large"96 fontSize: "large"
96 text: getstringTimer(model.contents.duration);97 text: getstringTimer(model.contents.duration);
97 color: Theme.palette.normal.baseText98 color: Theme.palette.normal.baseText
98 anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: units.gu(2) }99 anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: units.gu(2) }
99 }100 }
100 101
101 selected: listTimerPreset.currentIndex == index102 selected: listTimerPreset.currentIndex == index
102 removable: true103 removable: true
103 confirmRemoval: true104 confirmRemoval: true
104 105
105 onItemRemoved: {106 onItemRemoved: {
106 // NOTE: This causes the document to be deleted twice resulting in an error.107 // NOTE: This causes the document to be deleted twice resulting in an error.
107 // The bug has been reported at https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1276118108 // The bug has been reported at https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1276118

Subscribers

People subscribed via source and target branches