on xenial help sign in
Add PreviewWidgetFactory.
fab08c4Michał Sawicz
qml/Dash/Previews/PreviewWidgetFactory.qmlnew file+54
@@ -0,0 +1,54 @@
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 Lesser 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 Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+import QtQuick 2.0
19+import Ubuntu.Components 0.1
20+import Unity 0.1
21+
22+//! \brief This component loads the widgets based on widgetData["type"].
23+
24+Loader {
25+ id: root
26+
27+ //! Widget data, forwarded to the widget as is.
28+ property var widgetData: null
29+
30+ //! Triggered signal forwarded from the widgets.
31+ signal triggered(string widgetId, string actionId, var data)
32+
33+ source: {
34+ switch (widgetData && widgetData["type"]) {
35+ case "audio": return "PreviewAudioPlayback.qml";
36+ case "text": return "PreviewTextSummary.qml";
37+ case "gallery": return "PreviewImageGallery.qml";
38+ case "actions": return "PreviewActions.qml";
39+ default: return "";
40+ }
41+ }
42+
43+ Binding {
44+ target: root.item
45+ when: root.status === Loader.Ready
46+ property: "widgetData"
47+ value: root.widgetData
48+ }
49+
50+ Connections {
51+ target: root.item
52+ onTriggered: root.triggered(widgetId, actionId, data)
53+ }
54+}
tests/qmltests/CMakeLists.txt+1
@@ -54,6 +54,7 @@ add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IM
54add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
54add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
55add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
56add_qml_test(Dash/Music MusicPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
56add_qml_test(Dash/Music MusicPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
57+add_qml_test(Dash/Previews PreviewWidgetFactory IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
57add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
60add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/MockPreviewWidget.qmlnew file+27
@@ -0,0 +1,27 @@
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 Lesser 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 Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+import QtQuick 2.0
19+import "../../../../qml/Dash/Previews"
20+
21+PreviewWidget {
22+ objectName: "mockPreviewWidget"
23+
24+ function trigger() {
25+ triggered("mockWidget", "mockAction", {"mock": "data"})
26+ }
27+}
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qmlnew file+76
@@ -0,0 +1,76 @@
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 Ubuntu.Components 0.1
20+import "../../../../qml/Dash/Previews"
21+import Unity.Test 0.1 as UT
22+import QtMultimedia 5.0
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(80)
28+ color: Theme.palette.selected.background
29+
30+ PreviewWidgetFactory {
31+ id: factory
32+ anchors {
33+ left: parent.left
34+ right: parent.right
35+ }
36+
37+ source: Qt.resolvedUrl("MockPreviewWidget.qml")
38+
39+ widgetData: {
40+ "type": "mock"
41+ }
42+ }
43+
44+ SignalSpy {
45+ id: triggeredSpy
46+ target: factory
47+ signalName: "triggered"
48+ }
49+
50+ UT.UnityTestCase {
51+ name: "PreviewWidgetFactory"
52+ when: windowShown
53+
54+ property Item mockWidget: findChild(factory, "mockPreviewWidget")
55+
56+ function init() {
57+ verify(typeof mockWidget === "object", "Could not find the mock preview widget.");
58+ }
59+
60+ function test_previewData() {
61+ tryCompare(mockWidget, "widgetData", factory.widgetData);
62+ }
63+
64+ function test_triggered() {
65+ mockWidget.trigger();
66+
67+ triggeredSpy.wait();
68+
69+ var args = triggeredSpy.signalArguments[0];
70+
71+ compare(args[0], "mockWidget", "Widget id not passed correctly.");
72+ compare(args[1], "mockAction", "Action id not passed correctly.");
73+ compare(args[2]["mock"], "data", "Data not passed correctly.");
74+ }
75+ }
76+}