Merge lp:~nik90/ubuntu-clock-app/edit-alarm-qml-tests into lp:ubuntu-clock-app

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 159
Merged at revision: 146
Proposed branch: lp:~nik90/ubuntu-clock-app/edit-alarm-qml-tests
Merge into: lp:ubuntu-clock-app
Diff against target: 476 lines (+224/-74)
7 files modified
app/alarm/AlarmList.qml (+1/-1)
app/alarm/EditAlarmPage.qml (+3/-0)
debian/changelog (+2/-0)
tests/unit/CMakeLists.txt (+6/-0)
tests/unit/ClockTestCase.qml (+93/-0)
tests/unit/tst_alarm.qml (+117/-61)
tests/unit/tst_alarmLabel.qml (+2/-12)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/edit-alarm-qml-tests
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Ubuntu Clock Developers Pending
Review via email: mp+238062@code.launchpad.net

Commit message

- Added edit alarm qml tests
- Added a test utils library which includes commonly used test functions and helps reduce code duplication

Description of the change

Added edit alarm qml tests to prevent future regressions. I also added a test utils library which includes commonly used test functions and helps reduce code duplication.

Note: I numbered the tests to ensure that create_alarm test to run first before edit_alarm test. To be honest, it shouldn't matter which order the tests are run in, but I thought it just makes sense.

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

Added a test helper libary to house commonly used test functions to avoid duplication

147. By Nekhelesh Ramananthan

removed unnecessary return statement

148. By Nekhelesh Ramananthan

Added some comments

149. By Nekhelesh Ramananthan

More code refactoring

150. By Nekhelesh Ramananthan

Updated debian changelog

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
Leo Arias (elopio) wrote :
Download full text (3.1 KiB)

85 + Usage:
86 + Utils {
87 + id: testUtils
88 + }

I find it weird to import the test utilities this way. Is it a common practice in QML?
I'm wondering if this would be better as the parent test case. Name the file ClockTestCase.qml, and then instead of UbuntuTestCase, you make all your tests extend ClockTestCase.
That has some downsides, because we will be making something like an inheritance hierarchy, which sometimes is bad. What you have here is more like composition, but feels weird because of the declarative paradigm. I'm not sure, just throwing the idea here. Feel free to do it however you think it's best.

102 + testUtils._pressHeaderButton(header, "addAlarmAction")

You have a typo here. Now it doesn't have the leading underscore.

144 + // Click on the clear button shown on the right
145 + mouseClick(textfield, textfield.width - units.gu(2), centerOf(textfield).y)

Wouldn't it be better to find the clear button and then click its center? It should have an objectName.

