File: ClockTestCase.qml

package info (click to toggle)
lomiri-clock-app 4.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,788 kB
  • sloc: cpp: 1,600; python: 732; javascript: 74; sh: 55; makefile: 16
file content (93 lines) | stat: -rw-r--r-- 2,968 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (C) 2014-2016 Canonical Ltd.
 *
 * This file is part of Lomiri Clock App
 *
 * Lomiri Clock App is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * Lomiri Clock App is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtTest 1.0
import QtQuick 2.12
import Lomiri.Test 1.0

/*
 ClockTestCase extends LomiriTestCase with a set of commonly used test functions
 like pressing header buttons and help reduce code duplication. Ideally several
 of these functions can be pushed upstream into the Ubuntu SDK. That should happen
 as when time permits.

 Usage:
        ClockTestCase {
            id: sampleTest
            name: "SampleTest"

            when: windowShown

            function initTestCase() {
               header = findChild(mainView, "MainView_Header")
               backButton = findChild(alarmTest.header, "customBackButton")
            }

            function test_something() {
               pressHeaderButton(header, "addAlarmAction")
            }
       }
*/

LomiriTestCase {
    id: testUtils

    function pressHeaderButton(header, objectName) {
        var headerButton = findChild(header, objectName + "_button")
        mouseClick(headerButton, centerOf(headerButton).x, centerOf(headerButton).y)
    }

    function pressButton(objectName) {
        mouseClick(objectName, centerOf(objectName).x, centerOf(objectName).y)
    }

    function getPage(pageStack, objectName) {
        var page = findChild(pageStack, objectName)
        waitForRendering(page)
        return page
    }

    function swipeToDeleteItem(item)
    {
        var startX = item.threshold
        var startY = item.height / 2
        var endX = item.width
        var endY = startY
        mousePress(item, startX, startY)
        mouseMoveSlowly(item,
                        startX, startY,
                        endX - startX, endY - startY,
                        10, 100)
        mouseRelease(item, endX, endY)
        mouseClick(item, startX, startY)
    }

    function clearTextField(textfield) {
        var clearButton = findChild(textfield, "clear_button")
        /*
         This check is required since if the textfield is read-only or does
         not have input focus then the clearButton may not be shown resulting
         in the text field not being cleared.
        */
        if (clearButton.visible) {
            pressButton(clearButton)
        } else {
            console.log("Clear Button not visible. Hence textfield cannot be cleared.")
        }
    }
}