Merge lp:~canonical-platform-qa/ubuntu-calendar-app/fix1351319-swipe_to_get_current_day into lp:ubuntu-calendar-app

Proposed by Leo Arias
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 385
Merged at revision: 429
Proposed branch: lp:~canonical-platform-qa/ubuntu-calendar-app/fix1351319-swipe_to_get_current_day
Merge into: lp:ubuntu-calendar-app
Prerequisite: lp:~canonical-platform-qa/ubuntu-calendar-app/fix1341681-new_toolkit_namespace
Diff against target: 179 lines (+68/-40)
3 files modified
YearView.qml (+2/-1)
tests/autopilot/calendar_app/__init__.py (+61/-2)
tests/autopilot/calendar_app/tests/test_yearview.py (+5/-37)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-calendar-app/fix1351319-swipe_to_get_current_day
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nicholas Skaggs (community) Approve
Review via email: mp+229356@code.launchpad.net

This proposal supersedes a proposal from 2014-08-03.

Commit message

On autopilot tests, if the current month does not exist on the year grid, swipe it into view.

To post a comment you must log in.
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
Nicholas Skaggs (nskaggs) wrote :

I'd like to see a jenkins run against this

383. By Leo Arias

Fixed the call to swipe.

Revision history for this message
Leo Arias (elopio) wrote :

> I'd like to see a jenkins run against this

It's on its way. I've just confirmed that the test now works on mako.

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
Nicholas Skaggs (nskaggs) wrote :

Can this apply to other swipe tests in calendar? also note https://code.launchpad.net/~nskaggs/ubuntu-calendar-app/fix-1359167/+merge/233387 which overhauls the tests (gets rid of emulators.py among other things)

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
Nicholas Skaggs (nskaggs) wrote :

Merge conflicts now since the overhaul. The python3 support landed in another branch; you'll get it when you merge trunk.

review: Needs Fixing
384. By Leo Arias

Merged with trunk.

385. By Leo Arias

Removed the merge file.

Revision history for this message
Leo Arias (elopio) wrote :

> Can this apply to other swipe tests in calendar? also note
> https://code.launchpad.net/~nskaggs/ubuntu-calendar-
> app/fix-1359167/+merge/233387 which overhauls the tests (gets rid of
> emulators.py among other things)

I merged. The tests are running now.
This only applies to swipes on the year view. And we do it only on one tests, as far as I know.

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
Nicholas Skaggs (nskaggs) wrote :

