~macslow/unity8/fix-1475678

« back to all changes in this revision

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

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

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 "../../../Panel"
 
22
import "../../../Components"
 
23
 
 
24
/*
 
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.
 
28
*/
 
29
Item {
 
30
    id: shell
 
31
    width: units.gu(40)
 
32
    height: units.gu(80)
 
33
 
 
34
    PanelBackground {
 
35
        anchors.fill: indicators
 
36
    }
 
37
 
 
38
    Indicators {
 
39
        id: indicators
 
40
        anchors {
 
41
            right: parent.right
 
42
        }
 
43
        width: (shell.width > units.gu(60)) ? units.gu(40) : shell.width
 
44
        y: 0
 
45
        hintValue: indicatorRevealer.hintDisplacement
 
46
        shown: false
 
47
        revealer: indicatorRevealer
 
48
 
 
49
        openedHeight: parent.height - click_me.height
 
50
 
 
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 }
 
53
    }
 
54
 
 
55
    Revealer {
 
56
        anchors.fill: indicators
 
57
        id: indicatorRevealer
 
58
        hintDisplacement: indicators.panelHeight * 3
 
59
 
 
60
        openedValue: indicators.openedHeight - indicators.panelHeight
 
61
        closedValue: indicators.panelHeight
 
62
    }
 
63
 
 
64
    // Just a rect for clicking to open the indicators.
 
65
    Rectangle {
 
66
        id: click_me
 
67
        color: "red"
 
68
        anchors {
 
69
            bottom: shell.bottom
 
70
            left: parent.left
 
71
            right: parent.right
 
72
        }
 
73
        height: 50
 
74
 
 
75
        Text {
 
76
            text: "Click Me"
 
77
            horizontalAlignment: Text.AlignHCenter
 
78
            verticalAlignment: Text.AlignVCenter
 
79
            anchors.fill: parent
 
80
 
 
81
            MouseArea {
 
82
                anchors.fill: parent
 
83
 
 
84
                onClicked: {
 
85
                    if (!indicators.shown) {
 
86
                        indicators.openOverview();
 
87
                        indicators.show();
 
88
                    }
 
89
                    else {
 
90
                        indicators.hide();
 
91
                    }
 
92
                }
 
93
            }
 
94
        }
 
95
    }
 
96
 
 
97
    UT.UnityTestCase {
 
98
        name: "Indicators"
 
99
        when: windowShown
 
100
 
 
101
        function init() {
 
102
            indicators.hide();
 
103
            tryCompare(indicators.hideAnimation, "running", false);
 
104
            tryCompare(indicators, "state", "initial");
 
105
        }
 
106
 
 
107
        // Showing the indicators should fully open the indicator panel with the overview menu visible.
 
108
        function test_show() {
 
109
            indicators.show()
 
110
            tryCompare(indicators, "fullyOpened", true);
 
111
 
 
112
            // A show must open the indicators.
 
113
            compare(findChild(indicators, "indicatorRow").overviewActive, true, "Overview indicator should be active when opened overview.")
 
114
        }
 
115
 
 
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.")
 
120
        }
 
121
 
 
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() {
 
125
 
 
126
            var indicator_row = findChild(indicators, "indicatorRow");
 
127
            verify(indicator_row != undefined);
 
128
 
 
129
            indicators.show()
 
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.")
 
133
 
 
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;
 
138
 
 
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.")
 
141
                }
 
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.")
 
144
                }
 
145
 
 
146
                current_progress = current_progress - shell.height/20;
 
147
            }
 
148
        }
 
149
 
 
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()
 
153
        {
 
154
            // tests changing the lateral position of the revealer activates the correct indicator items.
 
155
 
 
156
            // This "should" put the indicators in "hint" state
 
157
            indicators.progress = indicators.hintValue;
 
158
 
 
159
            var indicator_row = findChild(indicators, "indicatorRow")
 
160
            var row_repeater = findChild(indicators, "rowRepeater")
 
161
 
 
162
            for (var i = 0; i < row_repeater.count; i++) {
 
163
                var indicator_item = row_repeater.itemAt(i);
 
164
 
 
165
                var indicator_position = indicator_row.row.x + indicator_item.x + indicator_item.width/2;
 
166
 
 
167
                indicatorRevealer.lateralPosition = indicator_position;
 
168
 
 
169
                compare(indicator_row.currentItem, indicator_item, "Incorrect item activated at position " + i);
 
170
            }
 
171
        }
 
172
 
 
173
        // PROGRESS TESTS
 
174
 
 
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.
 
178
 
 
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.");
 
182
        }
 
183
 
 
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.");
 
187
        }
 
188
 
 
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");
 
193
        }
 
194
 
 
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");
 
199
        }
 
200
 
 
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();
 
206
            indicators.show()
 
207
 
 
208
            var menuContent = findChild(indicators, "menuContent")
 
209
            compare(menuContent.__shown, true, "Indicator menu content should be shown after a indicator show.");
 
210
        }
 
211
    }
 
212
}