Merge lp:~nik90/ubuntu-clock-app/13-next-alarm-bottomedge into lp:ubuntu-clock-app

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 119
Merged at revision: 135
Proposed branch: lp:~nik90/ubuntu-clock-app/13-next-alarm-bottomedge
Merge into: lp:ubuntu-clock-app
Prerequisite: lp:~nik90/ubuntu-clock-app/12-alarm-list-design-spec
Diff against target: 288 lines (+117/-15)
9 files modified
app/alarm/AlarmList.qml (+0/-4)
app/alarm/AlarmPage.qml (+2/-0)
app/alarm/AlarmUtils.qml (+44/-0)
app/clock/ClockPage.qml (+9/-2)
app/ubuntu-clock-app.qml (+1/-7)
debian/changelog (+1/-0)
tests/autopilot/ubuntu_clock_app/emulators.py (+2/-2)
tests/unit/tst_alarm.qml (+5/-0)
tests/unit/tst_alarmUtils.qml (+53/-0)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/13-next-alarm-bottomedge
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Riccardo Padovani Approve
Nekhelesh Ramananthan Needs Fixing
Review via email: mp+237188@code.launchpad.net

This proposal supersedes a proposal from 2014-10-05.

Commit message

Dynamically sets the bottom edge title with the time to the next active alarm.

Description of the change

Dynamically sets the bottom edge title with the time to the next active alarm.

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
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)
Revision history for this message
Leo Arias (elopio) wrote :

Please try to name the tests as test_someActionOrComponentMustDoOrDisplaySomething.

227 + function test_bottomEdgeTitle() {

In my opinion, that naming rule makes it clear that you have at least three tests there.

test_bottomEdgeTitleMustDisplayActiveAlarm

test_bottomEdgeTitleMustDisplayNoAlarm

test_bottomEdgeTitleMustDisplayNextAlarm

Spliting them will make the tests clearer and easier to maintain. You will also get better feedback when only one of the features is failing, because you will have one test per code path.

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

> Please try to name the tests as
> test_someActionOrComponentMustDoOrDisplaySomething.
>
> 227 + function test_bottomEdgeTitle() {
>
> In my opinion, that naming rule makes it clear that you have at least three
> tests there.
>
> test_bottomEdgeTitleMustDisplayActiveAlarm
>
> test_bottomEdgeTitleMustDisplayNoAlarm
>
> test_bottomEdgeTitleMustDisplayNextAlarm
>
> Spliting them will make the tests clearer and easier to maintain. You will
> also get better feedback when only one of the features is failing, because you
> will have one test per code path.

Wholeheartedly agree :-). Implemented in latest rev as per your comment.

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)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

#blocked on Jenkins. This requires a patch to the Jenkins environment since the xvfb package which is used to run the clock app tests takes input focus away from the clock app when it is launched. This is causing the AP tests to be pass. Francis and Nicholas have been informed. Once jenkins is fixed, we should be good to merge this branch.

review: Needs Fixing
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Looks good to me, but I left a inline comment about a better implementation of an if

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: 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)
119. By Nekhelesh Ramananthan