Thanks for the fix Leo!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) 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 'YearView.qml'
2--- YearView.qml 2014-08-18 16:48:54 +0000
3+++ YearView.qml 2014-09-05 15:28:43 +0000
4@@ -100,9 +100,10 @@
5
6 MonthComponent {
7 id: monthComponent
8+ objectName: "monthComponent" + index
9 showEvents: false
10 currentMonth: new Date(yearView.year, index, 1, 0, 0, 0, 0)
11-
12+
13 isYearView: true
14 anchors.fill: parent
15 anchors.margins: units.gu(0.5)
16
17=== modified file 'tests/autopilot/calendar_app/__init__.py'
18--- tests/autopilot/calendar_app/__init__.py 2014-09-05 01:20:19 +0000
19+++ tests/autopilot/calendar_app/__init__.py 2014-09-05 15:28:43 +0000
20@@ -16,14 +16,15 @@
21
22 """Calendar app autopilot helpers."""
23
24+import datetime
25 import logging
26 from time import sleep
27
28 import autopilot.logging
29+import ubuntuuitoolkit
30+from autopilot import exceptions
31 from dateutil import tz
32
33-import ubuntuuitoolkit
34-
35 from calendar_app import data
36
37
38@@ -237,6 +238,64 @@
39
40 """Autopilot helper for the Year View page."""
41
42+ def get_selected_day(self):
43+ """Return the selected day.
44+
45+ :returns: A python datetime.date object with the selected day.
46+
47+ """
48+ current_year_grid = self._get_current_year_grid()
49+ for index in range(12):
50+ month_component = self._find_month_component(
51+ current_year_grid, index)
52+ try:
53+ today = month_component.select_single(
54+ 'QQuickItem', isCurrentMonth=True, isToday=True)
55+ except exceptions.StateNotFoundError:
56+ continue
57+ else:
58+ return datetime.date(
59+ current_year_grid.year, index + 1, today.date)
60+ else:
61+ raise CalendarException(
62+ 'No day is selected on the currently visible year.')
63+
64+ def _get_current_year_grid(self):
65+ path_view_base = self.select_single(
66+ 'PathViewBase', objectName='yearPathView')
67+ return path_view_base.select_single(
68+ ubuntuuitoolkit.QQuickGridView, isCurrentItem=True)
69+
70+ def _find_month_component(self, grid, index):
71+ try:
72+ month = self._get_month_component(grid, index)
73+ except exceptions.StateNotFoundError:
74+ month = self._swipe_to_find_month_component(grid, index)
75+ if month is None:
76+ raise CalendarException('Month {} not found.'.format(index))
77+ else:
78+ return month
79+
80+ def _get_month_component(self, grid, index):
81+ return grid.select_single(
82+ 'MonthComponent',
83+ objectName='monthComponent{}'.format(index))
84+
85+ def _swipe_to_find_month_component(self, grid, index):
86+ month = None
87+ grid.swipe_to_top()
88+ while not grid.atYEnd:
89+ try:
90+ month = self._get_month_component(grid, index)
91+ except exceptions.StateNotFoundError:
92+ # FIXME do not call the private _get_containers.
93+ # Reported as bug http://pad.lv/1365674
94+ # --elopio - 2014-09-04
95+ grid.swipe_to_show_more_below(grid._get_containers())
96+ else:
97+ break
98+ return month
99+
100
101 class WeekView(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
102
103
104=== modified file 'tests/autopilot/calendar_app/tests/test_yearview.py'
105--- tests/autopilot/calendar_app/tests/test_yearview.py 2014-09-04 16:04:37 +0000
106+++ tests/autopilot/calendar_app/tests/test_yearview.py 2014-09-05 15:28:43 +0000
107@@ -24,7 +24,7 @@
108 if sys.version_info < (3,):
109 range = xrange
110
111-from datetime import datetime
112+import datetime
113 from autopilot.matchers import Eventually
114 from testtools.matchers import Equals, NotEquals
115
116@@ -41,10 +41,6 @@
117 return self.year_view.wait_select_single("QQuickGridView",
118 isCurrentItem=True)
119
120- def _get_month_grid(self):
121- current_month = self._get_current_month()
122- return current_month.select_single(objectName="monthGrid")
123-
124 def _change_year(self, direction, how_many=5):
125 current_year = self.year_view.currentYear
126
127@@ -55,25 +51,10 @@
128 lambda: self.year_view.currentYear,
129 Eventually(Equals(current_year + (i * direction))))
130
131- def _get_current_month(self):
132- now = datetime.now()
133- _current_month_name = now.strftime("%B")
134-
135- year_grid = self._get_year_grid()
136- months = year_grid.select_many("MonthComponent")
137-
138- for month in months:
139- _current_month_label = month.select_single(
140- "Label", objectName="monthLabel")
141- if _current_month_name == _current_month_label.text:
142- return month
143-
144- return None
145-
146 def test_current_year_is_default(self):
147 """The current year should be the default shown"""
148 self.assertThat(self.year_view.currentYear,
149- Equals(datetime.now().year))
150+ Equals(datetime.datetime.now().year))
151
152 def test_selecting_a_month_switch_to_month_view(self):
153 """It must be possible to select a month and open the month view."""
154@@ -109,22 +90,9 @@
155
156 def test_current_day_is_selected(self):
157 """The current day must be selected."""
158-
159- month_grid = self._get_month_grid()
160-
161- # there could actually be two labels with
162- # the current day: one is the current day of the current month,
163- # the other one is the current day of the previous or next month. Both
164- # shouldn't have the standard white color.
165- current_day_labels = month_grid.select_many(
166- "Label", text=str(datetime.now().day))
167-
168- # probably better to check the surrounding UbuntuShape object,
169- # upgrade when python-autopilot 1.4 will be available (get_parent).
170- for current_day_label in current_day_labels:
171- color = current_day_label.color
172- label_color = (color[0], color[1], color[2], color[3])
173- self.assertThat(label_color, NotEquals((255, 255, 255, 255)))
174+ selected_day = self.year_view.get_selected_day()
175+ self.assertEqual(
176+ selected_day, datetime.date.today())
177
178 def test_show_next_years(self):
179 """It must be possible to show next years by swiping the view."""

Subscribers

People subscribed via source and target branches

to status/vote changes: