~ubuntu-branches/ubuntu/trusty/unity8/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/qmltests/Panel/tst_IndicatorRow.qml

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2014-02-03 16:56:47 UTC
  • mfrom: (1.1.64)
  • Revision ID: package-import@ubuntu.com-20140203165647-ik9w833cac4zu9da
Tags: 7.84+14.04.20140130.is.7.84+14.04.20131220-0ubuntu1
Reverting to last known good version, as after installing a click
application, it redirects you to the first click application everytime.
(LP: #1275832)

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
    function init_test()
34
34
    {
35
 
        indicatorModel.load();
36
 
 
37
35
        indicatorRow.state = "initial";
38
 
        indicatorRow.setCurrentItemIndex(-1);
39
 
        indicatorRow.unitProgress = 0.0;
 
36
        indicatorRow.currentItem = null;
40
37
    }
41
38
 
42
39
    PanelBackground {
51
48
        }
52
49
 
53
50
        indicatorsModel: indicatorModel
54
 
 
55
 
        Component.onCompleted: indicatorModel.load()
56
51
    }
57
52
 
58
53
    Indicators.IndicatorsModel {
59
54
        id: indicatorModel
 
55
        Component.onCompleted: load()
60
56
    }
61
57
 
62
58
    UT.UnityTestCase {
63
59
        name: "IndicatorRow"
64
60
        when: windowShown
65
61
 
66
 
        function get_indicator_item(index) {
67
 
            return findChild(indicatorRow.row, "item" + index);
68
 
        }
69
 
 
70
62
        function test_set_current_item() {
71
63
            init_test();
72
 
            indicatorRow.setCurrentItemIndex(0);
 
64
            indicatorRow.setCurrentItem(0);
73
65
            compare(indicatorRow.indicatorsModel.get(indicatorRow.currentItemIndex).identifier, "indicator-fake1", "Incorrect item at position 0");
74
66
 
75
 
            indicatorRow.setCurrentItemIndex(1);
 
67
            indicatorRow.setCurrentItem(1);
76
68
            compare(indicatorRow.indicatorsModel.get(indicatorRow.currentItemIndex).identifier, "indicator-fake2", "Incorrect item at position 1");
77
69
 
78
 
            indicatorRow.setCurrentItemIndex(2);
 
70
            indicatorRow.setCurrentItem(2);
79
71
            compare(indicatorRow.indicatorsModel.get(indicatorRow.currentItemIndex).identifier, "indicator-fake3", "Incorrect item at position 2");
80
72
        }
81
 
 
82
 
        function test_highlight_data() {
83
 
            return [
84
 
                { index: 0, progress: 0.0, current: false, other: false },
85
 
                { index: 0, progress: 0.1, current: true, other: false },
86
 
                { index: 0, progress: 0.5, current: true, other: false },
87
 
                { index: 0, progress: 1.0, current: true, other: false },
88
 
                { index: 2, progress: 0.0, current: false, other: false },
89
 
                { index: 2, progress: 0.1, current: true, other: false },
90
 
                { index: 2, progress: 0.5, current: true, other: false },
91
 
                { index: 2, progress: 1.0, current: true, other: false }
92
 
            ];
93
 
        }
94
 
 
95
 
        function test_highlight(data) {
96
 
            init_test();
97
 
 
98
 
            indicatorRow.unitProgress = data.progress;
99
 
            indicatorRow.setCurrentItemIndex(data.index);
100
 
 
101
 
            compare(indicatorRow.currentItem.highlighted, data.current, "Indicator hightlight did not match for current item");
102
 
 
103
 
            for (var i = 0; i < indicatorRow.row.count; i++) {
104
 
                compare(get_indicator_item(i).highlighted, i === data.index ? data.current: data.other, "Indicator hightlight did not match for item iter");
105
 
            }
106
 
        }
107
 
 
108
 
        function test_opacity_data() {
109
 
            return [
110
 
                { index: 0, progress: 0.0, current: 1.0, other: 1.0 },
111
 
                { index: 0, progress: 0.1, current: 1.0, other: 0.9 },
112
 
                { index: 0, progress: 0.5, current: 1.0, other: 0.5 },
113
 
                { index: 0, progress: 1.0, current: 1.0, other: 0.0 },
114
 
                { index: 2, progress: 0.0, current: 1.0, other: 1.0 },
115
 
                { index: 2, progress: 0.1, current: 1.0, other: 0.9 },
116
 
                { index: 2, progress: 0.5, current: 1.0, other: 0.5 },
117
 
                { index: 2, progress: 1.0, current: 1.0, other: 0.0 }
118
 
            ];
119
 
        }
120
 
 
121
 
        function test_opacity(data) {
122
 
            init_test();
123
 
 
124
 
            indicatorRow.unitProgress = data.progress;
125
 
            indicatorRow.setCurrentItemIndex(data.index);
126
 
 
127
 
            tryCompare(indicatorRow.currentItem, "opacity", data.current);
128
 
 
129
 
            for (var i = 0; i < indicatorRow.row.count; i++) {
130
 
                tryCompare(get_indicator_item(i), "opacity", i === data.index ? data.current: data.other);
131
 
            }
132
 
        }
133
 
 
134
 
        function test_dimmed_data() {
135
 
            return [
136
 
                { index: 0, progress: 0.0, current: false, other: false },
137
 
                { index: 0, progress: 0.1, current: false, other: true },
138
 
                { index: 0, progress: 0.5, current: false, other: true },
139
 
                { index: 0, progress: 1.0, current: false, other: true },
140
 
                { index: 2, progress: 0.0, current: false, other: false },
141
 
                { index: 2, progress: 0.1, current: false, other: true },
142
 
                { index: 2, progress: 0.5, current: false, other: true },
143
 
                { index: 2, progress: 1.0, current: false, other: true }
144
 
            ];
145
 
        }
146
 
 
147
 
        function test_dimmed(data) {
148
 
            init_test();
149
 
 
150
 
            indicatorRow.unitProgress = data.progress;
151
 
            indicatorRow.setCurrentItemIndex(data.index);
152
 
 
153
 
            compare(indicatorRow.currentItem.dimmed, data.current, "Indicator dim did not match for current item");
154
 
 
155
 
            for (var i = 0; i < indicatorRow.row.count; i++) {
156
 
                compare(get_indicator_item(i).dimmed, i === data.index ? data.current: data.other, "Indicator dim did not match for item iter");
157
 
            }
 
73
    }
 
74
 
 
75
    UT.UnityTestCase {
 
76
        name: "IndicatorRow_IconPosition"
 
77
        when: windowShown
 
78
 
 
79
        function get_indicator_item_at(index) {
 
80
            return findChild(indicatorRow, "rowRepeater").itemAt(index);
 
81
        }
 
82
 
 
83
        function test_current_item_commit() {
 
84
            init_test();
 
85
 
 
86
            indicatorRow.setCurrentItem(1);
 
87
            indicatorRow.state = "commit";
 
88
            tryCompare(get_indicator_item_at(0), "opacity", 0.0);
 
89
            tryCompare(get_indicator_item_at(1), "opacity", 1.0);
 
90
            tryCompare(get_indicator_item_at(2), "opacity", 0.0);
 
91
            tryCompare(get_indicator_item_at(3), "opacity", 0.0);
 
92
            tryCompare(get_indicator_item_at(4), "opacity", 0.0);
 
93
 
 
94
        }
 
95
    }
 
96
 
 
97
    UT.UnityTestCase {
 
98
        name: "IndicatorRow_Highlight"
 
99
        when: windowShown
 
100
 
 
101
        function get_indicator_item_at(index) {
 
102
            return findChild(indicatorRow, "rowRepeater").itemAt(index);
 
103
        }
 
104
 
 
105
        function test_intial_state() {
 
106
            init_test();
 
107
 
 
108
            indicatorRow.state = "initial";
 
109
            indicatorRow.setCurrentItem(0);
 
110
 
 
111
            compare(indicatorRow.currentItem.highlighted, false, "Indicator should not highlight when in initial state");
 
112
            compare(get_indicator_item_at(1).highlighted, false, "Other indicators should not highlight when in initial state");
 
113
            compare(get_indicator_item_at(2).highlighted, false, "Other indicators should not highlight when in initial state");
 
114
            compare(get_indicator_item_at(3).highlighted, false, "Other indicators should not highlight when in initial state");
 
115
            compare(get_indicator_item_at(4).highlighted, false, "Other indicators should not highlight when in initial state");
 
116
        }
 
117
 
 
118
        function test_hint_state() {
 
119
            init_test();
 
120
 
 
121
            indicatorRow.state = "hint";
 
122
            indicatorRow.setCurrentItem(0);
 
123
 
 
124
            compare(indicatorRow.currentItem.highlighted, true, "Indicator should highlight when in hint state");
 
125
            compare(get_indicator_item_at(1).highlighted, false, "Other indicators should not highlight when in hint state");
 
126
            compare(get_indicator_item_at(2).highlighted, false, "Other indicators should not highlight when in hint state");
 
127
            compare(get_indicator_item_at(3).highlighted, false, "Other indicators should not highlight when in hint state");
 
128
            compare(get_indicator_item_at(4).highlighted, false, "Other indicators should not highlight when in hint state");
 
129
        }
 
130
 
 
131
        function test_revealed_state() {
 
132
            init_test();
 
133
 
 
134
            indicatorRow.state = "reveal";
 
135
            indicatorRow.setCurrentItem(0);
 
136
 
 
137
            compare(indicatorRow.currentItem.highlighted, true, "Indicator should highlight when in reveal state");
 
138
            compare(get_indicator_item_at(1).highlighted, false, "Other indicators should not highlight when in commit state");
 
139
            compare(get_indicator_item_at(2).highlighted, false, "Other indicators should not highlight when in commit state");
 
140
            compare(get_indicator_item_at(3).highlighted, false, "Other indicators should not highlight when in commit state");
 
141
            compare(get_indicator_item_at(4).highlighted, false, "Other indicators should not highlight when in commit state");
 
142
        }
 
143
 
 
144
        function test_commit_state() {
 
145
            init_test();
 
146
 
 
147
            indicatorRow.state = "commit";
 
148
            indicatorRow.setCurrentItem(0);
 
149
 
 
150
            compare(indicatorRow.currentItem.highlighted, true, "Indicator should highlight when in commit state");
 
151
            compare(get_indicator_item_at(1).highlighted, false, "Other indicators should not highlight when in commit state");
 
152
            compare(get_indicator_item_at(2).highlighted, false, "Other indicators should not highlight when in commit state");
 
153
            compare(get_indicator_item_at(3).highlighted, false, "Other indicators should not highlight when in commit state");
 
154
            compare(get_indicator_item_at(4).highlighted, false, "Other indicators should not highlight when in commit state");
 
155
        }
 
156
 
 
157
        function test_locked_state() {
 
158
            init_test();
 
159
 
 
160
            indicatorRow.state = "locked";
 
161
            indicatorRow.setCurrentItem(0);
 
162
 
 
163
            compare(indicatorRow.currentItem.highlighted, true, "Indicator should highlight when in locked state");
 
164
            compare(get_indicator_item_at(1).highlighted, false, "Other indicators should not highlight when in locked state");
 
165
            compare(get_indicator_item_at(2).highlighted, false, "Other indicators should not highlight when in locked state");
 
166
            compare(get_indicator_item_at(3).highlighted, false, "Other indicators should not highlight when in locked state");
 
167
            compare(get_indicator_item_at(4).highlighted, false, "Other indicators should not highlight when in locked state");
 
168
        }
 
169
    }
 
170
 
 
171
    UT.UnityTestCase {
 
172
        name: "IndicatorRow_Dimmed"
 
173
        when: windowShown
 
174
 
 
175
        function get_indicator_item_at(index) {
 
176
            return findChild(indicatorRow, "rowRepeater").itemAt(index);
 
177
        }
 
178
 
 
179
        function test_intial_state() {
 
180
            init_test();
 
181
 
 
182
            indicatorRow.state = "initial";
 
183
            indicatorRow.setCurrentItem(0);
 
184
 
 
185
            compare(get_indicator_item_at(0).dimmed, false, "Current indicator should not dim when in intiial state");
 
186
            compare(get_indicator_item_at(1).dimmed, false, "Other indicators should not dim when in initial state");
 
187
            compare(get_indicator_item_at(2).dimmed, false, "Other indicators should not dim when in initial state");
 
188
            compare(get_indicator_item_at(3).dimmed, false, "Other indicators should not dim when in initial state");
 
189
            compare(get_indicator_item_at(4).dimmed, false, "Other indicators should not dim when in initial state");
 
190
        }
 
191
 
 
192
        function test_hint_state() {
 
193
            init_test();
 
194
 
 
195
            indicatorRow.state = "hint";
 
196
            indicatorRow.setCurrentItem(0);
 
197
 
 
198
            compare(get_indicator_item_at(0).dimmed, false, "Current indicator should not dim when in hint state");
 
199
            compare(get_indicator_item_at(1).dimmed, true, "Other indicators should dim when in hint state");
 
200
            compare(get_indicator_item_at(2).dimmed, true, "Other indicators should dim when in hint state");
 
201
            compare(get_indicator_item_at(3).dimmed, true, "Other indicators should dim when in hint state");
 
202
            compare(get_indicator_item_at(4).dimmed, true, "Other indicators should dim when in hint state");
 
203
        }
 
204
 
 
205
        function test_revealed_state() {
 
206
            init_test();
 
207
 
 
208
            indicatorRow.state = "reveal";
 
209
            indicatorRow.setCurrentItem(0);
 
210
 
 
211
            compare(get_indicator_item_at(0).dimmed, false, "Current indicator should not dim when in reveal state");
 
212
            compare(get_indicator_item_at(1).dimmed, true, "Other indicators should dim when in reveal state");
 
213
            compare(get_indicator_item_at(2).dimmed, true, "Other indicators should dim when in reveal state");
 
214
            compare(get_indicator_item_at(3).dimmed, true, "Other indicators should dim when in reveal state");
 
215
            compare(get_indicator_item_at(4).dimmed, true, "Other indicators should dim when in reveal state");
 
216
        }
 
217
 
 
218
        function test_commit_state() {
 
219
            init_test();
 
220
 
 
221
            indicatorRow.state = "commit";
 
222
            indicatorRow.setCurrentItem(0);
 
223
 
 
224
            compare(get_indicator_item_at(0).dimmed, false, "Current indicator should not dim when in commit state");
 
225
            compare(get_indicator_item_at(1).dimmed, true, "Other indicators should dim when in commit state");
 
226
            compare(get_indicator_item_at(2).dimmed, true, "Other indicators should dim when in commit state");
 
227
            compare(get_indicator_item_at(3).dimmed, true, "Other indicators should dim when in commit state");
 
228
            compare(get_indicator_item_at(4).dimmed, true, "Other indicators should dim when in commit state");
 
229
        }
 
230
 
 
231
        function test_locked_state() {
 
232
            init_test();
 
233
 
 
234
            indicatorRow.state = "locked";
 
235
            indicatorRow.setCurrentItem(0);
 
236
 
 
237
            compare(get_indicator_item_at(0).dimmed, false, "Current indicator should not dim when in locked state");
 
238
            compare(get_indicator_item_at(1).dimmed, true, "Other indicators should dim when in locked state");
 
239
            compare(get_indicator_item_at(2).dimmed, true, "Other indicators should dim when in locked state");
 
240
            compare(get_indicator_item_at(3).dimmed, true, "Other indicators should dim when in locked state");
 
241
            compare(get_indicator_item_at(4).dimmed, true, "Other indicators should dim when in locked state");
158
242
        }
159
243
    }
160
244
}