~mterry/+junk/u8.2

« back to all changes in this revision

Viewing changes to tests/qmltests/Panel/tst_Indicators.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 Ubuntu.Components 0.1 as UC
21
 
import ".."
22
 
import "../../../qml/Panel"
23
 
import "../../../qml/Components"
24
 
 
25
 
/*
26
 
  This tests the Indicators component by using a fake model to stage data in the indicators
27
 
  A view will show with indicators at the top, as does in the shell. There is a clickable area
28
 
  marked "Click Me" which can be used to expose the indicators.
29
 
*/
30
 
Item {
31
 
    id: shell
32
 
    width: units.gu(40)
33
 
    height: units.gu(80)
34
 
 
35
 
    PanelBackground {
36
 
        anchors.fill: indicators
37
 
    }
38
 
 
39
 
    Indicators {
40
 
        id: indicators
41
 
        anchors {
42
 
            right: parent.right
43
 
        }
44
 
        width: (shell.width > units.gu(60)) ? units.gu(40) : shell.width
45
 
        y: 0
46
 
        shown: false
47
 
        profile: "test1"
48
 
 
49
 
        openedHeight: parent.height - button.height
50
 
    }
51
 
 
52
 
    UC.Button {
53
 
        id: button
54
 
        text: indicators.shown ? "Hide" : "Show"
55
 
        anchors {
56
 
            bottom: shell.bottom
57
 
            left: parent.left
58
 
            right: parent.right
59
 
        }
60
 
        height: 50
61
 
 
62
 
        onClicked: {
63
 
            if (!indicators.shown) {
64
 
                indicators.show();
65
 
            } else {
66
 
                indicators.hide();
67
 
            }
68
 
        }
69
 
    }
70
 
 
71
 
    UT.UnityTestCase {
72
 
        name: "Indicators"
73
 
        when: windowShown
74
 
 
75
 
        function init() {
76
 
            indicators.initialise();
77
 
 
78
 
            indicators.hide();
79
 
            tryCompare(indicators.hideAnimation, "running", false);
80
 
            tryCompare(indicators, "state", "initial");
81
 
        }
82
 
 
83
 
        // Showing the indicators should fully open the indicator panel.
84
 
        function test_show() {
85
 
            indicators.show()
86
 
            tryCompare(indicators, "fullyOpened", true);
87
 
        }
88
 
 
89
 
        // Test the change in the revealer lateral position changes the current panel menu to fit the position
90
 
        // of the indicator in the row.
91
 
        function test_change_revealer_lateral_position()
92
 
        {
93
 
            // tests changing the lateral position of the revealer activates the correct indicator items.
94
 
 
95
 
            var indicatorRow = findChild(indicators, "indicatorRow")
96
 
            verify(indicatorRow !== null);
97
 
            var indicatorRowItems = findChild(indicatorRow, "indicatorRowItems");
98
 
            verify(indicatorRowItems !== null);
99
 
 
100
 
            for (var i = 0; i < indicatorRowItems.count; i++) {
101
 
                var indicatorItem = findChild(indicatorRowItems, "item" + i);
102
 
 
103
 
                if (!indicatorItem.visible)
104
 
                    continue;
105
 
 
106
 
                var indicatorPosition = indicators.mapFromItem(indicatorItem,
107
 
                        indicatorItem.width/2, indicatorItem.height/2);
108
 
 
109
 
                touchFlick(indicators,
110
 
                           indicatorPosition.x, indicatorPosition.y,
111
 
                           indicatorPosition.x, indicators.openedHeight * 0.4,
112
 
                           true /* beginTouch */, false /* endTouch */);
113
 
 
114
 
                compare(indicatorRow.currentItem, indicatorItem,
115
 
                        "Incorrect item activated at position " + i);
116
 
 
117
 
                touchFlick(indicators,
118
 
                           indicatorPosition.x, indicators.openedHeight * 0.4,
119
 
                           indicatorPosition.x, indicatorPosition.y,
120
 
                           false /* beginTouch */, true /* endTouch */);
121
 
 
122
 
                // wait until fully closed
123
 
                tryCompare(indicators, "height", indicators.panelHeight);
124
 
            }
125
 
        }
126
 
 
127
 
        // values for specific state changes are subject to internal decisions, so we can't
128
 
        // determine the true height value which would cause the state to change without making
129
 
        // too many assuptyions
130
 
        // However, we can assume that a partially opened panel will not be initial, and fully
131
 
        // opened panel will be locked.
132
 
 
133
 
        function test_progress_changes_state_to_not_initial() {
134
 
            indicators.height = indicators.openedHeight / 2
135
 
            compare(indicators.state!="initial", true,
136
 
                    "Indicators should not be in initial state when partially opened.");
137
 
        }
138
 
 
139
 
        function test_progress_changes_state_to_locked() {
140
 
            indicators.height = indicators.openedHeight - indicators.panelHeight
141
 
            compare(indicators.state, "locked", "Indicators should be locked when fully opened.");
142
 
        }
143
 
 
144
 
        function test_partially_open() {
145
 
            indicators.height = indicators.openedHeight / 2
146
 
            compare(indicators.partiallyOpened, true,
147
 
                    "Indicator should show as partially opened when height is half of openedHeight");
148
 
            compare(indicators.fullyOpened, false,
149
 
                    "Indicator should not show as fully opened when height is half of openedHeight");
150
 
        }
151
 
 
152
 
        function test_fully_open() {
153
 
            indicators.height = indicators.openedHeight
154
 
            compare(indicators.partiallyOpened, false);
155
 
            compare(indicators.fullyOpened, true);
156
 
        }
157
 
 
158
 
        function init_invisible_indicator(identifier) {
159
 
            tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
160
 
            var item = findChild(indicators, identifier+"-delegate");
161
 
 
162
 
            item.enabled = false;
163
 
        }
164
 
 
165
 
        function test_row_visible_menuContent_visible_data() { return [
166
 
            {tag: "first", visible: [false, true, true, true, true] },
167
 
            {tag: "adjacent", visible: [true, false, false, true, true] },
168
 
            {tag: "bounds", visible: [false, true, true, true, false] },
169
 
            {tag: "disjoint", visible: [true, false, true, false, true] },
170
 
            {tag: "last", visible: [true, true, true, true, false] }];
171
 
        }
172
 
 
173
 
        function test_row_visible_menuContent_visible(data) {
174
 
            indicators.show();
175
 
 
176
 
            var contentListView = findChild(indicators, "indicatorsContentListView");
177
 
            var indicatorRowItems = findChild(indicators, "indicatorRowItems");
178
 
 
179
 
            var count = data.visible.length
180
 
            for (var i = 0; i< data.visible.length; i++) {
181
 
                if (data.visible[i] === false) {
182
 
                    init_invisible_indicator("indicator-fake" + (i + 1));
183
 
                    count--;
184
 
                }
185
 
            }
186
 
 
187
 
            tryCompare(indicatorRowItems, "count", count);
188
 
 
189
 
            for (i = 0; i < data.visible.length; i++) {
190
 
                var widgetName = "indicator-fake" + (i + 1 + "-widget");
191
 
                var pageName = "indicator-fake" + (i + 1 + "-page");
192
 
 
193
 
                // check for item
194
 
                tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== null }, data.visible[i]);
195
 
 
196
 
                // check for tab
197
 
                tryCompareFunction(function() { return findChild(contentListView, pageName) !== null }, data.visible[i]);
198
 
            }
199
 
        }
