2
* Copyright 2013 Canonical Ltd.
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.
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.
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/>.
19
import Unity.Test 0.1 as UT
21
import "../../../qml/Panel"
22
import Unity.Indicators 0.1 as Indicators
25
This tests the IndicatorRow component by using a fake model to stage data in the indicators
26
A view will show with indicators at the top, as does in the shell.
35
indicatorModel.load("test1");
37
indicatorRow.state = "initial";
38
indicatorRow.setCurrentItemIndex(-1);
39
indicatorRow.unitProgress = 0.0;
43
anchors.fill: indicatorRow
53
indicatorsModel: indicatorModel
55
Component.onCompleted: indicatorModel.load("test1")
58
Indicators.IndicatorsModel {
66
function get_indicator_item(index) {
67
return findChild(indicatorRow.row, "item" + index);
70
function test_set_current_item() {
72
indicatorRow.setCurrentItemIndex(0);
73
compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake1", "Incorrect item at position 0");
75
indicatorRow.setCurrentItemIndex(1);
76
compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake2", "Incorrect item at position 1");
78
indicatorRow.setCurrentItemIndex(2);
79
compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake3", "Incorrect item at position 2");
82
function test_highlight_data() {
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 }
95
function test_highlight(data) {
98
indicatorRow.unitProgress = data.progress;
99
indicatorRow.setCurrentItemIndex(data.index);
101
compare(indicatorRow.currentItem.highlighted, data.current, "Indicator hightlight did not match for current item");
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");
108
function test_opacity_data() {
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 }
121
function test_opacity(data) {
124
indicatorRow.unitProgress = data.progress;
125
indicatorRow.setCurrentItemIndex(data.index);
127
tryCompare(indicatorRow.currentItem, "opacity", data.current);
129
for (var i = 0; i < indicatorRow.row.count; i++) {
130
tryCompare(get_indicator_item(i), "opacity", i === data.index ? data.current: data.other);
134
function test_dimmed_data() {
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 }
147
function test_dimmed(data) {
150
indicatorRow.unitProgress = data.progress;
151
indicatorRow.setCurrentItemIndex(data.index);
153
compare(indicatorRow.currentItem.dimmed, data.current, "Indicator dim did not match for current item");
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");