@@ -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+}