Merge lp:~acerisara/ubuntu-calendar-app/week-view-autopilot into lp:ubuntu-calendar-app

Proposed by Andrea Cerisara
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 163
Merged at revision: 163
Proposed branch: lp:~acerisara/ubuntu-calendar-app/week-view-autopilot
Merge into: lp:ubuntu-calendar-app
Diff against target: 211 lines (+119/-13)
6 files modified
HeaderDateComponent.qml (+1/-0)
WeekView.qml (+1/-0)
calendar.qml (+1/-0)
tests/autopilot/calendar_app/emulators.py (+11/-0)
tests/autopilot/calendar_app/tests/test_weekview.py (+98/-0)
tests/autopilot/calendar_app/tests/test_yearview.py (+7/-13)
To merge this branch: bzr merge lp:~acerisara/ubuntu-calendar-app/week-view-autopilot
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+192952@code.launchpad.net

Commit message

Autopilot tests for the weekly view.

Description of the change

Autopilot tests for the weekly 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: Approve (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Wonderful, thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HeaderDateComponent.qml'
2--- HeaderDateComponent.qml 2013-09-28 09:37:52 +0000
3+++ HeaderDateComponent.qml 2013-10-28 21:19:43 +0000
4@@ -26,6 +26,7 @@
5
6 Label{
7 id: dateLabel
8+ objectName: "dateLabel"
9 text: date.getDate();
10 fontSize: "large"
11 horizontalAlignment: Text.AlignHCenter
12
13=== modified file 'WeekView.qml'
14--- WeekView.qml 2013-09-28 09:37:52 +0000
15+++ WeekView.qml 2013-10-28 21:19:43 +0000
16@@ -20,6 +20,7 @@
17
18 TimeLineHeader{
19 id: weekHeader
20+ objectName: "weekHeader"
21 type: typeWeek
22 date: weekViewPath.weekStart
23 }
24
25=== modified file 'calendar.qml'
26--- calendar.qml 2013-10-22 17:32:19 +0000
27+++ calendar.qml 2013-10-28 21:19:43 +0000
28@@ -266,6 +266,7 @@
29 }
30 }
31 Tab{
32+ objectName: "weekTab"
33 title: i18n.tr("Week")
34 page: Page{
35 anchors.fill: parent
36
37=== modified file 'tests/autopilot/calendar_app/emulators.py'
38--- tests/autopilot/calendar_app/emulators.py 2013-10-13 18:26:25 +0000
39+++ tests/autopilot/calendar_app/emulators.py 2013-10-28 21:19:43 +0000
40@@ -28,6 +28,9 @@
41 def get_day_view(self):
42 return self.select_single("DayView")
43
44+ def get_week_view(self):
45+ return self.select_single("WeekView")
46+
47 def get_label_with_text(self, text, root=None):
48 if root is None:
49 root = self
50@@ -85,3 +88,11 @@
51 x_stop = view.globalRect[0] + view.globalRect[2] * stop
52
53 self.pointing_device.drag(x_start, y_line, x_stop, y_line)
54+
55+ def get_year(self, component):
56+ return int(component.select_single(
57+ "Label", objectName="yearLabel").text)
58+
59+ def get_month_name(self, component):
60+ return component.select_single(
61+ "Label", objectName="monthLabel").text
62
63=== added file 'tests/autopilot/calendar_app/tests/test_weekview.py'
64--- tests/autopilot/calendar_app/tests/test_weekview.py 1970-01-01 00:00:00 +0000
65+++ tests/autopilot/calendar_app/tests/test_weekview.py 2013-10-28 21:19:43 +0000
66@@ -0,0 +1,98 @@
67+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
68+# Copyright 2013 Canonical
69+#
70+# This program is free software: you can redistribute it and/or modify it
71+# under the terms of the GNU General Public License version 3, as published
72+# by the Free Software Foundation.
73+
74+"""
75+Calendar app autopilot tests for the week view.
76+"""
77+
78+import calendar
79+import datetime
80+
81+from autopilot.matchers import Eventually
82+from testtools.matchers import Equals, NotEquals
83+
84+from calendar_app.tests import CalendarTestCase
85+
86+
87+class TestWeekView(CalendarTestCase):
88+
89+ def setUp(self):
90+ super(TestWeekView, self).setUp()
91+ self.assertThat(self.main_view.visible, Eventually(Equals(True)))
92+ self.main_view.switch_to_tab("weekTab")
93+
94+ self.assertThat(
95+ self.main_view.get_week_view, Eventually(NotEquals(None)))
96+
97+ self.week_view = self.main_view.get_week_view()
98+
99+ def test_current_month_and_year_is_selected(self):
100+ """By default, the week view shows the current month and year."""
101+
102+ now = datetime.datetime.now()
103+
104+ expected_year = now.year
105+ expected_month_name = now.strftime("%B")
106+
107+ self.assertThat(self.main_view.get_year(self.week_view),
108+ Equals(expected_year))
109+
110+ self.assertThat(self.main_view.get_month_name(self.week_view),
111+ Equals(expected_month_name))
112+
113+ def test_current_week_is_selected(self):
114+ """By default, the week view shows the current week."""
115+
116+ now = datetime.datetime.now()
117+ days = self.get_days_of_week()
118+ monday = (now - datetime.timedelta(days=now.weekday())).day
119+ current_month_days = calendar.monthrange(now.year, now.month)[1]
120+
121+ for i in xrange(7):
122+ current_day = int(days[i].text)
123+ expected_day = (monday + i) % current_month_days
124+
125+ if (monday + i) == current_month_days:
126+ expected_day = current_month_days
127+
128+ self.assertThat(current_day, Equals(expected_day))
129+
130+ color = days[i].color
131+ # current day is highlighted in white.
132+ if(current_day == now.day):
133+ label_color = (color[0], color[1], color[2], color[3])
134+ self.assertThat(label_color, Equals((255, 255, 255, 255)))
135+
136+ def test_show_next_weeks(self):
137+ """It must be possible to show next weeks by swiping the view."""
138+ self.change_week(1)
139+
140+ def test_show_previous_weeks(self):
141+ """It must be possible to show previous weeks by swiping the view."""
142+ self.change_week(-1)
143+
144+ def change_week(self, direction):
145+ now = datetime.datetime.now()
146+ current_day_start = (now - datetime.timedelta(days=now.weekday()))
147+
148+ for i in xrange(1, 5):
149+ self.main_view.swipe_view(direction, self.week_view, x_pad=0.15)
150+ day_start = datetime.datetime.fromtimestamp(
151+ self.week_view.dayStart)
152+
153+ expected_day_start = current_day_start + datetime.timedelta(
154+ days=(i * 7 * direction))
155+
156+ expected_day_start = expected_day_start.replace(
157+ hour=0, minute=0, second=0, microsecond=0)
158+
159+ self.assertThat(day_start, Equals(expected_day_start))
160+
161+ def get_days_of_week(self):
162+ header = self.main_view.select_single(objectName="weekHeader")
163+ timeline = header.select_many("TimeLineHeaderComponent")[1]
164+ return timeline.select_many("Label", objectName="dateLabel")
165
166=== modified file 'tests/autopilot/calendar_app/tests/test_yearview.py'
167--- tests/autopilot/calendar_app/tests/test_yearview.py 2013-10-22 17:53:04 +0000
168+++ tests/autopilot/calendar_app/tests/test_yearview.py 2013-10-28 21:19:43 +0000
169@@ -35,8 +35,8 @@
170 self.assert_current_year_is_default_one(months[0])
171
172 february = months[1]
173- expected_month_name = self.get_month_name(february)
174- expected_year = self.get_year(february)
175+ expected_month_name = self.main_view.get_month_name(february)
176+ expected_year = self.main_view.get_year(february)
177
178 self.pointing_device.click_object(february)
179
180@@ -47,8 +47,10 @@
181 self.assertThat(month_view.visible, Eventually(Equals(True)))
182 selected_month = month_view.select_many("MonthComponent")[1]
183
184- self.assertThat(self.get_year(selected_month), Equals(expected_year))
185- self.assertThat(self.get_month_name(selected_month),
186+ self.assertThat(self.main_view.get_year(selected_month),
187+ Equals(expected_year))
188+
189+ self.assertThat(self.main_view.get_month_name(selected_month),
190 Equals(expected_month_name))
191
192 def test_current_day_is_selected(self):
193@@ -88,17 +90,9 @@
194 selected_year, Equals(current_year + (i * direction)))
195
196 def assert_current_year_is_default_one(self, month_component):
197- self.assertThat(self.get_year(month_component),
198+ self.assertThat(self.main_view.get_year(month_component),
199 Equals(datetime.now().year))
200
201- def get_year(self, month_component):
202- return int(month_component.select_single(
203- "Label", objectName="yearLabel").text)
204-
205- def get_month_name(self, month_component):
206- return month_component.select_single(
207- "Label", objectName="monthLabel").text
208-
209 def months_from_selected_year(self):
210 # TODO: the component indexed at 1 is the one currently displayed,
211 # investigate a way to validate this assumption visually.

Subscribers

People subscribed via source and target branches

to status/vote changes: