@@ -0,0 +1,126 @@
1+/*
2+ * Copyright 2015 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+ if (!testcase.running) {
48+ console.log("Processing other click, ignoring");
49+ }
50+ return;
51+ }
52+
53+ for (var i in actionDataActions.actions) {
54+ if (actionId == actionDataActions.actions[i].id) {
55+ timer.index = i;
56+ break;
57+ }
58+ }
59+
60+ timer.start();
61+ if (!testcase.running) {
62+ console.log("triggered", widgetId, actionId);
63+ }
64+ }
65+ width: parent.width
66+ clip: true
67+ }
68+
69+ Timer {
70+ id: timer
71+ property int index: -1
72+ interval: 500
73+ onTriggered: {
74+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
75+ preview.widgetDataChanged();
76+ index = -1;
77+ }
78+ }
79+
80+ UT.UnityTestCase {
81+ id: testcase
82+ name: "PreviewIconActionTest"
83+ when: windowShown
84+
85+ function cleanup()
86+ {
87+ spy.clear();
88+ }
89+
90+ function test_checkButtonWithTemporary_data() {
91+ return [
92+ {tag: "with temporary", temporaryIcon: "emblem", index: 0},
93+ {tag: "without temporary", temporaryIcon: undefined, index: 2},
94+ ];
95+ }
96+
97+ function test_checkButtonWithTemporary(data) {
98+ spy.target = preview;
99+
100+ var buttonId = actionDataActions.actions[data.index].id;
101+ var buttonIcon = actionDataActions.actions[data.index].icon;
102+ var buttonTemporaryIcon = actionDataActions.actions[data.index]["temporaryIcon"];
103+ var buttonLabel = actionDataActions.actions[data.index].label;
104+
105+ var button = findChild(root, "button" + buttonId);
106+ var image = findChildsByType(button, "QQuickImage")[0];
107+ var label = findChildsByType(button, "Label")[0];
108+
109+ compare(image.source, buttonIcon);
110+ compare(label.text, buttonLabel);
111+ mouseClick(button);
112+ compare(spy.count, 1);
113+ compare(spy.signalArguments[0][1], buttonId);
114+
115+ if (buttonTemporaryIcon) {
116+ compare(image.source, buttonTemporaryIcon);
117+ }
118+
119+ tryCompareFunction(function() {
120+ var button = findChild(root, "button" + buttonId);
121+ var image = findChildsByType(button, "QQuickImage")[0];
122+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
123+ }, true);
124+ }
125+ }
126+}