~mterry/+junk/u8.2

« back to all changes in this revision

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

  • Committer: Michael Terry
  • Date: 2014-11-17 14:56:04 UTC
  • mfrom: (1317.1.118 unity8)
  • Revision ID: michael.terry@canonical.com-20141117145604-96dn9p5nwkifq2f4
MergeĀ fromĀ trunk

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.Test 0.1 as UT
20
 
import ".."
21
 
import "../../../qml/Panel"
22
 
import Unity.Indicators 0.1 as Indicators
23
 
 
24
 
/*
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.
27
 
*/
28
 
Item {
29
 
    id: rootItem
30
 
    width: units.gu(40)
31
 
    height: units.gu(60)
32
 
 
33
 
    function init_test()
34
 
    {
35
 
        indicatorModel.load("test1");
36
 
 
37
 
        indicatorRow.state = "initial";
38
 
        indicatorRow.setCurrentItemIndex(-1);
39
 
        indicatorRow.unitProgress = 0.0;
40
 
    }
41
 
 
42
 
    PanelBackground {
43
 
        anchors.fill: indicatorRow
44
 
    }
45
 
 
46
 
    IndicatorRow {
47
 
        id: indicatorRow
48
 
        anchors {
49
 
            left: parent.left
50
 
            right: parent.right
51
 
        }
52
 
 
53
 
        indicatorsModel: indicatorModel
54
 
 
55
 
        Component.onCompleted: indicatorModel.load("test1")
56
 
    }
57
 
 
58
 
    Indicators.IndicatorsModel {
59
 
        id: indicatorModel
60
 
    }
61
 
 
62
 
    UT.UnityTestCase {
63
 
        name: "IndicatorRow"
64
 
        when: windowShown
65
 
 
66
 
        function get_indicator_item(index) {
67
 
            return findChild(indicatorRow.row, "item" + index);
68
 
        }
69
 
 
70
 
        function test_set_current_item() {
71
 
            init_test();
72
 
            indicatorRow.setCurrentItemIndex(0);
73
 
            compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake1", "Incorrect item at position 0");
74
 
 
75
 
            indicatorRow.setCurrentItemIndex(1);
76
 
            compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake2", "Incorrect item at position 1");
77
 
 
78
 
            indicatorRow.setCurrentItemIndex(2);
79
 
            compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake3", "Incorrect item at position 2");
80
 
        }
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
 
            }
158
 
        }
159
 
    }
160
 
}