~iahmad/ubuntu-ui-toolkit/textarea_tests

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_picker.qml

  • Committer: Tarmac
  • Author(s): Zsombor Egri
  • Date: 2013-09-11 10:46:22 UTC
  • mfrom: (739.1.9 picker-api)
  • Revision ID: tarmac-20130911104622-c1aq0wjfuabrta13
Picker component, a tumbler style value selector.

Approved by PS Jenkins bot.

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 Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser 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 Ubuntu.Test 0.1
 
20
import Ubuntu.Components 0.1
 
21
import Ubuntu.Components.Pickers 0.1
 
22
 
 
23
Item {
 
24
    id: testSuite
 
25
    width: units.gu(20)
 
26
    height: units.gu(40)
 
27
 
 
28
    Column {
 
29
        Picker {
 
30
            objectName: "linear"
 
31
            id: linearShort
 
32
            circular: false
 
33
            model: objectModel
 
34
            delegate: PickerDelegate {
 
35
                Label {text: modelData}
 
36
            }
 
37
        }
 
38
        Picker {
 
39
            objectName: "linear"
 
40
            id: linearLong
 
41
            circular: false
 
42
            model: longerModel
 
43
            delegate: PickerDelegate {
 
44
                Label {text: modelData}
 
45
            }
 
46
        }
 
47
 
 
48
        Picker {
 
49
            objectName: "objectModelled"
 
50
            id: objectModelled
 
51
            model: objectModel
 
52
            selectedIndex: 2
 
53
        }
 
54
        Picker {
 
55
            objectName: "simpleModelled"
 
56
            id: simpleModelled
 
57
            model: emptyModel
 
58
            selectedIndex: 2
 
59
        }
 
60
        Picker {
 
61
            objectName: "picker"
 
62
            id: picker
 
63
        }
 
64
    }
 
65
 
 
66
    ListModel {
 
67
        id: emptyModel
 
68
    }
 
69
 
 
70
    ListModel {
 
71
        id: objectModel
 
72
        ListElement {
 
73
            label: "line1"
 
74
        }
 
75
        ListElement {
 
76
            label: "line2"
 
77
        }
 
78
        ListElement {
 
79
            label: "line3"
 
80
        }
 
81
    }
 
82
 
 
83
    ListModel {
 
84
        id: longerModel
 
85
        ListElement {
 
86
            label: "line1"
 
87
        }
 
88
        ListElement {
 
89
            label: "line2"
 
90
        }
 
91
        ListElement {
 
92
            label: "line3"
 
93
        }
 
94
        ListElement {
 
95
            label: "line4"
 
96
        }
 
97
        ListElement {
 
98
            label: "line5"
 
99
        }
 
100
        ListElement {
 
101
            label: "line6"
 
102
        }
 
103
    }
 
104
 
 
105
    SignalSpy {
 
106
        id: spy
 
107
    }
 
108
 
 
109
    UbuntuTestCase {
 
110
        id: testCase
 
111
        name: "PickerAPI"
 
112
        when: windowShown
 
113
 
 
114
        function test_0_circular() {
 
115
            compare(picker.circular, true, "default circular");
 
116
        }
 
117
        function test_0_model() {
 
118
            compare(picker.model, undefined, "default model");
 
119
        }
 
120
        function test_0_delegate() {
 
121
            compare(picker.delegate, null, "default delegate");
 
122
        }
 
123
        function test_0_selectedIndex() {
 
124
            compare(picker.selectedIndex, 0, "default selectedIndex");
 
125
        }
 
126
 
 
127
        function test_1_runtimeModel() {
 
128
            picker.model = emptyModel;
 
129
            compare(picker.selectedIndex, 0, "selectedIndex gets 0");
 
130
        }
 
131
 
 
132
        function test_1_selectedIndexForEmptyModel() {
 
133
            compare(simpleModelled.selectedIndex, 2, "empty modelled picker selectedIndex is 0");
 
134
        }
 
135
 
 
136
        function test_1_selectedIndexForObjectModel() {
 
137
            compare(objectModelled.selectedIndex, 2, "model containing data, picker.selectedIndex");
 
138
        }
 
139
 
 
140
        function test_2_updateModel() {
 
141
            picker.selectedIndex = 1;
 
142
            spy.clear();
 
143
            spy.signalName = "onSelectedIndexChanged";
 
144
            spy.target = picker;
 
145
            picker.model = [];
 
146
            tryCompare(spy, "count", 1);
 
147
        }
 
148
 
 
149
        function test_2_updateModel2() {
 
150
            objectModelled.selectedIndex = 1;
 
151
            spy.clear();
 
152
            spy.signalName = "onSelectedIndexChanged";
 
153
            spy.target = objectModelled;
 
154
            objectModelled.model = [];
 
155
            tryCompare(spy, "count", 1);
 
156
        }
 
157
 
 
158
        function test_4_clickMovesSelection_Long() {
 
159
            spy.clear();
 
160
            spy.signalName = "onSelectedIndexChanged";
 
161
            spy.target = linearLong;
 
162
            mouseClick(linearLong, units.gu(1), units.gu(1));
 
163
            tryCompare(spy, "count", 0);
 
164
            mouseClick(linearLong, units.gu(1), units.gu(18));
 
165
            tryCompare(spy, "count", 1);
 
166
        }
 
167
 
 
168
        function test_3_clickMovesSelection_Short() {
 
169
            spy.clear();
 
170
            spy.signalName = "onSelectedIndexChanged";
 
171
            spy.target = linearShort;
 
172
            mouseClick(linearShort, units.gu(1), units.gu(1));
 
173
            tryCompare(spy, "count", 0);
 
174
            mouseClick(linearShort, units.gu(1), units.gu(18));
 
175
            tryCompare(spy, "count", 1);
 
176
        }
 
177
 
 
178
        function test_5_clickMovesSelection_Long() {
 
179
            spy.clear();
 
180
            spy.signalName = "onSelectedIndexChanged";
 
181
            linearLong.circular = true;
 
182
 
 
183
            spy.target = linearLong;
 
184
            mouseClick(linearLong, units.gu(1), units.gu(1));
 
185
            tryCompare(spy, "count", 1);
 
186
            mouseClick(linearLong, units.gu(1), units.gu(18));
 
187
            tryCompare(spy, "count", 2);
 
188
        }
 
189
    }
 
190
}