~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to tests/qmltests/Panel/tst_Overview.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 ".."
 
20
import "../../../Panel/Menus"
 
21
import "../../../Components"
 
22
import Unity.Test 0.1 as UT
 
23
 
 
24
Rectangle {
 
25
    id: shell
 
26
    width: units.gu(40)
 
27
    height: units.gu(80)
 
28
    color: "black"
 
29
 
 
30
    Overview {
 
31
        id: overview
 
32
        anchors.fill: parent
 
33
        indicatorsModel: mockModel
 
34
        shown: true
 
35
    }
 
36
 
 
37
    Item {
 
38
        id: volumeControl
 
39
        property int volume
 
40
        function volumeUp() {
 
41
            volume = Math.min(100, volume + 10);
 
42
        }
 
43
        function volumeDown() {
 
44
            volume = Math.max(0, volume - 10);
 
45
        }
 
46
    }
 
47
 
 
48
    ListModel {
 
49
        id: mockModel
 
50
        ListElement {title: "foo"; label: "foo"; iconSource: "graphics/sound_on_icon.png"}
 
51
        ListElement {title: "bar"; label: ""; iconSource: "graphics/sound_on_icon.png"}
 
52
        ListElement {title: "baz"; label: "baz"; iconSource: "graphics/sound_on_icon.png"}
 
53
    }
 
54
 
 
55
    ListModel {
 
56
        id: mockModel2
 
57
    }
 
58
 
 
59
    SignalSpy {
 
60
        id: clickSpy
 
61
        target: overview
 
62
        signalName: "menuSelected"
 
63
    }
 
64
 
 
65
    UT.UnityTestCase {
 
66
        name: "Overview"
 
67
        when: windowShown
 
68
 
 
69
        function initTestCase() {
 
70
            // Spin the event loop once because the UI builds up delayed
 
71
            wait(0);
 
72
        }
 
73
 
 
74
        function test_menuSelected() {
 
75
            overview.indicatorsModel = mockModel;
 
76
 
 
77
            for (var i = 0; i < mockModel.count; ++i) {
 
78
                var button = findChild(overview, "overviewGridButton" + i);
 
79
                clickSpy.clear();
 
80
                mouseClick(button, button.width / 2, button.height / 2);
 
81
                compare(clickSpy.count, 1, "Clicking on grid didn't work");
 
82
                compare(clickSpy.signalArguments[0][0], i, "Clicking the grid returned a wrong index");
 
83
            }
 
84
        }
 
85
 
 
86
        function test_dynamic_addition() {
 
87
            var overviewGrid = findChild(overview, "overviewGrid");
 
88
 
 
89
            for(var i = 0; i < mockModel.count; ++i) {
 
90
                mockModel2.append(mockModel.get(i));
 
91
            }
 
92
            overview.indicatorsModel = mockModel2;
 
93
            overviewGrid.forceLayout();
 
94
            waitForRendering(overviewGrid);
 
95
 
 
96
            var button = findChild(overview, "overviewGridButton2");
 
97
            verify(button !== undefined, "button2 wasn't found");
 
98
            button = findChild(overview, "overviewGridButton3");
 
99
            compare(button, undefined, "There should only be 3 buttons... found at least 4...");
 
100
 
 
101
            mockModel2.append({title: "humppa", label: "", iconSource: "graphics/sound_on_icon.png"})
 
102
            overviewGrid.forceLayout();
 
103
            waitForRendering(overviewGrid);
 
104
 
 
105
            button = findChild(overview, "overviewGridButton3");
 
106
            verify(button !== undefined, "button3 wasn't found");
 
107
        }
 
108
 
 
109
        function test_text_or_icon_data() {
 
110
            return [
 
111
                {tag: "text", index: 0, imageVisible: false},
 
112
                {tag: "image", index: 1, imageVisible: true}
 
113
            ]
 
114
        }
 
115
 
 
116
        function test_text_or_icon(data) {
 
117
            var button = findChild(overview, "overviewGridButton" + data.index);
 
118
            var image = findChild(button, "overviewGridButtonImage");
 
119
            compare(image.visible, data.imageVisible)
 
120
        }
 
121
 
 
122
        function test_volume_slider_data() {
 
123
            return [
 
124
                {tag: "0%", sliderPos:0},
 
125
                {tag: "100%", sliderPos: 100},
 
126
                {tag: "50%", sliderPos: 50}
 
127
            ];
 
128
        }
 
129
 
 
130
        function test_volume_slider(data) {
 
131
            var volumeSlider = findChild(overview, "volumeSlider");
 
132
            var startX = volumeSlider.width * volumeSlider.value / 100;
 
133
            var startY = volumeSlider.y + volumeSlider.height / 2;
 
134
            var stopX = (volumeSlider.width - units.gu(5)) * data.sliderPos / 100;
 
135
            var stopY = volumeSlider.y + volumeSlider.height / 2;
 
136
            mouseFlick(volumeSlider, startX, startY, stopX, stopY, true, true, 0.1);
 
137
        }
 
138
 
 
139
        function test_volume_buttons(data) {
 
140
            var volumeDownButton = findChild(overview, "minVolumeIcon");
 
141
            var volumeUpButton = findChild(overview, "maxVolumeIcon");
 
142
 
 
143
            for (var i = 0; i < 10; ++i) {
 
144
                mouseClick(volumeDownButton, volumeDownButton.width / 2, volumeDownButton.height / 2);
 
145
                wait(0)
 
146
            }
 
147
            tryCompare(volumeControl, "volume", 0);
 
148
            for (var i = 0; i < 10; ++i) {
 
149
                mouseClick(volumeUpButton, 1, 1);
 
150
                wait(0)
 
151
            }
 
152
        }
 
153
    }
 
154
}