~ci-train-bot/unity8/unity8-ubuntu-zesty-2167

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/tst_DashBar.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Unity 0.1
 
20
import ".."
 
21
import "../../../Dash"
 
22
import Ubuntu.Components 0.1
 
23
import Unity.Test 0.1 as UT
 
24
 
 
25
Item {
 
26
    width: units.gu(40)
 
27
    height: units.gu(71)
 
28
 
 
29
    DashBar {
 
30
        id: dashBar
 
31
 
 
32
        anchors {
 
33
            left: parent.left
 
34
            right: parent.right
 
35
            bottom: parent.bottom
 
36
        }
 
37
        model: lenses
 
38
        onItemSelected: currentIndex = index
 
39
    }
 
40
 
 
41
    Lenses {
 
42
        id: lenses
 
43
    }
 
44
 
 
45
    SignalSpy {
 
46
        id: signalSpy
 
47
        signalName: "itemSelected"
 
48
        target: dashBar
 
49
    }
 
50
 
 
51
    UT.UnityTestCase {
 
52
        name: "DashBar"
 
53
        when: lenses.loaded
 
54
 
 
55
        property alias model: dashBar.model
 
56
        property alias currentIndex: dashBar.currentIndex
 
57
 
 
58
        readonly property alias lineHeight: dashBar.lineHeight
 
59
        readonly property alias itemSize: dashBar.itemSize
 
60
        readonly property alias iconSize: dashBar.iconSize
 
61
        readonly property var panel: findChild(dashBar, "panel");
 
62
 
 
63
        function initTestCase() {
 
64
            currentIndex = 2
 
65
        }
 
66
 
 
67
        function waitForAnimationToEnd() {
 
68
            compare(panel.animating, true) // check the animation started
 
69
            tryCompare(panel, "animating", false) // wait till the animation ends
 
70
        }
 
71
 
 
72
        function closePanel() {
 
73
            dashBar.finishNavigation()
 
74
            waitForAnimationToEnd()
 
75
            tryCompare(panel, "opened", false)
 
76
        }
 
77
 
 
78
        function openPanel() {
 
79
            dashBar.startNavigation()
 
80
            waitForAnimationToEnd()
 
81
            tryCompare(panel, "opened", true)
 
82
        }
 
83
 
 
84
        function test_navigationAndHide() {
 
85
            openPanel()
 
86
            closePanel()
 
87
        }
 
88
 
 
89
        function test_itemSelected() {
 
90
            openPanel()
 
91
 
 
92
            var row = findChild(dashBar, "row");
 
93
            tryCompareFunction(function(){return row.width > 0;}, true);
 
94
            for (var i = 0; i < model.rowCount(); i++) {
 
95
                // coordinate x in the middle of item with index 'i'
 
96
                var x = row.x + (row.width / model.rowCount()) * i + itemSize / 2
 
97
 
 
98
                // FIXME workaround for a bug in SignalSpy
 
99
                signalSpy.clear()
 
100
 
 
101
                // (item, x, y, button, modifiers, delay)
 
102
                mouseClick(panel, x, row.height / 2, Qt.LeftButton, Qt.NoModifier, 0)
 
103
                compare(signalSpy.count > 0, true, "signal itemSelected not triggered")
 
104
                compare(signalSpy.signalArguments[0][0], i, "signal itemSelected emitted unexpected index");
 
105
                tryCompare(dashBar, "currentIndex", i);
 
106
            }
 
107
 
 
108
            closePanel()
 
109
        }
 
110
    }
 
111
}