200
 
 
201
 
        function test_indicator_visible_correct_menu_data() { return [
202
 
            {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expectedIndex: 0, expextedMenu: "indicator-fake2"  },
203
 
            {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expextedMenu: "indicator-fake4" },
204
 
            {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expextedMenu: "indicator-fake1" },
205
 
            {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expextedMenu: "indicator-fake2" }];
206
 
        }
207
 
 
208
 
        function test_indicator_visible_correct_menu(data) {
209
 
            var contentListView = findChild(indicators, "indicatorsContentListView");
210
 
            var indicatorRow = findChild(indicators, "indicatorRow");
211
 
 
212
 
            indicators.show();
213
 
            indicatorRow.setCurrentItemIndex(data.currentIndex);
214
 
            tryCompare(indicators, "fullyOpened", true);
215
 
 
216
 
            for (var i = 0; i< data.visible.length; i++) {
217
 
                if (data.visible[i] === false) {
218
 
                    init_invisible_indicator("indicator-fake" + (i + 1));
219
 
                }
220
 
            }
221
 
 
222
 
            // check for current selected item
223
 
            tryCompare(indicatorRow, "currentItemIndex", data.expectedIndex);
224
 
 
225
 
            // check for current selected tab
226
 
            tryCompareFunction(function() { return findChild(contentListView, data.expextedMenu) === contentListView.currentItem }, true);
227
 
 
228
 
        }
229
 
    }
230
 
}