on xenial help sign in
add tests for gnericPreview
62b4defMichael Zanetti
Dash/Generic/GenericPreview.qml+10−6
@@ -24,22 +24,22 @@ import "../Previews"
24
24
25DashPreview {
25DashPreview {
26 id: genericPreview
26 id: genericPreview
27− property url url: previewData.image
28
27
29 previewImages: previewImagesComponent
28 previewImages: previewImagesComponent
30 header: headerComponent
29 header: headerComponent
31− actions: previewData.infoMap["show_progressbar"] ? progressComponent : actionsComponent
30+ actions: (previewData.infoMap !== undefined && previewData.infoMap["show_progressbar"]) ? progressComponent : actionsComponent
32 description: descriptionComponent
31 description: descriptionComponent
33
32
34 Component {
33 Component {
35 id: previewImagesComponent
34 id: previewImagesComponent
36 LazyImage {
35 LazyImage {
36+ objectName: "genericPreviewImage"
37 anchors {
37 anchors {
38 left: parent.left
38 left: parent.left
39 right: parent.right
39 right: parent.right
40 }
40 }
41 scaleTo: "width"
41 scaleTo: "width"
42− source: genericPreview.url
42+ source: genericPreview.previewData.image
43 height: implicitHeight
43 height: implicitHeight
44 }
44 }
45 }
45 }
@@ -131,15 +131,17 @@ DashPreview {
131 }
131 }
132
132
133 Column {
133 Column {
134− id: infoItem
134+ objectName: "infoHintColumn"
135 anchors {
135 anchors {
136 left: parent.left
136 left: parent.left
137 right: parent.right
137 right: parent.right
138 }
138 }
139 Repeater {
139 Repeater {
140+ objectName: "infoHintRepeater"
140 model: previewData.infoHints
141 model: previewData.infoHints
141
142
142 delegate: Item {
143 delegate: Item {
144+ objectName: "infoHintItem" + index
143 width: parent.width
145 width: parent.width
144 height: units.gu(5)
146 height: units.gu(5)
145 Row {
147 Row {
@@ -149,7 +151,8 @@ DashPreview {
149 anchors.verticalCenter: parent.verticalCenter
151 anchors.verticalCenter: parent.verticalCenter
150
152
151 Label {
153 Label {
154+ objectName: "displayNameLabel"
152− visible: directedLabel.visible
155+ visible: valueLabel.visible
153 fontSize: "small"
156 fontSize: "small"
154 opacity: 0.9
157 opacity: 0.9
155 color: "white"
158 color: "white"
@@ -160,7 +163,8 @@ DashPreview {
160 styleColor: "black"
163 styleColor: "black"
161 }
164 }
162 Label {
165 Label {
163− id: directedLabel
166+ id: valueLabel
167+ objectName: "valueLabel"
164 visible: modelData.value != ""
168 visible: modelData.value != ""
165 fontSize: "small"
169 fontSize: "small"
166 opacity: 0.6
170 opacity: 0.6
tests/qmltests/CMakeLists.txt+1
@@ -45,6 +45,7 @@ add_qml_test(Dash Dash IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAUL
45add_qml_test(Dash DashBar IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
45add_qml_test(Dash DashBar IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
46add_qml_test(Dash DashContent IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS})
46add_qml_test(Dash DashContent IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS})
47add_qml_test(Dash DashPreview)
47add_qml_test(Dash DashPreview)
48+add_qml_test(Dash GenericPreview)
48add_qml_test(Dash GenericScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
49add_qml_test(Dash GenericScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
49add_qml_test(Dash ScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
50add_qml_test(Dash ScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
50add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins
51add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins
tests/qmltests/Dash/Movie/tst_MoviePreview.qml+3−3
@@ -67,12 +67,12 @@ Item {
67 }
67 }
68
68
69 function test_numofbuttons() {
69 function test_numofbuttons() {
70− var buttons = findChild(moviePreview, "gridButtons");
70+ var buttons = findChild(moviePreview, "buttonList");
71 compare(buttons.count, 3);
71 compare(buttons.count, 3);
72
72
73 for(var i = 0; i < buttons.count; i++) {
73 for(var i = 0; i < buttons.count; i++) {
74− buttons.currentIndex = i;
74+ var button = findChild(appPreview, "button" + i);
75− buttons.currentItem.clicked();
75+ mouseClick(button, 1, 1);
76 }
76 }
77
77
78 var actions = get_actions_data();
78 var actions = get_actions_data();
tests/qmltests/Dash/tst_GenericPreview.qmlnew file+116
@@ -0,0 +1,116 @@
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/Generic"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ id: root
24+ width: units.gu(60)
25+ height: units.gu(80)
26+
27+ property var calls: []
28+ property int counter: 0
29+
30+ function get_actions_data() {
31+ return [
32+ { id: 123, displayName: "Button 1", iconHint: "image://theme/search" },
33+ { id: 456, displayName: "Button 2", iconHint: "image://theme/search" },
34+ { id: 789, displayName: "Button 3", iconHint: "image://theme/search" }
35+ ]
36+ }
37+
38+ function fake_callback(id, data){
39+ root.calls[root.calls.length] = id;
40+ }
41+
42+ // The component under test
43+ GenericPreview {
44+ id: genericPreview
45+ anchors.fill: parent
46+
47+ previewData: QtObject {
48+ id: dataObject
49+ property string rendererName: "preview-generic"
50+ property string title: "Unity Generic Preview"
51+ property string subtitle: "Subtitle"
52+ property string description: "This is the description"
53+ property string image: "../../tests/qmltests/Components/tst_LazyImage/square.png"
54+ property var actions: get_actions_data()
55+ property string year: "2013"
56+ property var execute: fake_callback
57+ property var infoHints: [{displayName: "info 1", value: "value 1"},
58+ {displayName: "info 2", value: "value 2"}
59+ ]
60+ }
61+ }
62+
63+ UT.UnityTestCase {
64+ name: "GenericPreviewTest"
65+ when: windowShown
66+
67+ function init() {
68+ waitForRendering(genericPreview)
69+ root.calls = new Array();
70+ }
71+
72+ function test_actions() {
73+ var buttons = findChild(genericPreview, "buttonList");
74+ compare(buttons.count, 3);
75+
76+ for(var i = 0; i < buttons.count; i++) {
77+ var button = findChild(genericPreview, "button" + i);
78+ mouseClick(button, 1, 1);
79+ }
80+
81+ var actions = get_actions_data();
82+ for(var i = 0; i < actions.length; i++) {
83+ compare(root.calls[i], actions[i].id);
84+ }
85+ }
86+
87+ function test_title() {
88+ var titleLabel = findChild(genericPreview, "titleLabel");
89+ compare(titleLabel.text, dataObject.title)
90+ }
91+
92+ function test_subtitle() {
93+ var subtitleLabel = findChild(genericPreview, "subtitleLabel");
94+ compare(subtitleLabel.text, dataObject.subtitle)
95+ }
96+
97+ function test_image() {
98+ var image = findChild(genericPreview, "genericPreviewImage");
99+ tryCompare(image, "height", genericPreview.width - units.gu(6))
100+ }
101+
102+ function test_infoHints() {
103+ var infoHintColumn = findChild(genericPreview, "infoHintColumn")
104+ var infoHintRepeater = findChild(genericPreview, "infoHintRepeater")
105+ compare(infoHintRepeater.count, dataObject.infoHints.length)
106+
107+ for (var i = 0; i < dataObject.infoHints.length; ++i) {
108+ var infoItem = findChild(infoHintColumn, "infoHintItem" + i)
109+ var displayName = findChild(infoItem, "displayNameLabel")
110+ compare(displayName.text, dataObject.infoHints[i].displayName)
111+ var value = findChild(infoItem, "valueLabel")
112+ compare(value.text, dataObject.infoHints[i].value)
113+ }
114+ }
115+ }
116+}