on xenial help sign in
Added Dash tests.
commit1fe83ec613f233cff7fb4b615240367b69709e71 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 7 Jun 2013, 11:22 (13 years ago) parentdc7b34f
12 files changed+254−72
Dash/Dash.qml+2 Dash/DashContent.qml+5−16 Dash/LensDelegateMapper.qml+35 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/qml/FakeLensView.qml+63−36 tests/qmltests/Dash/qml/fake_generic_lensView.qml+1−3 tests/qmltests/Dash/qml/fake_lensView1.qml+1−3 tests/qmltests/Dash/qml/fake_lensView2.qml+1−3 tests/qmltests/Dash/qml/fake_lensView3.qml+1−3 tests/qmltests/Dash/qml/fake_lensView4.qml+1−3 tests/qmltests/Dash/tst_Dash.qml+133 tests/qmltests/Dash/tst_DashContent.qml+10−5
Dash/Dash.qml+2
@@ -59,6 +59,7 @@ Showable {
5959
6060 DashContent {
6161 id: dashContent
62+ objectName: "dashContent"
6263 anchors.fill: parent
6364 model: filteredLenses
6465 lenses: lenses
@@ -79,6 +80,7 @@ Showable {
7980
8081 DashBar {
8182 id: dashbar
83+ objectName: "dashbar"
8284 anchors.bottom: parent.bottom
8385 anchors.left: parent.left
8486 anchors.right: parent.right
Dash/DashContent.qml+5−16
@@ -28,6 +28,8 @@ Item {
2828 property real contentProgress: Math.max(0, Math.min(dashContentList.contentX / (dashContentList.contentWidth - dashContentList.width), units.dp(1)))
2929 property alias currentIndex: dashContentList.currentIndex
3030
31+ property LensDelegateMapper lens_mapper : LensDelegateMapper {}
32+
3133 signal movementStarted()
3234 signal movementEnded()
3335 signal contentFlickStarted()
@@ -79,14 +81,6 @@ Item {
7981 }
8082 }
8183
82− property var lensDelegateMapping: {"mockmusic.lens": "DashMusic.qml",
83− "applications.lens": "DashApps.qml",
84− "home.lens": "DashHome.qml",
85− "mockvideos.lens": "DashVideos.qml",
86− "people.lens": "DashPeople.qml",
87− }
88− property string genericLens: "GenericLensView.qml"
89−
9084 ListView {
9185 id: dashContentList
9286 objectName: "dashContentList"
@@ -121,14 +115,7 @@ Item {
121115 width: ListView.view.width
122116 height: ListView.view.height
123117 asynchronous: true
124− source: {
125− var customLens = lensDelegateMapping[lens.id]
126− if (customLens) {
127− return customLens
128− } else {
129− return genericLens
130− }
131− }
118+ source: lens_mapper.map(lens.id)
132119 onLoaded: {
133120 item.lens = Qt.binding(function() { return lens })
134121 item.isCurrent = Qt.binding(function() { return ListView.isCurrentItem })
@@ -150,6 +137,8 @@ Item {
150137 }
151138 }
152139 }
140+
141+ Component.onDestruction: active = false
153142 }
154143 }
155144}
Dash/LensDelegateMapper.qmlnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 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+
19+QtObject {
20+ property var lensDelegateMapping: {"mockmusic.lens": "DashMusic.qml",
21+ "applications.lens": "DashApps.qml",
22+ "home.lens": "DashHome.qml",
23+ "mockvideos.lens": "DashVideos.qml",
24+ "people.lens": "DashPeople.qml",
25+ }
26+ property string genericLens: "GenericLensView.qml"
27+
28+ function map(lensId) {
29+ var customLens = lensDelegateMapping[lensId]
30+ if (customLens != undefined) {
31+ return customLens
32+ }
33+ return genericLens
34+ }
35+}
tests/qmltests/CMakeLists.txt+1
@@ -37,6 +37,7 @@ add_qml_test(Components Stage IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS}
3737 ${CMAKE_BINARY_DIR}/plugins)
3838add_qml_test(Components Tile)
3939add_qml_test(Components PageHeader)
40+add_qml_test(Dash Dash IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
4041add_qml_test(Dash DashBar IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
4142add_qml_test(Dash DashContent IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS})
4243add_qml_test(Dash DashPreview)
tests/qmltests/Dash/qml/FakeLensView.qml+63−36
@@ -22,16 +22,14 @@ FocusScope {
2222 property Lens lens : null
2323 property bool isCurrent : false
2424
25− property alias rect_color1 : rect1.color
26− property alias rect_color2 : rect2.color
27− property alias rect_color3 : rect3.color
28−
2925 property ListModel searchHistory
3026
3127 signal endReached
3228 signal movementStarted
3329 signal positionedAtBeginning
3430
31+ property alias back_color : back.color
32+
3533 onEndReached: {
3634 if (shell != undefined && shell.lens_status != undefined) {
3735 shell.lens_status[lens.id].endReached++;
@@ -48,45 +46,74 @@ FocusScope {
4846 }
4947 }
5048
49+ Rectangle {
50+ id: back
51+ anchors.fill: parent
52+ color: "grey"
53+ }
54+
55+ function randomBg()
56+ {
57+ var hex1=new Array("4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
58+ var bg="#"+hex1[Math.floor(Math.random()*hex1.length)]+
59+ hex1[Math.floor(Math.random()*hex1.length)]+
60+ hex1[Math.floor(Math.random()*hex1.length)]+
61+ hex1[Math.floor(Math.random()*hex1.length)]+
62+ hex1[Math.floor(Math.random()*hex1.length)]+
63+ hex1[Math.floor(Math.random()*hex1.length)]
64+ return bg
65+ }
5166
52− Column {
67+
68+ ListView {
69+ id: list_view
5370 anchors.fill: parent
54− Rectangle {
55− id: rect1
56− height: parent.height/3; width: parent.width;
71+ model: lens ? lens.categories : null
72+ orientation: ListView.Vertical
5773
58− Text {
59− id: label1
60− anchors.fill: parent
61− verticalAlignment: Text.AlignVCenter
62− horizontalAlignment: Text.AlignHCenter
63− text: lens ? lens.id : ""
64− }
65− }
74+ delegate: Column {
75+ id: column
76+ width: list_view.width
77+ height: childrenRect.height
6678
67− Rectangle {
68− id: rect2
69− height: parent.height/3; width: parent.width
79+ Rectangle {
80+ width: list_view.width
81+ height: units.gu(3)
82+ color: randomBg()
7083
71− Text {
72− id: label2
73− anchors.fill: parent
74− verticalAlignment: Text.AlignVCenter
75− horizontalAlignment: Text.AlignHCenter
76− text: lens ? lens.id : ""
84+ Text {
85+ text: name
86+ font.family: "Ubuntu"
87+ font.weight: Font.Bold
88+ font.pixelSize: 20
89+ anchors.horizontalCenter: parent.horizontalCenter
90+ }
7791 }
78− }
79−
80− Rectangle {
81− id: rect3
82− height: parent.height/3; width: parent.width
92+ GridView {
93+ id: results_grid
94+ model: results
95+ cellWidth: units.gu(10); cellHeight: units.gu(10)
96+ height: childrenRect.height
97+ width: list_view.width
98+ interactive: false
8399
84− Text {
85− id: label3
86− anchors.fill: parent
87− verticalAlignment: Text.AlignVCenter
88− horizontalAlignment: Text.AlignHCenter
89− text: lens ? lens.id : ""
100+ delegate: Component {
101+ id: resultDelegate
102+ Item {
103+ width: results_grid.cellWidth; height: results_grid.cellHeight
104+ Column {
105+ anchors.verticalCenter: parent.verticalCenter
106+ anchors.horizontalCenter: parent.horizontalCenter
107+ Image {
108+ width: units.gu(5)
109+ height: units.gu(5)
110+ source: column_1
111+ anchors.horizontalCenter: parent.horizontalCenter
112+ }
113+ Text { text: column_4; anchors.horizontalCenter: parent.horizontalCenter }
114+ }
115+ }
116+ }
90117 }
91118 }
92119 }
tests/qmltests/Dash/qml/fake_generic_lensView.qml+1−3
@@ -20,7 +20,5 @@ FakeLensView {
2020 id: fake_generic_lensView
2121 objectName: "fake_generic_lensView"
2222
23− rect_color1: "blue"
24− rect_color2: "orange"
25− rect_color3: "teal"
23+ back_color: "#D0D0D0"
2624}
tests/qmltests/Dash/qml/fake_lensView1.qml+1−3
@@ -20,7 +20,5 @@ FakeLensView {
2020 id: fake_lensView1
2121 objectName: "fake_lensView1"
2222
23− rect_color1: "red"
24− rect_color2: "green"
25− rect_color3: "blue"
23+ back_color: "#909090"
2624}
tests/qmltests/Dash/qml/fake_lensView2.qml+1−3
@@ -20,7 +20,5 @@ FakeLensView {
2020 id: fake_lensView2
2121 objectName: "fake_lensView2"
2222
23− rect_color1: "orange"
24− rect_color2: "grey"
25− rect_color3: "purple"
23+ back_color: "#A0A0A0"
2624}
tests/qmltests/Dash/qml/fake_lensView3.qml+1−3
@@ -20,7 +20,5 @@ FakeLensView {
2020 id: fake_lensView3
2121 objectName: "fake_lensView3"
2222
23− rect_color1: "yellow"
24− rect_color2: "cyan"
25− rect_color3: "white"
23+ back_color: "#B0B0B0"
2624}
tests/qmltests/Dash/qml/fake_lensView4.qml+1−3
@@ -20,7 +20,5 @@ FakeLensView {
2020 id: fake_lensView4
2121 objectName: "fake_lensView4"
2222
23− rect_color1: "grey"
24− rect_color2: "purple"
25− rect_color3: "red"
23+ back_color: "#C0C0C0"
2624}
tests/qmltests/Dash/tst_Dash.qmlnew file+133
@@ -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+}
tests/qmltests/Dash/tst_DashContent.qml+10−5
@@ -47,12 +47,17 @@ Item {
4747 model: lensesModel
4848 lenses : lensesModel
4949
50− lensDelegateMapping: { "MockLens3" : "../tests/qmltests/Dash/qml/fake_lensView3.qml",
51− "MockLens2" : "../tests/qmltests/Dash/qml/fake_lensView2.qml",
52− "MockLens1" : "../tests/qmltests/Dash/qml/fake_lensView1.qml",
53− "MockLens4" : "../tests/qmltests/Dash/qml/fake_lensView4.qml"
54− }
50+ lens_mapper : lens_delegate_mapper
51+ }
5552
53+ LensDelegateMapper {
54+ id: lens_delegate_mapper
55+ lensDelegateMapping: {
56+ "MockLens1": "../tests/qmltests/Dash/qml/fake_lensView1.qml",
57+ "MockLens2": "../tests/qmltests/Dash/qml/fake_lensView2.qml",
58+ "MockLens3": "../tests/qmltests/Dash/qml/fake_lensView3.qml",
59+ "MockLens4": "../tests/qmltests/Dash/qml/fake_lensView4.qml"
60+ }
5661 genericLens: "../tests/qmltests/Dash/qml/fake_generic_lensView.qml"
5762 }
5863