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 "../../../Panel"
22
import "../../../Components"
25
This tests the Indicators 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. There is a clickable area
27
marked "Click Me" which can be used to expose the indicators.
35
anchors.fill: indicators
43
width: (shell.width > units.gu(60)) ? units.gu(40) : shell.width
45
hintValue: indicatorRevealer.hintDisplacement
47
revealer: indicatorRevealer
49
openedHeight: parent.height - click_me.height
51
showAnimation: NumberAnimation { property: "progress"; duration: 350; to: indicatorRevealer.openedValue; easing.type: Easing.OutCubic }
52
hideAnimation: NumberAnimation { property: "progress"; duration: 350; to: indicatorRevealer.closedValue; easing.type: Easing.OutCubic }
56
anchors.fill: indicators
58
hintDisplacement: indicators.panelHeight * 3
60
openedValue: indicators.openedHeight - indicators.panelHeight
61
closedValue: indicators.panelHeight
64
// Just a rect for clicking to open the indicators.
77
horizontalAlignment: Text.AlignHCenter
78
verticalAlignment: Text.AlignVCenter
85
if (!indicators.shown) {
86
indicators.openOverview();
103
tryCompare(indicators.hideAnimation, "running", false);
104
tryCompare(indicators, "state", "initial");
107
// Showing the indicators should fully open the indicator panel with the overview menu visible.
108
function test_show() {
110
tryCompare(indicators, "fullyOpened", true);
112
// A show must open the indicators.
113
compare(findChild(indicators, "indicatorRow").overviewActive, true, "Overview indicator should be active when opened overview.")
116
// Opening the overview menu will activate the overview panel.
117
function test_open_overview() {
118
indicators.openOverview();
119
compare(findChild(indicators, "indicatorRow").overviewActive, true, "Overview should be active when opened overview.")
122
// Showing the indicators, then changing the progress (simulating drag) should keep the overview panel open until
123
// the reveal state is reached.
124
function test_slow_close_open_overview() {
126
var indicator_row = findChild(indicators, "indicatorRow");
127
verify(indicator_row != undefined);
130
// wait for animation to end. (progress needs to be updated)
131
tryCompare(indicators.showAnimation, "running", false);
132
compare(indicator_row.overviewActive, true, "Overview should be active when opened overview.")
134
// iteratively decrease the progress and ensure that it keeps the correct behaviour
135
var current_progress = indicators.progress - shell.height/20;
136
while (current_progress > 0) {
137
indicators.progress = current_progress;
139
if (indicators.state == "commit" || indicators.state == "locked") {
140
compare(indicator_row.overviewActive, true, "Overview should be active when in locked or commit state after show.")
142
else if (indicators.state == "reveal" || indicators.state == "hint") {
143
compare(indicator_row.overviewActive, false, "Overview should be not active when not in commit or locked state.")
146
current_progress = current_progress - shell.height/20;
150
// Test the change in the revealer lateral position changes the current panel menu to fit the position
151
// of the indicator in the row.
152
function test_change_revealer_lateral_position()
154
// tests changing the lateral position of the revealer activates the correct indicator items.
156
// This "should" put the indicators in "hint" state
157
indicators.progress = indicators.hintValue;
159
var indicator_row = findChild(indicators, "indicatorRow")
160
var row_repeater = findChild(indicators, "rowRepeater")
162
for (var i = 0; i < row_repeater.count; i++) {
163
var indicator_item = row_repeater.itemAt(i);
165
var indicator_position = indicator_row.row.x + indicator_item.x + indicator_item.width/2;
167
indicatorRevealer.lateralPosition = indicator_position;
169
compare(indicator_row.currentItem, indicator_item, "Incorrect item activated at position " + i);
175
// values for specific state changes are subject to internal decisions, so we can't determine the true progress value
176
// which would cause the state to change without making too many assuptyions
177
// However, we can assume that a partially opened panel will not be initial, and fully opened panel will be locked.
179
function test_progress_changes_state_to_not_initial() {
180
indicators.progress = indicatorRevealer.closedValue + (indicatorRevealer.openedValue - indicatorRevealer.closedValue)/2;
181
compare(indicators.state!="initial", true, "Indicators should not be in initial state when partially opened.");
184
function test_progress_changes_state_to_locked() {
185
indicators.progress = indicators.openedHeight;
186
compare(indicators.state, "locked", "Indicators should be locked when fully opened.");
189
function test_partially_open() {
190
indicators.progress = indicatorRevealer.closedValue + (indicatorRevealer.openedValue - indicatorRevealer.closedValue)/2;
191
compare(indicators.partiallyOpened, true, "Indicator should show as partially opened when in between revealer closedValue & openedValue height");
192
compare(indicators.fullyOpened, false, "Indicator should not show as fully opened when in between revealer closedValue & openedValue height");
195
function test_fully_open() {
196
indicators.progress = indicatorRevealer.openedValue
197
compare(indicators.partiallyOpened, false, "Indicator should show as fully opened when in between revealer closedValue & openedValue height");
198
compare(indicators.fullyOpened, true, "Indicator should not show as fully opened when at revealer openedValue height");
201
// The indicator menu content should be shown if the indicators are show through an animation before they
202
// enter a furthur state through a progress change (eg press indicator row, drag down a less then hint
203
// threshold and release to show
204
function test_menu_open_on_hint_drag() {
205
indicators.handlePress();
208
var menuContent = findChild(indicators, "menuContent")
209
compare(menuContent.__shown, true, "Indicator menu content should be shown after a indicator show.");