@@ -1,239 +0,0 @@
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 ".."
20−import "../../../qml/Hud"
21−import HudClient 0.1
22−import Unity.Test 0.1 as UT
23−
24−Hud {
25− id: hud
26− height: units.gu(80)
27− width: units.gu(50)
28−
29− // Mock shell to shut up some warnings
30− property QtObject shell: QtObject {
31− property QtObject applicationManager: QtObject {
32− id: applicationManager
33− property bool keyboardVisible: false
34− }
35− }
36−
37− HudClientStub {
38− id: hudClientStub
39− }
40−
41− UT.UnityTestCase {
42− name: "Hud"
43− when: windowShown
44−
45− function resetToInitialState() {
46− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
47−
48− hud.show()
49− hud.resetToInitialState()
50− hudClientStub.reset()
51− tryCompare(parametrizedActionsPage, "x", hud.width) // Make sure the parametrized page action animation is finished
52− }
53−
54− function test_hud_toolbar() {
55− var toolBar = findChild(hud, "toolBar")
56− resetToInitialState()
57−
58− var toolBarIconCount = 0
59− for (var i in toolBar.children) {
60− if (UT.Util.isInstanceOf(toolBar.children[i], "ToolBarIcon")) {
61− toolBarIconCount++
62− }
63− }
64− compare(toolBarIconCount, 4, "toolbar item count")
65−
66− mouseClick(toolBar.children[0], 0, 0)
67− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.undoToolbarItemValue(), "Click on undo")
68−
69− mouseClick(toolBar.children[1], 0, 0)
70− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.helpToolbarItemValue(), "Click on help")
71−
72− mouseClick(toolBar.children[2], 0, 0)
73− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.fullScreenToolbarItemValue(), "Click on fullscreen")
74−
75− mouseClick(toolBar.children[3], 0, 0)
76− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.preferencesToolbarItemValue(), "Click on preferences")
77−
78− compare(toolBar.children[0].enabled, true)
79− compare(toolBar.children[1].enabled, true)
80− compare(toolBar.children[2].enabled, true)
81− compare(toolBar.children[3].enabled, true)
82−
83− hudClientStub.setHelpToolbarItemEnabled(false);
84− compare(toolBar.children[0].enabled, true)
85− compare(toolBar.children[1].enabled, false)
86− compare(toolBar.children[2].enabled, true)
87− compare(toolBar.children[3].enabled, true)
88− }
89−
90− function test_hud_results() {
91− var resultListRepeater = findChild(hud, "resultListRepeater")
92− resetToInitialState()
93−
94− tryCompare(resultListRepeater, "count", 5)
95−
96− compare(resultListRepeater.itemAt(0).children[1].nameText, "Help", "First result name")
97− compare(resultListRepeater.itemAt(0).children[1].contextSnippetText, "Get Help", "First result description")
98−
99− compare(resultListRepeater.itemAt(1).children[1].nameText, "About", "Second result name")
100− compare(resultListRepeater.itemAt(1).children[1].contextSnippetText, "Show About", "Second result description")
101−
102− compare(resultListRepeater.itemAt(2).children[1].nameText, "Foo", "Third result name")
103− compare(resultListRepeater.itemAt(2).children[1].contextSnippetText, "Show Foo", "Third result description")
104−
105− compare(resultListRepeater.itemAt(3).children[1].nameText, "Bar", "Fourth result name")
106− compare(resultListRepeater.itemAt(3).children[1].contextSnippetText, "Show Bar", "Fourth result description")
107−
108− compare(resultListRepeater.itemAt(4).children[1].nameText, "FooBar", "Fifth result name")
109− compare(resultListRepeater.itemAt(4).children[1].contextSnippetText, "Show FooBar", "Fifth result description")
110− }
111−
112− function test_hud_set_query() {
113− var searchBar = findChild(hud, "searchBar")
114− resetToInitialState()
115−
116− compare(hudClientStub.lastSetQuery, "", "Query should be empty at start")
117−
118− searchBar.text = "Hi"
119− compare(hudClientStub.lastSetQuery, "Hi", "Query should be updated")
120−
121− searchBar.text = "Ho"
122− compare(hudClientStub.lastSetQuery, "Ho", "Query should be updated")
123− }
124−
125− function compareItemAnchoredAtTopOf(itemA, itemB, spacing, text) {
126− compare(itemA.y - spacing, itemB.y, text)
127− }
128−
129− function compareItemAnchoredAtBottomOf(itemA, itemB, spacing, text) {
130− compare(itemA.y + itemA.height + spacing, itemB.y + itemB.height, text)
131− }
132−
133− function compareItemAnchoredUnderItem(itemUnder, itemTop, spacing, text) {
134− compare(itemUnder.y - spacing, itemTop.y + itemTop.height, text)
135− }
136−
137− function compareItemAnchoredOverItem(itemTop, itemUnder, spacing, text) {
138− compareItemAnchoredUnderItem(itemUnder, itemTop, spacing, text)
139− }
140−
141− function test_hud_elements_positioning() {
142− var searchBar = findChild(hud, "searchBar")
143− var searchBarContainer = findChild(hud, "searchBarAnimator")
144− var resultListContainer = findChild(hud, "resultsCardAnimator")
145− var toolBarContainer = findChild(hud, "toolBarAnimator")
146− var toolBar = findChild(hud, "toolBar")
147− var handle = findChild(hud, "handle")
148− resetToInitialState()
149−
150− compare(toolBar.visible, true, "Toolbar is initially visible")
151− compareItemAnchoredAtTopOf(handle, hud, 0, "Handle is anchored at the top")
152− compareItemAnchoredAtBottomOf(searchBarContainer, hud, hud.elementsPadding, "SearchBar is anchored at the bottom")
153− compareItemAnchoredOverItem(toolBarContainer, searchBarContainer, 2 * hud.elementsPadding, "Toolbar is anchored over the searchBar")
154− compareItemAnchoredOverItem(resultListContainer, toolBarContainer, hud.elementsPadding, "ResultsList is anchored over the toolBar")
155−
156− mouseClick(searchBar, 0, 0)
157−
158− tryCompare(toolBar, "visible", false)
159− compareItemAnchoredAtTopOf(handle, hud, 0, "Handle is anchored at the top")
160− compareItemAnchoredUnderItem(searchBarContainer, handle, hud.elementsPadding + units.dp(1), "SearchBar is anchored under the handle")
161− compareItemAnchoredUnderItem(resultListContainer, searchBarContainer, hud.elementsPadding, "ResultsList is anchored under the searchBar")
162− }
163−
164− function test_hud_result_suggestion_execution() {
165− var resultListRepeater = findChild(hud, "resultListRepeater")
166− resetToInitialState()
167−
168− mouseClick(resultListRepeater.itemAt(1), 0, 0)
169− compare(hudClientStub.lastExecutedCommandRow, 1, "Last executed row was 1")
170− compare(hud.shown, false, "Should not be shown after executing")
171− }
172−
173− function number_of_activated_actions(activatedActionsObject) {
174− var activatedActions = 0
175− for(var key in activatedActionsObject) {
176− ++activatedActions
177− }
178− return activatedActions
179− }
180−
181− function test_hud_result_suggestion_parametrized_execution_and_back() {
182− var resultListRepeater = findChild(hud, "resultListRepeater")
183− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
184− var backButton = parametrizedActionsPage.children[1].children[0]
185− resetToInitialState()
186−
187− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
188− tryCompare(parametrizedActionsPage, "x", hud.width)
189−
190− mouseClick(resultListRepeater.itemAt(2), 0, 0)
191− compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
192− compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
193− compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
194− tryCompare(parametrizedActionsPage, "x", 0)
195−
196− var sliderLabel = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[0]
197− var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
198− compare(sliderLabel.text, "Item1Label")
199− compare(slider.minimumValue, 10)
200− compare(slider.maximumValue, 80)
201− compare(slider.live, true)
202− compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
203−
204− // Since it's live moving the slider will activate it already
205− var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
206− mouseClick(slider, units.gu(1), units.gu(1))
207− compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
208− compare(hudClientStub.activatedActions["costAction"], 10)
209−
210− mouseClick(backButton, 0, 0)
211− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden after going back")
212− compare(hudClientStub.lastParametrizedCommandCommited, false, "Cancelling does not commit")
213− tryCompare(parametrizedActionsPage, "x", hud.width)
214− }
215−
216− function test_hud_result_suggestion_parametrized_execution_and_confirm() {
217− var resultListRepeater = findChild(hud, "resultListRepeater")
218− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
219− var confirmButton = parametrizedActionsPage.children[1].children[2]
220− resetToInitialState()
221−
222− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
223− tryCompare(parametrizedActionsPage, "x", hud.width)
224−
225− mouseClick(resultListRepeater.itemAt(2), 0, 0)
226− compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
227− compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
228− compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
229− tryCompare(parametrizedActionsPage, "x", 0)
230− compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
231−
232− mouseClick(confirmButton, 0, 0)
233− compare(hud.shown, false, "Should not be shown after executing")
234− compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
235− compare(hudClientStub.activatedActions["costAction"], 75)
236− compare(hudClientStub.lastParametrizedCommandCommited, true, "Confirming does commit")
237− }
238− }
239−}