@@ -0,0 +1,112 @@
1+/*
2+ * Copyright 2014 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 "../../../../qml/Dash/Previews"
20+import Unity.Test 0.1 as UT
21+import Unity 0.1 as Unity
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(60)
26+ height: units.gu(80)
27+ color: Theme.palette.selected.background
28+
29+ Item {
30+ id: shell
31+
32+ anchors.fill: parent
33+ property var applicationManager: null
34+ }
35+
36+ Unity.FakePreviewModel {
37+ id: mockPreviewModel
38+ }
39+
40+ Preview {
41+ id: preview
42+ anchors.fill: parent
43+
44+ previewModel: mockPreviewModel
45+ }
46+
47+ SignalSpy {
48+ id: triggeredSpy
49+ target: mockPreviewModel
50+ signalName: "actionTriggered"
51+ }
52+
53+ UT.UnityTestCase {
54+ name: "Preview"
55+ when: windowShown
56+
57+ function test_triggered() {
58+ waitForRendering(preview);
59+ var widget = findChild(preview, "widget-3");
60+
61+ compare(typeof widget, "object", "Could not find the widget object.");
62+
63+ widget.triggered(widget.widgetId, "mockAction", {"mock": "data"});
64+
65+ triggeredSpy.wait();
66+
67+ var args = triggeredSpy.signalArguments[0];
68+
69+ compare(args[0], "widget-3", "Widget id not passed correctly.");
70+ compare(args[1], "mockAction", "Action id not passed correctly.");
71+ compare(args[2]["mock"], "data", "Data not passed correctly.");
72+ }
73+
74+ function test_showProcessing() {
75+ waitForRendering(preview);
76+ var widget = findChild(preview, "widget-3");
77+ widget.triggered(widget.widgetId, "mockAction", {"mock": "data"});
78+
79+ var processing = findChild(preview, "processingMouseArea");
80+
81+ tryCompare(processing, "enabled", true);
82+
83+ preview.previewModelChanged();
84+
85+ tryCompare(processing, "enabled", false);
86+ }
87+
88+ function test_containOnFocus() {
89+ waitForRendering(preview);
90+ var widget = findChild(preview, "widget-13");
91+
92+ widget.forceActiveFocus();
93+
94+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
95+
96+ tryCompareFunction(function () { return bottomLeft.y <= preview.height }, true);
97+ }
98+
99+ function test_containOnGrow() {
100+ waitForRendering(preview);
101+ var widget = findChild(preview, "widget-13");
102+
103+ widget.forceActiveFocus();
104+ widget.height += 200;
105+
106+ tryCompareFunction(function () {
107+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
108+ return bottomLeft.y <= preview.height
109+ }, true);
110+ }
111+ }
112+}