40
41
super(TestWeekView, self).setUp()
41
42
self.week_view = self.app.main_view.go_to_week_view()
43
def _change_week(self, direction):
44
first_dow = self._get_first_day_of_week()
46
# prevent timing issues with swiping
47
old_day = self.app.main_view.to_local_date(
48
self.week_view.dayStart.datetime)
50
pathView = self.week_view.select_single("PathViewBase")
51
timeLineBase = pathView.select_single("TimeLineBaseComponent",
53
timelineview = timeLineBase.select_single(objectName="timelineview")
56
val = timelineview.contentWidth - timelineview.width
58
while timelineview.contentX != val:
59
self.app.main_view.swipe_view(direction, self.week_view)
61
self.app.main_view.swipe_view(direction, self.week_view)
62
self.assertThat(lambda:
63
self.app.main_view.to_local_date(
64
self.week_view.dayStart.datetime),
65
Eventually(NotEquals(old_day)))
67
new_day_start = self.app.main_view.to_local_date(
68
self.week_view.dayStart.datetime)
70
expected_day_start = first_dow + datetime.timedelta(
73
self.assertThat(new_day_start.day, Equals(expected_day_start.day))
75
def _get_days_of_week(self):
76
# sort based on text value of the day
77
days = sorted(self._get_date_label_headers(),
78
key=lambda label: label.text)
79
days = [int(item.text) for item in days]
81
# resort so beginning of next month comes after the end
82
# need to support overlapping months 28,30,31 -> 1
86
for index, sortday in enumerate(sorteddays):
87
if day - sorteddays[index] == 1:
88
sorteddays.insert(index + 1, day)
92
sorteddays.insert(0, day)
95
def _get_date_label_headers(self):
96
pathView = self.week_view.select_single("PathViewBase")
97
timeLineBase = pathView.select_single("TimeLineBaseComponent",
99
viewHeader = timeLineBase.select_single(objectName="viewHeader")
100
timeLineHeader = viewHeader.select_single(objectName="timelineHeader")
101
dateLabels = timeLineHeader.select_many("Label",
102
objectName="dateLabel")
105
def _get_first_day_of_week(self):
106
date = self.app.main_view.to_local_date(
107
self.week_view.dayStart.datetime)
108
firstDay = self.app.main_view.to_local_date(
109
self.week_view.firstDay.datetime)
112
if firstDay.weekday() == 6:
113
logger.debug("Locale has Sunday as first day of week")
114
weekday = date.weekday()
115
diff = datetime.timedelta(days=weekday + 1)
117
elif firstDay.weekday() == 5:
118
logger.debug("Locale has Saturday as first day of week")
119
weekday = date.weekday()
120
diff = datetime.timedelta(days=weekday + 2)
123
logger.debug("Locale has Monday as first day of week")
124
weekday = date.weekday()
125
diff = datetime.timedelta(days=weekday)
127
# set the start of week
128
if date.day != firstDay.day:
129
day_start = date - diff
130
logger.debug("Setting day_start to %s" % firstDay.day)
133
logger.debug("Using today as day_start %s" % date)
136
def test_current_month_and_year_is_selected(self):
137
"""By default, the week view shows the current month and year."""
44
def _assert_week_delta(self, original_week, delta):
45
current_week = self.week_view.get_current_weeknumber()
46
expected_week = original_week + delta
50
elif expected_week > 52:
53
self.assertEquals(current_week, expected_week)
55
def test_default_view(self):
56
"""By default, the week view shows the current week.
57
It also displays the current year and month"""
139
59
now = datetime.datetime.now()
141
60
expected_month_name_year = now.strftime("%B %Y")
143
61
self.assertThat(self.app.main_view.get_month_year(self.week_view),
144
62
Equals(expected_month_name_year))
146
def test_current_week_is_selected(self):
147
"""By default, the week view shows the current week."""
149
now = datetime.datetime.now()
150
days = self._get_days_of_week()
151
day_headers = self._get_date_label_headers()
153
first_dow = self._get_first_day_of_week()
156
current_day = days[i]
157
expected_day = (first_dow + datetime.timedelta(days=i)).day
159
self.assertThat(current_day, Equals(expected_day))
161
# current day is highlighted in white.
162
# days returned by AP are out of order, so check header and today
163
color = day_headers[i].color
164
label_color = (color[0], color[1], color[2], color[3])
165
if label_color == (255, 255, 255, 255):
166
self.assertThat(int(day_headers[i].text), Equals(now.day))
168
def test_show_next_weeks(self):
169
"""It must be possible to show next weeks by swiping the view."""
173
def test_show_previous_weeks(self):
174
"""It must be possible to show previous weeks by swiping the view."""
176
self._change_week(-1)
64
# TODO: check current day is highlighted
66
# These testing stubs need completed
67
# def test_scroll_week_must_scroll_within_week(self):
68
# """Scrolling inside the timeline should scroll the weekdays"""
71
# def test_change_week_across_month(self):
72
# """Changing week across months should update the month"""
75
# def test_change_week_across_year(self):
76
# """Changing week across years should update the year"""
79
# def test_month_to_week(self):
80
# """Changing from a month to weekview should
81
# start weekview on the first week of the month"""
84
# def test_day_to_week(self):
85
# """Changing from a day to weekview should
86
# start weekview on the same week as the day"""
89
def test_change_week(self):
90
"""It must be possible to change weeks by swiping the timeline"""
92
direction = randrange(-1, 1, 2)
93
delta = weeks * direction
94
original_week = self.week_view.get_current_weeknumber()
96
self.week_view.change_week(delta)
97
self._assert_week_delta(original_week, delta)
178
99
def test_selecting_a_day_switches_to_day_view(self):
179
100
"""It must be possible to show a single day by clicking on it."""
180
first_day_date = self.week_view.firstDay
181
# expected_day = first_day_date.day
182
expected_month = first_day_date.month
183
expected_year = first_day_date.year
185
days = self._get_days_of_week()
101
days = self.week_view.get_days_of_week()
186
102
day_to_select = self.app.main_view.get_label_with_text(days[0])
103
expected_day = days[0]
104
dayStart = self.week_view.dayStart
105
expected_month = dayStart.month
106
expected_year = dayStart.year
188
108
self.app.pointing_device.click_object(day_to_select)