@@ -0,0 +1,121 @@
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 Ubuntu.Components 0.1
22+
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(80)
28+
29+ property var actionDataActions: {
30+ "actions": [{"label": "10", "id": "someid", "icon": Qt.resolvedUrl("../artwork/avatar@12.png"), "temporaryIcon": Qt.resolvedUrl("../artwork/emblem.png")},
31+ {"label": "12", "id": "someid2", "icon": Qt.resolvedUrl("../artwork/checkers.png"), "temporaryIcon": Qt.resolvedUrl("../artwork/background.png")},
32+ {"label": "", "id": "someid3", "icon": Qt.resolvedUrl("../artwork/music-player-design.png")},
33+ ]
34+ }
35+
36+ SignalSpy {
37+ id: spy
38+ signalName: "triggered"
39+ }
40+
41+ PreviewIconActions {
42+ id: preview
43+ widgetId: "iconActions"
44+ widgetData: actionDataActions
45+ onTriggered: {
46+ if (timer.index !== -1) {
47+ console.log("Processing other click, ignoring");
48+ return;
49+ }
50+
51+ for (var i in actionDataActions.actions) {
52+ if (actionId == actionDataActions.actions[i].id) {
53+ timer.index = i;
54+ break;
55+ }
56+ }
57+
58+ timer.start();
59+ console.log("triggered", widgetId, actionId);
60+ }
61+ width: parent.width
62+ clip: true
63+ }
64+
65+ Timer {
66+ id: timer
67+ property int index: -1
68+ interval: 500
69+ onTriggered: {
70+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
71+ preview.widgetDataChanged();
72+ index = -1;
73+ }
74+ }
75+
76+ UT.UnityTestCase {
77+ name: "PreviewIconActionTest"
78+ when: windowShown
79+
80+ function cleanup()
81+ {
82+ spy.clear();
83+ }
84+
85+ function test_checkButtonWithTemporary_data() {
86+ return [
87+ {tag: "with temporary", temporaryIcon: "emblem", index: 0},
88+ {tag: "without temporary", temporaryIcon: undefined, index: 2},
89+ ];
90+ }
91+
92+ function test_checkButtonWithTemporary(data) {
93+ spy.target = preview;
94+
95+ var buttonId = actionDataActions.actions[data.index].id;
96+ var buttonIcon = actionDataActions.actions[data.index].icon;
97+ var buttonTemporaryIcon = actionDataActions.actions[data.index]["temporaryIcon"];
98+ var buttonLabel = actionDataActions.actions[data.index].label;
99+
100+ var button = findChild(root, "button" + buttonId);
101+ var image = findChildsByType(button, "QQuickImage")[0];
102+ var label = findChildsByType(button, "Label")[0];
103+
104+ compare(image.source, buttonIcon);
105+ compare(label.text, buttonLabel);
106+ mouseClick(button);
107+ compare(spy.count, 1);
108+ compare(spy.signalArguments[0][1], buttonId);
109+
110+ if (buttonTemporaryIcon) {
111+ compare(image.source, buttonTemporaryIcon);
112+ }
113+
114+ tryCompareFunction(function() {
115+ var button = findChild(root, "button" + buttonId);
116+ var image = findChildsByType(button, "QQuickImage")[0];
117+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
118+ }, true);
119+ }
120+ }
121+}