230 + function _confirmListItemValue(page, objectName, expectedValue, message) {

Instead of confirm, we generally use the word "assert". check or compare also sound better than confirm to me.

321 + compare(Qt.formatTime(alarmTimePicker.date), oldtime, "Time read from the saved alarm is incorrect")
324 + _confirmListItemValue(addAlarmPage, "alarmRepeat", oldrepeat, "Alarm repeat options read from the saved alarm is incorrect")
332 + _confirmListItemValue(addAlarmPage, "alarmLabel", oldlabel, "Alarm name read from the saved alarm is incorrect")
340 + _confirmListItemValue(addAlarmPage, "alarmSound", "Celestial", "Alarm sound read from the saved alarm is incorrect")

Generally, you shouldn't do assertions in the middle of the test steps. Why would the alarm now have an incorrect value? If you have a test that makes sure that the alarm was created correctly where you are already doing these assertions, there's no need to repeat them here. We can assume that the alarm creation is a tested unit of code that will always work. If you haven't done those assertions on a previous test or you can't rely on the alarm creation tests to fail if some of your assumptions for this test break, then you need to work a little more on the alarm creation tests.

391 + #NOTE: This wait is required since as per the design after an alarm is edited and saved
[...]

Awesome, great comment! Bonus points.

403 + _deleteAlarm("Alarm Edited", "Weekends", Qt.formatTime(newDate), true)

I saw this on a previous branch but forgot to comment about it. There's a chance that it won't run, if a previous step fails. So you could end up with an alarm that affects the rest of the tests. As we don't have an addCleanup in QML tests, is there an easy way to delete all the existing alarms (if any) on the cleanup function?
Or, are you planning to mock the alarm data in the short term, so is it better to spend the time doing the mock instead of improving the cleanup?

This looks great. As always, many things are just opinions so feel free to disagree. I just would like to see the typo fixed; and the assertions at the end of a test instead of in the middle of the steps. That is, unless you have a good reason to do...

Read more...

review: Needs Fixing
151. By Nekhelesh Ramananthan

Renamed Utils to ClockTestCase and made test case derive from that class

152. By Nekhelesh Ramananthan

Fixed example comment in ClockTestCase

153. By Nekhelesh Ramananthan

removed QtTest and UbuntuTestCase imports in test files since it is already done by ClockTestCase

154. By Nekhelesh Ramananthan

Improved clear text field function and removed the hacky way of clearing textfields

155. By Nekhelesh Ramananthan

renamed confirm listvalue and confirm alarm creation functions to assert as recommended by elopio

156. By Nekhelesh Ramananthan

explained better why the alarm values are verified during the edit alarm test

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :
Download full text (4.1 KiB)

@elopio, thnx a lot for the detailed review. All the points you raised were very valuable and I have addressed them in the later revisions.

> 85 + Usage:
> 86 + Utils {
> 87 + id: testUtils
> 88 + }
>
> I find it weird to import the test utilities this way. Is it a common practice
> in QML?
> I'm wondering if this would be better as the parent test case. Name the file
> ClockTestCase.qml, and then instead of UbuntuTestCase, you make all your tests
> extend ClockTestCase.
> That has some downsides, because we will be making something like an
> inheritance hierarchy, which sometimes is bad. What you have here is more like
> composition, but feels weird because of the declarative paradigm. I'm not
> sure, just throwing the idea here. Feel free to do it however you think it's
> best.

Excellent Idea! To be honest I am unable to think why I chose the Utils{} approach rather than extending the UbuntuTestCase{} to ClockTestCase{}.

> 144 + // Click on the clear button shown on the right
> 145 + mouseClick(textfield, textfield.width - units.gu(2),
> centerOf(textfield).y)
>
> Wouldn't it be better to find the clear button and then click its center? It
> should have an objectName.
>

I swear I looked at the Ubuntu SDK qml test case and couldn't find it earlier. But today I found it after some more digging. Hmm with AP tests this all was written by you, while in QML I am essentially rewriting the SDK Qml Test helpers for clock app from scratch ;)

> 230 + function _confirmListItemValue(page, objectName, expectedValue,
> message) {
>
> Instead of confirm, we generally use the word "assert". check or compare also
> sound better than confirm to me.
>
> 321 + compare(Qt.formatTime(alarmTimePicker.date), oldtime, "Time read
> from the saved alarm is incorrect")
> 324 + _confirmListItemValue(addAlarmPage, "alarmRepeat", oldrepeat, "Alarm
> repeat options read from the saved alarm is incorrect")
> 332 + _confirmListItemValue(addAlarmPage, "alarmLabel", oldlabel, "Alarm
> name read from the saved alarm is incorrect")
> 340 + _confirmListItemValue(addAlarmPage, "alarmSound", "Celestial",
> "Alarm sound read from the saved alarm is incorrect")
>
> Generally, you shouldn't do assertions in the middle of the test steps. Why
> would the alarm now have an incorrect value? If you have a test that makes
> sure that the alarm was created correctly where you are already doing these
> assertions, there's no need to repeat them here. We can assume that the alarm
> creation is a tested unit of code that will always work. If you haven't done
> those assertions on a previous test or you can't rely on the alarm creation
> tests to fail if some of your assumptions for this test break, then you need
> to work a little more on the alarm creation tests.

I renamed the functions to assert..() and also explained why those assert statement are required. I am essentially try to prevent bug 1338697 from happening again. While Bug 1338697 was certainly due to an upstream revision, it affected clock app and should be detected appropriately by our qml tests. Call me paranoid when it comes to testing alarm functionality.

>
> 403 ...

Read more...

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

merged trunk

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
Leo Arias (elopio) wrote :

nik90: now the usage comment of ClockTestCase is not accurate.
on line 82 it says Utils.qml. On line 86 it says UbuntuTestCase.
I'm leaving my approval on that one, but please make the changes to the comments.

review: Approve
158. By Nekhelesh Ramananthan

Fixed ClockTestCase description

159. By Nekhelesh Ramananthan

Fixed another typo

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 15:33:27 +0000
3+++ app/alarm/AlarmList.qml 2014-10-14 16:01:40 +0000
4@@ -129,7 +129,7 @@
5
6 else {
7 pageStack.push(Qt.resolvedUrl("EditAlarmPage.qml"),
8- {"isNewAlarm": false, "alarmIndex": index})
9+ {isNewAlarm: false, alarmIndex: index, alarmModel: alarmModel})
10 }
11 }
12
13
14=== modified file 'app/alarm/EditAlarmPage.qml'
15--- app/alarm/EditAlarmPage.qml 2014-10-10 19:58:49 +0000
16+++ app/alarm/EditAlarmPage.qml 2014-10-14 16:01:40 +0000
17@@ -37,6 +37,9 @@
18 // Temporary alarm used to read saved alarm and modify them
19 property var tempAlarm
20
21+ // Property to store the alarm model
22+ property var alarmModel
23+
24 title: isNewAlarm ? i18n.tr("New alarm") : i18n.tr("Edit alarm")
25 visible: false
26
27
28=== modified file 'debian/changelog'
29--- debian/changelog 2014-10-11 18:41:14 +0000
30+++ debian/changelog 2014-10-14 16:01:40 +0000
31@@ -12,6 +12,8 @@
32 * Synced ListItemWithActions with upstream
33 * Delayed loading of AlarmModel to improve app startup time (LP: #1362140)
34 * Fixed alarm page header width warning and corrected icon spacing.
35+ * Added edit alarm qml tests and added a library helper which contains commonly
36+ used test functions to avoid code duplication in future tests.
37 * Delayed loading of xmltimezone model until add world city page is loaded and
38 dynamically load/unload the jsontimezone model only when necessary.
39
40
41=== modified file 'tests/unit/CMakeLists.txt'
42--- tests/unit/CMakeLists.txt 2014-10-05 21:22:25 +0000
43+++ tests/unit/CMakeLists.txt 2014-10-14 16:01:40 +0000
44@@ -42,3 +42,9 @@
45 tst_alarmUtils.qml
46 )
47 add_custom_target(tst_QmlFiles ALL SOURCES ${QML_TST_FILES})
48+
49+set(QML_TST_UTILS
50+ ClockTestCase.qml
51+)
52+
53+add_custom_target(tst_Utils ALL SOURCES ${QML_TST_UTILS})
54
55=== added file 'tests/unit/ClockTestCase.qml'
56--- tests/unit/ClockTestCase.qml 1970-01-01 00:00:00 +0000
57+++ tests/unit/ClockTestCase.qml 2014-10-14 16:01:40 +0000
58@@ -0,0 +1,93 @@
59+/*
60+ * Copyright (C) 2014 Canonical Ltd
61+ *
62+ * This file is part of Ubuntu Clock App
63+ *
64+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
65+ * it under the terms of the GNU General Public License version 3 as
66+ * published by the Free Software Foundation.
67+ *
68+ * Ubuntu Clock App is distributed in the hope that it will be useful,
69+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
70+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71+ * GNU General Public License for more details.
72+ *
73+ * You should have received a copy of the GNU General Public License
74+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
75+ */
76+
77+import QtTest 1.0
78+import QtQuick 2.3
79+import Ubuntu.Test 1.0
80+
81+/*
82+ ClockTestCase extends UbuntuTestCase with a set of commonly used test functions
83+ like pressing header buttons and help reduce code duplication. Ideally several
84+ of these functions can be pushed upstream into the Ubuntu SDK. That should happen
85+ as when time permits.
86+
87+ Usage:
88+ ClockTestCase {
89+ id: sampleTest
90+ name: "SampleTest"
91+
92+ when: windowShown
93+
94+ function initTestCase() {
95+ header = findChild(mainView, "MainView_Header")
96+ backButton = findChild(alarmTest.header, "customBackButton")
97+ }
98+
99+ function test_something() {
100+ pressHeaderButton(header, "addAlarmAction")
101+ }
102+ }
103+*/
104+
105+UbuntuTestCase {
106+ id: testUtils
107+
108+ function pressHeaderButton(header, objectName) {
109+ var headerButton = findChild(header, objectName + "_header_button")
110+ mouseClick(headerButton, centerOf(headerButton).x, centerOf(headerButton).y)
111+ }
112+
113+ function pressButton(objectName) {
114+ mouseClick(objectName, centerOf(objectName).x, centerOf(objectName).y)
115+ }
116+
117+ function getPage(pageStack, objectName) {
118+ var page = findChild(pageStack, objectName)
119+ waitForRendering(page)
120+ return page
121+ }
122+
123+ function swipeToDeleteItem(item)
124+ {
125+ var startX = item.threshold
126+ var startY = item.height / 2
127+ var endX = item.width
128+ var endY = startY
129+ mousePress(item, startX, startY)
130+ mouseMoveSlowly(item,
131+ startX, startY,
132+ endX - startX, endY - startY,
133+ 10, 100)
134+ mouseRelease(item, endX, endY)
135+ mouseClick(item, startX, startY)
136+ }
137+
138+ function clearTextField(textfield) {
139+ var clearButton = findChild(textfield, "clear_button")
140+ /*
141+ This check is required since if the textfield is read-only or does
142+ not have input focus then the clearButton may not be shown resulting
143+ in the text field not being cleared.
144+ */
145+ if (clearButton.visible) {
146+ pressButton(clearButton)
147+ } else {
148+ console.log("Clear Button not visible. Hence textfield cannot be cleared.")
149+ }
150+ }
151+}
152
153=== modified file 'tests/unit/tst_alarm.qml'
154--- tests/unit/tst_alarm.qml 2014-10-10 21:24:28 +0000
155+++ tests/unit/tst_alarm.qml 2014-10-14 16:01:40 +0000
156@@ -17,9 +17,7 @@
157 */
158
159 import QtQuick 2.3
160-import QtTest 1.0
161 import DateTime 1.0
162-import Ubuntu.Test 1.0
163 import Ubuntu.Components 1.1
164 import "../../app/alarm"
165
166@@ -63,7 +61,7 @@
167 id: alarmPage
168 }
169
170- UbuntuTestCase {
171+ ClockTestCase {
172 id: alarmTest
173 name: "AlarmTest"
174
175@@ -79,31 +77,11 @@
176
177 // ************* Helper Functions ************
178
179- function _pressAddAlarmHeaderButton() {
180- var addButton = findChild(header, "addAlarmAction" + "_header_button")
181- mouseClick(addButton, centerOf(addButton).x, centerOf(addButton).y)
182- }
183-
184- function _pressSaveAlarmHeaderButton() {
185- var saveButton = findChild(alarmTest.header, "saveAlarmAction" + "_header_button")
186- mouseClick(saveButton, centerOf(saveButton).x, centerOf(saveButton).y)
187- }
188-
189- function _pressBackButton() {
190- mouseClick(backButton, centerOf(backButton).x, centerOf(backButton).y)
191- }
192-
193 function _pressListItem(page, objectName) {
194 var listitem = findChild(page, objectName)
195 mouseClick(listitem, centerOf(listitem).x, centerOf(listitem).y)
196 }
197
198- function _getPage(objectName) {
199- var page = findChild(pageStack, objectName)
200- waitForRendering(page)
201- return page
202- }
203-
204 function _waitForPickerToStopMoving(picker) {
205 waitForRendering(picker);
206 tryCompareFunction(function(){return picker.moving}, false);
207@@ -112,7 +90,6 @@
208 function _setAlarmTime(picker, time) {
209 picker.date = time
210 _waitForPickerToStopMoving(picker)
211- return picker.date
212 }
213
214 function _setAlarmRepeatDays(alarmRepeatPage, days) {
215@@ -136,8 +113,7 @@
216
217 function _setAlarmLabel(alarmLabelPage, label) {
218 var alarmLabel = findChild(alarmLabelPage, "labelEntry")
219- mouseClick(alarmLabel, alarmLabel.width - units.gu(2), centerOf(alarmLabel).y)
220- mouseClick(alarmLabel, alarmLabel.width - units.gu(2), centerOf(alarmLabel).y)
221+ clearTextField(alarmLabel)
222 typeString(label)
223 }
224
225@@ -167,25 +143,15 @@
226 return -1;
227 }
228
229- function _confirmAlarmCreation(label, repeat, time, status) {
230+ function _assertAlarmCreation(label, repeat, time, status) {
231 if (findAlarm(label, repeat, time, status) === -1) {
232 fail("No Alarm found with the specified characteristics")
233 }
234 }
235
236- function _swipeToDeleteItem(item)
237- {
238- var startX = item.threshold
239- var startY = item.height / 2
240- var endX = item.width
241- var endY = startY
242- mousePress(item, startX, startY)
243- mouseMoveSlowly(item,
244- startX, startY,
245- endX - startX, endY - startY,
246- 10, 100)
247- mouseRelease(item, endX, endY)
248- mouseClick(item, startX, startY)
249+ function _assertListItemValue(page, objectName, expectedValue, message) {
250+ var listitem = findChild(page, objectName)
251+ compare(listitem.subText, expectedValue, message)
252 }
253
254 function _deleteAlarm(label, repeat, time, status) {
255@@ -196,50 +162,108 @@
256 var alarmObject = findChild(alarmsList, "alarm"+index)
257
258 if (index !== -1) {
259- _swipeToDeleteItem(alarmObject)
260+ swipeToDeleteItem(alarmObject)
261 }
262
263 tryCompare(alarmsList, "count", oldCount-1, 10000, "Alarm count did not decrease after deleting the alarm")
264 }
265
266 function _setAlarm(label, repeat, time) {
267- _pressAddAlarmHeaderButton()
268+ pressHeaderButton(header, "addAlarmAction")
269
270 var addAlarmPage = findChild(pageStack, "AddAlarmPage")
271 waitForRendering(addAlarmPage)
272
273+ // Set the alarm time
274 var alarmTimePicker = findChild(pageStack, "alarmTime")
275- var date = _setAlarmTime(alarmTimePicker, time)
276+ _setAlarmTime(alarmTimePicker, time)
277
278+ // Set the alarm repeat options
279 _pressListItem(addAlarmPage, "alarmRepeat")
280- var alarmRepeatPage = _getPage("alarmRepeatPage")
281+ var alarmRepeatPage = getPage(pageStack, "alarmRepeatPage")
282 _setAlarmRepeatDays(alarmRepeatPage, repeat)
283- _pressBackButton()
284+ pressButton(backButton)
285
286 waitForRendering(addAlarmPage)
287
288+ // Set the alarm label
289 _pressListItem(addAlarmPage, "alarmLabel")
290- var alarmLabelPage = _getPage("alarmLabelPage")
291+ var alarmLabelPage = getPage(pageStack, "alarmLabelPage")
292 _setAlarmLabel(alarmLabelPage, label)
293- _pressBackButton()
294-
295- waitForRendering(addAlarmPage)
296-
297- _pressListItem(addAlarmPage, "alarmSound")
298- var alarmSoundPage = _getPage("alarmSoundPage")
299- _setAlarmSound(alarmSoundPage)
300- _pressBackButton()
301-
302- waitForRendering(addAlarmPage)
303-
304- _pressSaveAlarmHeaderButton()
305+ pressButton(backButton)
306+
307+ waitForRendering(addAlarmPage)
308+
309+ // Set the alarm sound
310+ _pressListItem(addAlarmPage, "alarmSound")
311+ var alarmSoundPage = getPage(pageStack, "alarmSoundPage")
312+ _setAlarmSound(alarmSoundPage)
313+ pressButton(backButton)
314+
315+ waitForRendering(addAlarmPage)
316+
317+ pressHeaderButton(header, "saveAlarmAction")
318+
319+ waitForRendering(alarmPage)
320+ }
321+
322+ function _editAlarm(oldlabel, oldrepeat, oldtime, status, newlabel, newrepeat, newtime) {
323+ // Find the index of the alarm which needs to be edited
324+ var alarmIndex = findAlarm(oldlabel, oldrepeat, oldtime, status)
325+
326+ if (alarmIndex === -1) {
327+ fail("Cannot find saved alarm to edit")
328+ }
329+
330+ // Press the alarm to be edited
331+ var alarmsList = findChild(alarmPage, "alarmListView")
332+ var alarmObject = findChild(alarmsList, "alarm"+alarmIndex)
333+ mouseClick(alarmObject, centerOf(alarmObject).x, centerOf(alarmObject).y)
334+
335+ /*
336+ Proceed to verify the alarm read is correct and then set new values.
337+ The values are verified after the alarm is read from the alarm model
338+ to prevent regressions like http://pad.lv/1338697 in the future.
339+ */
340+ var addAlarmPage = findChild(pageStack, "AddAlarmPage")
341+ waitForRendering(addAlarmPage)
342+
343+ var alarmTimePicker = findChild(pageStack, "alarmTime")
344+ compare(Qt.formatTime(alarmTimePicker.date), oldtime, "Time read from the saved alarm is incorrect")
345+ _setAlarmTime(alarmTimePicker, newtime)
346+
347+ _assertListItemValue(addAlarmPage, "alarmRepeat", oldrepeat, "Alarm repeat options read from the saved alarm is incorrect")
348+ _pressListItem(addAlarmPage, "alarmRepeat")
349+ var alarmRepeatPage = getPage(pageStack, "alarmRepeatPage")
350+ _setAlarmRepeatDays(alarmRepeatPage, newrepeat)
351+ pressButton(backButton)
352+
353+ waitForRendering(addAlarmPage)
354+
355+ _assertListItemValue(addAlarmPage, "alarmLabel", oldlabel, "Alarm name read from the saved alarm is incorrect")
356+ _pressListItem(addAlarmPage, "alarmLabel")
357+ var alarmLabelPage = getPage(pageStack, "alarmLabelPage")
358+ _setAlarmLabel(alarmLabelPage, newlabel)
359+ pressButton(backButton)
360+
361+ waitForRendering(addAlarmPage)
362+
363+ _assertListItemValue(addAlarmPage, "alarmSound", "Celestial", "Alarm sound read from the saved alarm is incorrect")
364+ _pressListItem(addAlarmPage, "alarmSound")
365+ var alarmSoundPage = getPage(pageStack, "alarmSoundPage")
366+ _setAlarmSound(alarmSoundPage)
367+ pressButton(backButton)
368+
369+ waitForRendering(addAlarmPage)
370+
371+ pressHeaderButton(header, "saveAlarmAction")
372
373 waitForRendering(alarmPage)
374 }
375
376 // ************* Test Functions ************
377
378- function test_createAlarm_data() {
379+ function test_01_createAlarm_data() {
380 return [
381 {tag: "Weekday Alarms", name: "Weekday Alarm", repeat: [0,1,2,3,4], repeatLabel: "Weekdays"},
382 {tag: "Weekend Alarms", name: "Weekend Alarm", repeat: [5,6], repeatLabel: "Weekends"},
383@@ -248,14 +272,14 @@
384 }
385
386 // Test to check if creating an alarm works as expected
387- function test_createAlarm(data) {
388+ function test_01_createAlarm(data) {
389 var date = new Date()
390 date.setHours((date.getHours() + 10) % 24)
391 date.setMinutes((date.getMinutes() + 40) % 60)
392 date.setSeconds(0)
393
394 _setAlarm(data.name, data.repeat, date)
395- _confirmAlarmCreation(data.name, data.repeatLabel, Qt.formatTime(date), true)
396+ _assertAlarmCreation(data.name, data.repeatLabel, Qt.formatTime(date), true)
397
398 /*
399 #FIXME: This won't be required once we mock up alarm data. Until
400@@ -263,5 +287,37 @@
401 */
402 _deleteAlarm(data.name, data.repeatLabel, Qt.formatTime(date), true)
403 }
404+
405+ // Test to check if editing an alarm and saving it works as expected
406+ function test_02_editAlarm() {
407+ var date = new Date()
408+ date.setHours((date.getHours() + 10) % 24)
409+ date.setMinutes((date.getMinutes() + 40) % 60)
410+ date.setSeconds(0)
411+
412+ _setAlarm("Test Edit Alarm", [0,1,2,3,4], date)
413+
414+ var newDate = new Date()
415+ newDate.setHours((newDate.getHours() + 5) % 24)
416+ newDate.setMinutes((newDate.getMinutes() + 15) % 60)
417+ newDate.setSeconds(0)
418+
419+ _editAlarm("Test Edit Alarm", "Weekdays", Qt.formatTime(date), true, "Alarm Edited", [5,6], newDate)
420+
421+ /*
422+ #NOTE: This wait is required since as per the design after an alarm is edited and saved
423+ it shows the remaining time to that alarm and then after 5 secs shows the alarm
424+ frequency. Hence we need to wait for 5 seconds before confirming alarm creation.
425+ */
426+ wait(6000)
427+
428+ _assertAlarmCreation("Alarm Edited", "Weekends", Qt.formatTime(newDate), true)
429+
430+ /*
431+ #FIXME: This won't be required once we mock up alarm data. Until
432+ then we need to delete alarms to cleanup after the tests.
433+ */
434+ _deleteAlarm("Alarm Edited", "Weekends", Qt.formatTime(newDate), true)
435+ }
436 }
437 }
438
439=== modified file 'tests/unit/tst_alarmLabel.qml'
440--- tests/unit/tst_alarmLabel.qml 2014-09-25 11:14:24 +0000
441+++ tests/unit/tst_alarmLabel.qml 2014-10-14 16:01:40 +0000
442@@ -16,9 +16,7 @@
443 * along with this program. If not, see <http://www.gnu.org/licenses/>.
444 */
445
446-import QtQuick 2.0
447-import QtTest 1.0
448-import Ubuntu.Test 1.0
449+import QtQuick 2.3
450 import Ubuntu.Components 1.1
451 import "../../app/alarm"
452
453@@ -38,7 +36,7 @@
454 alarm: _alarm
455 }
456
457- UbuntuTestCase {
458+ ClockTestCase {
459 id: alarmLabelPageTest
460 name: "AlarmLabelPage"
461
462@@ -55,14 +53,6 @@
463 backButton = findChild(header, "customBackButton")
464 }
465
466- function clearTextField(textfield) {
467- // Get textfield focus by clicking once
468- mouseClick(textfield, textfield.width - units.gu(2), textfield.height/2)
469-
470- // Click on the clear button shown on the right
471- mouseClick(textfield, textfield.width - units.gu(2), textfield.height/2)
472- }
473-
474 /*
475 Test to check if the alarm label has focus true by default to ensure
476 that the OSK is shown when the opens the alarm label page.

Subscribers

People subscribed via source and target branches