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
20
import Ubuntu.Components 0.1 as UC
22
import "../../../qml/Panel"
23
import "../../../qml/Components"
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.
36
anchors.fill: indicators
44
width: (shell.width > units.gu(60)) ? units.gu(40) : shell.width
49
openedHeight: parent.height - button.height
54
text: indicators.shown ? "Hide" : "Show"
63
if (!indicators.shown) {
76
indicators.initialise();
79
tryCompare(indicators.hideAnimation, "running", false);
80
tryCompare(indicators, "state", "initial");
83
// Showing the indicators should fully open the indicator panel.
84
function test_show() {
86
tryCompare(indicators, "fullyOpened", true);
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()
93
// tests changing the lateral position of the revealer activates the correct indicator items.
95
var indicatorRow = findChild(indicators, "indicatorRow")
96
verify(indicatorRow !== null);
97
var indicatorRowItems = findChild(indicatorRow, "indicatorRowItems");
98
verify(indicatorRowItems !== null);
100
for (var i = 0; i < indicatorRowItems.count; i++) {
101
var indicatorItem = findChild(indicatorRowItems, "item" + i);
103
if (!indicatorItem.visible)
106
var indicatorPosition = indicators.mapFromItem(indicatorItem,
107
indicatorItem.width/2, indicatorItem.height/2);
109
touchFlick(indicators,
110
indicatorPosition.x, indicatorPosition.y,
111
indicatorPosition.x, indicators.openedHeight * 0.4,
112
true /* beginTouch */, false /* endTouch */);
114
compare(indicatorRow.currentItem, indicatorItem,
115
"Incorrect item activated at position " + i);
117
touchFlick(indicators,
118
indicatorPosition.x, indicators.openedHeight * 0.4,
119
indicatorPosition.x, indicatorPosition.y,
120
false /* beginTouch */, true /* endTouch */);
122
// wait until fully closed
123
tryCompare(indicators, "height", indicators.panelHeight);
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.
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.");
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.");
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");
152
function test_fully_open() {
153
indicators.height = indicators.openedHeight
154
compare(indicators.partiallyOpened, false);
155
compare(indicators.fullyOpened, true);
158
function init_invisible_indicator(identifier) {
159
tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
160
var item = findChild(indicators, identifier+"-delegate");
162
item.enabled = false;
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] }];
173
function test_row_visible_menuContent_visible(data) {
176
var contentListView = findChild(indicators, "indicatorsContentListView");
177
var indicatorRowItems = findChild(indicators, "indicatorRowItems");
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));
187
tryCompare(indicatorRowItems, "count", count);
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");
194
tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== null }, data.visible[i]);
197
tryCompareFunction(function() { return findChild(contentListView, pageName) !== null }, data.visible[i]);
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" }];
208
function test_indicator_visible_correct_menu(data) {
209
var contentListView = findChild(indicators, "indicatorsContentListView");
210
var indicatorRow = findChild(indicators, "indicatorRow");
213
indicatorRow.setCurrentItemIndex(data.currentIndex);
214
tryCompare(indicators, "fullyOpened", true);
216
for (var i = 0; i< data.visible.length; i++) {
217
if (data.visible[i] === false) {
218
init_invisible_indicator("indicator-fake" + (i + 1));
222
// check for current selected item
223
tryCompare(indicatorRow, "currentItemIndex", data.expectedIndex);
225
// check for current selected tab
226
tryCompareFunction(function() { return findChild(contentListView, data.expextedMenu) === contentListView.currentItem }, true);