@@ -0,0 +1,133 @@
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 "../../../Dash"
20+import Ubuntu.Components 0.1
21+import Unity.Test 0.1 as UT
22+
23+Item {
24+ id: shell
25+ width: units.gu(40)
26+ height: units.gu(80)
27+
28+ property ListModel searchHistory : ListModel {}
29+
30+ Dash {
31+ id: dash
32+ anchors.fill: parent
33+ showLensOnLoaded: "MockLens2"
34+ }
35+
36+ LensDelegateMapper {
37+ id: lens_delegate_mapper
38+ lensDelegateMapping: {
39+ "MockLens1": "../tests/qmltests/Dash/qml/fake_lensView1.qml",
40+ "MockLens2": "../tests/qmltests/Dash/qml/fake_lensView2.qml",
41+ "MockLens3": "../tests/qmltests/Dash/qml/fake_lensView3.qml",
42+ "MockLens4": "../tests/qmltests/Dash/qml/fake_lensView4.qml"
43+ }
44+ genericLens: "../tests/qmltests/Dash/qml/fake_generic_lensView.qml"
45+ }
46+
47+ UT.UnityTestCase {
48+ name: "Dash"
49+ when: windowShown
50+
51+ property var lenses
52+
53+ Component.onCompleted: {
54+ var dashContent = findChild(dash, "dashContent");
55+ dashContent.lens_mapper = lens_delegate_mapper;
56+ lenses = dashContent.lenses;
57+ }
58+
59+ function init() {
60+ // clear and reload the lenses.
61+ lenses.clear();
62+ var dashContentList = findChild(dash, "dashContentList");
63+ verify(dashContentList != undefined);
64+ tryCompare(dashContentList, "count", 0);
65+ lenses.load();
66+ }
67+
68+ function get_lens_data() {
69+ return [
70+ { tag: "MockLens1", visual_index: 0, should_be_visible: true },
71+ { tag: "MockLens2", visual_index: -1, should_be_visible: false },
72+ { tag: "MockLens3", visual_index: 1, should_be_visible: true },
73+ { tag: "MockLens4", visual_index: 2, should_be_visible: true },
74+ { tag: "MockLens5", visual_index: 3, should_be_visible: true },
75+ ]
76+ }
77+
78+ function test_set_current_lens_data() {
79+ return get_lens_data()
80+ }
81+
82+ function test_set_current_lens(data) {
83+ // wait for lenses to load
84+ tryCompare(lenses, "loaded", true);
85+
86+ var dashbar = findChild(dash, "dashbar");
87+ verify(dashbar != undefined)
88+ var dashContent = findChild(dash, "dashContent");
89+ var current_index = dashContent.currentIndex;
90+
91+ dash.setCurrentLens(data.tag, true, false);
92+ compare(dashContent.currentIndex, data.should_be_visible ? data.visual_index : current_index);
93+ compare(dashbar.currentIndex, data.should_be_visible ? data.visual_index : current_index);
94+ }
95+
96+ function test_show_lens_on_load_data() {
97+ return get_lens_data()
98+ }
99+
100+ function test_show_lens_on_load(data) {
101+ if (data.should_be_visible == false) {
102+ console.log("Not testing " + data.tag + ": not visible");
103+ return;
104+ }
105+ dash.showLensOnLoaded = data.tag
106+
107+ var dashContentList = findChild(dash, "dashContentList");
108+ verify(dashContentList != undefined);
109+ tryCompare(dashContentList, "currentIndex", data.visual_index);
110+ }
111+
112+ function test_dash_bar_set_index_connection_data() {
113+ return get_lens_data()
114+ }
115+
116+ function test_dash_bar_set_index_connection(data) {
117+ if (data.should_be_visible == false) {
118+ console.log("Not testing " + data.tag + ": not visible");
119+ return;
120+ }
121+ // wait for lenses to load
122+ tryCompare(lenses, "loaded", true);
123+
124+ var dashbar = findChild(dash, "dashbar");
125+ verify(dashbar != undefined)
126+ var dashContent = findChild(dash, "dashContent");
127+ var current_index = dashContent.currentIndex;
128+
129+ dashbar.itemSelected(data.visual_index);
130+ compare(dashContent.currentIndex, data.should_be_visible ? data.visual_index : current_index);
131+ }
132+ }
133+}