File: ListItemTestCase13.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (157 lines) | stat: -rw-r--r-- 5,492 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright 2015 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtTest 1.0
import Lomiri.Test 1.3
import Lomiri.Components 1.3

/*
 * Common test case functions for ListItem. A CPO for unit tests.
 */
LomiriTestCase {
    when: windowShown

    SignalSpy {
        id: signalSpy
    }

    // set up the spy component for an item and a signal
    function setupSpy(item, signalName) {
        if (item.hasOwnProperty("leadingActions")) {
            signalSpy.target = item;
            signalSpy.signalName = signalName;
            signalSpy.clear();
        }
    }
    // wait on the previosuly set up spy
    function spyWait(timeout) {
        if (timeout == undefined) {
            timeout = 500;
        }
        if (signalSpy.target) {
            signalSpy.wait(timeout);
            signalSpy.clear();
            signalSpy.target = null;
        } else {
            wait(timeout);
        }
    }

    // rebounds a ListItem
    function rebound(item, watchTarget) {
        if (watchTarget === undefined) {
            watchTarget = item;
        }

        if (watchTarget.contentItem.x != watchTarget.contentItem.anchors.leftMargin) {
            mouseClick(item, 1, 1);
            tryCompareFunction(function() {
                return watchTarget.contentItem.x == watchTarget.contentItem.anchors.leftMargin;
            }, true, 500);
        }
    }

    // delayed swipe, gives few millisecond timeout between each move
    // so Repeater has time to create the panel actions in style
    function swipe(item, x, y, dx, dy) {
        setupSpy(item, "contentMovementEnded");
        flick(item, x, y, dx, dy, 0, 0, undefined, undefined, 100);
        spyWait();
    }
    function swipeNoWait(item, x, y, dx, dy) {
        flick(item, x, y, dx, dy, 0, 0, undefined, undefined, 100);
    }

    // touch swipes
    function swipeTouch(touchId, item, x, y, dx, dy) {
        setupSpy(item, "contentMovementEnded");
        flickTouch(touchId, item, x, y, dx, dy, 0, 100);
        spyWait();
    }
    function swipeTouchNoWait(touchId, item, x, y, dx, dy) {
        flickTouch(touchId, item, x, y, dx, dy, 0, 100);
    }

    function tug(item, x, y, dx, dy) {
        setupSpy(item, "contentMovementEnded");
        TestExtras.touchDrag(0, item, Qt.point(x, y), Qt.point(dx, dy));
        spyWait();
    }

    function tugNoWait(item, x, y, dx, dy) {
        TestExtras.touchDrag(0, item, Qt.point(x, y), Qt.point(dx, dy));
    }

    // returns the leading or trailing panel item
    function panelItem(item, leading) {
        return findInvisibleChild(item, (leading ? "ListItemPanelLeading" : "ListItemPanelTrailing"));
    }

    function toggleSelectMode(view, enabled, scrollToTop) {
        if (view.hasOwnProperty("positionViewAtBeginning") && scrollToTop) {
            // use the topmost listItem to wait for rendering completion
            view.positionViewAtBeginning();
        }
        var listItem = findChild(view, "listItem0");
        verify(listItem);
        view.ViewItems.selectMode = enabled;
        // waitForRendering aint seems to be reliable here, so we wait ~400 msecs
        wait(400);
    }

    function toggleDragMode(view, enabled) {
        // use the topmost listItem to wait for rendering completion
        view.positionViewAtBeginning();
        var listItem = findChild(view, "listItem0");
        verify(listItem);
        view.ViewItems.dragMode = enabled;
        // waitForRendering aint seems to be reliable here, so we wait ~400 msecs
        wait(400);
    }

    function drag(view, from, to) {
        var dragArea = findChild(view, "drag_area");
        verify(dragArea, "Cannot locate drag area");

        // grab the source item
        view.positionViewAtBeginning(from,ListView.Beginning);
        var panel = findChild(view, "drag_panel" + from);
        verify(panel, "Cannot locate source panel");
        var dragPos = dragArea.mapFromItem(panel, centerOf(panel).x, centerOf(panel).y);
        // move the mouse
        var dy = Math.abs(to - from) * panel.height + units.gu(1);
        dy *= (to > from) ? 1 : -1;
        mousePress(dragArea, dragPos.x, dragPos.y);
        wait(100);
        var draggedItem = findChild(view.contentItem, "DraggedListItem");
        if (draggedItem) {
            setupSpy(draggedItem.__styleInstance.dropAnimation, "stopped");
        }
        // use 10 steps to be sure the move is properly detected by the drag area
        mouseMoveSlowly(dragArea, dragPos.x, dragPos.y, 0, dy, 10, 100);
        // drop it, needs two mouse releases, this generates the Drop event also
        mouseRelease(dragArea, dragPos.x, dragPos.y + dy);
        // needs one more mouse release
        mouseRelease(dragArea, dragPos.x, dragPos.y + dy);
        spyWait();
    }

    function expand(item, expand) {
        item.expansion.expanded = expand;
        wait(400);
    }
}