Fixed AP test

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 'app/alarm/AlarmList.qml'
2--- app/alarm/AlarmList.qml 2014-10-05 00:01:42 +0000
3+++ app/alarm/AlarmList.qml 2014-10-10 01:55:06 +0000
4@@ -51,10 +51,6 @@
5 clip: true
6 anchors.fill: parent
7
8- AlarmUtils {
9- id: alarmUtils
10- }
11-
12 listDelegate: AlarmDelegate {
13 id: alarmDelegate
14 objectName: "alarm" + index
15
16=== modified file 'app/alarm/AlarmPage.qml'
17--- app/alarm/AlarmPage.qml 2014-10-05 00:01:42 +0000
18+++ app/alarm/AlarmPage.qml 2014-10-10 01:55:06 +0000
19@@ -23,6 +23,8 @@
20 Page {
21 id: alarmPage
22
23+ property var alarmModel
24+
25 title: i18n.tr("Alarms")
26 objectName: 'AlarmPage'
27
28
29=== modified file 'app/alarm/AlarmUtils.qml'
30--- app/alarm/AlarmUtils.qml 2014-10-05 00:25:25 +0000
31+++ app/alarm/AlarmUtils.qml 2014-10-10 01:55:06 +0000
32@@ -50,6 +50,29 @@
33 }
34 }
35
36+ // Function to set the bottom edge title with "Next Active in..."
37+ function set_bottom_edge_title(alarmModel, clockTime) {
38+ var bottom_edge_title = i18n.tr("No active alarms")
39+
40+ /*
41+ Check if alarm model received is valid and has saved alarms and only
42+ then proceed to find the next active alarm.
43+ */
44+ if (!alarmModel || !alarmModel.count) {
45+ return bottom_edge_title
46+ }
47+
48+ var activeAlarmDate = _get_next_active_alarm(alarmModel, clockTime)
49+
50+ // Return immediately if there are no active alarms found
51+ if (!activeAlarmDate) {
52+ return bottom_edge_title
53+ }
54+
55+ bottom_edge_title = i18n.tr("Next Alarm %1").arg(get_time_to_next_alarm(activeAlarmDate - clockTime))
56+ return bottom_edge_title
57+ }
58+
59 // Function to format the time to next alarm into a string
60 function get_time_to_next_alarm(totalTime) {
61 if(totalTime < 0) {
62@@ -103,6 +126,27 @@
63 INTERNAL FUNCTIONS
64 */
65
66+ /*
67+ Function to get the next active alarm. This function ignores alarms in the
68+ past and also iteratively looks through every alarm since the alarm model
69+ does not always list the active alarms in chronological order.
70+ */
71+ function _get_next_active_alarm(alarmModel, clockTime) {
72+ var activeAlarmDate = undefined
73+
74+ for (var i=0; i<alarmModel.count; i++) {
75+ var currentAlarm = alarmModel.get(i)
76+ if (currentAlarm.enabled && currentAlarm.date > clockTime) {
77+ if (activeAlarmDate === undefined ||
78+ currentAlarm.date < activeAlarmDate) {
79+ activeAlarmDate = currentAlarm.date
80+ }
81+ }
82+ }
83+
84+ return activeAlarmDate
85+ }
86+
87 // Function to split time (in ms) into days, hours and minutes
88 function _split_time(totalTime) {
89 // increase by a minute, so we could make a nicer time
90
91=== modified file 'app/clock/ClockPage.qml'
92--- app/clock/ClockPage.qml 2014-10-03 11:55:41 +0000
93+++ app/clock/ClockPage.qml 2014-10-10 01:55:06 +0000
94@@ -17,8 +17,8 @@
95 */
96
97 import QtQuick 2.3
98-import U1db 1.0 as U1db
99 import Ubuntu.Components 1.1
100+import "../alarm"
101 import "../components"
102 import "../upstreamcomponents"
103 import "../worldclock"
104@@ -33,11 +33,18 @@
105 // Property to keep track of the clock time
106 property alias clockTime: clock.analogTime
107
108+ property var alarmModel
109+
110 flickable: null
111+ bottomEdgeTitle: alarmUtils.set_bottom_edge_title(alarmModel, clockTime)
112
113 Component.onCompleted: {
114 console.log("[LOG]: Clock Page loaded")
115- _clockPage.setBottomEdgePage(Qt.resolvedUrl("../alarm/AlarmPage.qml"), {})
116+ _clockPage.setBottomEdgePage(Qt.resolvedUrl("../alarm/AlarmPage.qml"), { alarmModel: alarmModel })
117+ }
118+
119+ AlarmUtils {
120+ id: alarmUtils
121 }
122
123 Flickable {
124
125=== modified file 'app/ubuntu-clock-app.qml'
126--- app/ubuntu-clock-app.qml 2014-10-09 16:41:18 +0000
127+++ app/ubuntu-clock-app.qml 2014-10-10 01:55:06 +0000
128@@ -21,7 +21,6 @@
129 import U1db 1.0 as U1db
130 import Ubuntu.Components 1.1
131 import "clock"
132-import "alarm"
133 import "components"
134
135 MainView {
136@@ -117,6 +116,7 @@
137 possible to receive a datetime object directly instead of using this hack.
138 */
139
140+ alarmModel: alarmModel
141 clockTime: new Date
142 (
143 localTimeSource.localDateString.split(":")[0],
144@@ -127,12 +127,6 @@
145 localTimeSource.localTimeString.split(":")[2],
146 localTimeSource.localTimeString.split(":")[3]
147 )
148-
149- /*
150- #TODO: The bottom edge title should reflect the time to the next
151- alarm. For instance it should read "Next alarm in 9h23m".
152- */
153- bottomEdgeTitle: i18n.tr("Alarms")
154 }
155 }
156 }
157
158=== modified file 'debian/changelog'
159--- debian/changelog 2014-10-09 16:44:50 +0000
160+++ debian/changelog 2014-10-10 01:55:06 +0000
161@@ -8,6 +8,7 @@
162 * Removed Unused Utils library.
163 * Design tweak to always show the remaining time to an alarm for one-time alarms
164 only. (LP: #1377538)
165+ * Tweaked bottom edge to show the time to the next active alarm (LP: #1290793)
166
167 [Akiva Shammai Avraham]
168 * Improved the analog clock performance by updating the clock hands every second
169
170=== modified file 'tests/autopilot/ubuntu_clock_app/emulators.py'
171--- tests/autopilot/ubuntu_clock_app/emulators.py 2014-10-09 21:47:45 +0000
172+++ tests/autopilot/ubuntu_clock_app/emulators.py 2014-10-10 01:55:06 +0000
173@@ -54,7 +54,7 @@
174 clockPage = self.open_clock()
175 clockPage.reveal_bottom_edge_page()
176 self.get_header().visible.wait_for(True)
177- return self.wait_select_single(Page11)
178+ return self.wait_select_single(AlarmPage)
179
180 def get_AlarmList(self):
181 """ Get the AlarmList object. """
182@@ -178,7 +178,7 @@
183 self.pointing_device.click_object(deleteButton)
184
185
186-class Page11(Page):
187+class AlarmPage(Page):
188 """Autopilot helper for the Alarm page."""
189
190 @autopilot_logging.log_action(logger.info)
191
192=== modified file 'tests/unit/tst_alarm.qml'
193--- tests/unit/tst_alarm.qml 2014-10-05 00:10:34 +0000
194+++ tests/unit/tst_alarm.qml 2014-10-10 01:55:06 +0000
195@@ -45,6 +45,10 @@
196 id: alarmModel
197 }
198
199+ AlarmUtils {
200+ id: alarmUtils
201+ }
202+
203 DateTime {
204 id: localTimeSource
205 updateInterval: 1000
206@@ -57,6 +61,7 @@
207
208 AlarmPage {
209 id: alarmPage
210+ alarmModel: alarmModel
211 }
212
213 UbuntuTestCase {
214
215=== modified file 'tests/unit/tst_alarmUtils.qml'
216--- tests/unit/tst_alarmUtils.qml 2014-10-06 21:19:45 +0000
217+++ tests/unit/tst_alarmUtils.qml 2014-10-10 01:55:06 +0000
218@@ -16,6 +16,7 @@
219 * along with this program. If not, see <http://www.gnu.org/licenses/>.
220 */
221
222+import QtQuick 2.3
223 import QtTest 1.0
224 import Ubuntu.Components 1.1
225 import "../../app/alarm"
226@@ -24,10 +25,62 @@
227 id: alarmUtilsTest
228 name: "AlarmUtilsLibrary"
229
230+ property var futureTime: new Date()
231+ property var currentTime: new Date()
232+
233 AlarmUtils {
234 id: alarmUtils
235 }
236
237+ ListModel {
238+ id: mockAlarmDatabase
239+ }
240+
241+ function initTestCase() {
242+ /*
243+ Here the alarm database is mocked by creating 2 alarms in the future.
244+ The alarm list is as follows,
245+
246+ Alarm1, currentTime+2hrs, not enabled
247+ Alarm2, currentTime+7hrs, enabled
248+ */
249+ futureTime.setHours((futureTime.getHours() + 2))
250+ mockAlarmDatabase.append({"name": "Alarm1", "date": futureTime, "enabled": false})
251+ futureTime.setHours((futureTime.getHours() + 5))
252+ mockAlarmDatabase.append({"name": "Alarm2", "date": futureTime, "enabled": true})
253+ }
254+
255+ /*
256+ This test checks if the the bottom edge title is set correctly according
257+ to the active alarms amongst other disabled alarms.
258+ */
259+ function test_bottomEdgeTitleMustDisplayActiveAlarm() {
260+ var result = alarmUtils.set_bottom_edge_title(mockAlarmDatabase, currentTime)
261+ compare(result, "Next Alarm in 7h 1m", "Bottom edge title is incorrect")
262+ }
263+
264+ /*
265+ This test checks if the bottom edge title is correctly set to "No Active
266+ Alarms" where there are no enabled alarms"
267+ */
268+ function test_bottomEdgeTitleMustDisplayNoActiveAlarm() {
269+ mockAlarmDatabase.set(1, {"enabled": false})
270+ var result = alarmUtils.set_bottom_edge_title(mockAlarmDatabase, currentTime)
271+ compare(result, "No active alarms", "Bottom edge title is not correctly set when there are no enabled alarms")
272+ mockAlarmDatabase.set(1, {"enabled": true})
273+ }
274+
275+ /*
276+ This test checks if the bottom edge title is correctly set with the next
277+ immediate active alarm amongst several active alarms"
278+ */
279+ function test_bottomEdgeTitleMustDisplayNextActiveAlarm() {
280+ mockAlarmDatabase.set(0, {"enabled": true})
281+ var result = alarmUtils.set_bottom_edge_title(mockAlarmDatabase, currentTime)
282+ compare(result, "Next Alarm in 2h 1m", "Bottom edge title is not correctly set to the next immediate active alarm where there are multiple active alarms.")
283+ mockAlarmDatabase.set(0, {"enabled": false})
284+ }
285+
286 /*
287 This test checks if the _split_time() function takes a time in milliseconds
288 and is able to split it into days, hours and minutes correctly.

Subscribers

People subscribed via source and target branches