on xenial help sign in
Merged imagegallery branch and added tests for the previewimage
778cf03Andrea Cimitan
qml/Dash/Previews/PreviewImage.qml+1−1
@@ -29,7 +29,7 @@ PreviewWidget {
29 implicitHeight: units.gu(22)
29 implicitHeight: units.gu(22)
30
30
31 LazyImage {
31 LazyImage {
32− objectName: "image"
32+ objectName: "lazyImage"
33 anchors.fill: parent
33 anchors.fill: parent
34 scaleTo: "height"
34 scaleTo: "height"
35 source: widgetData["source"]
35 source: widgetData["source"]
qml/Dash/Previews/PreviewImageGallery.qmlnew file+58
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (C) 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 "../../Components"
19+
20+/*! This preview widget shows a horizontal list of images.
21+ * The URIs for the images should be an array in widgetData["sources"].
22+ */
23+
24+PreviewWidget {
25+ id: root
26+ implicitHeight: units.gu(22)
27+
28+ ListView {
29+ id: previewImageListView
30+ spacing: units.gu(1)
31+ anchors.fill: parent
32+ orientation: ListView.Horizontal
33+ cacheBuffer: width * 3
34+ model: root.widgetData["sources"]
35+
36+ LazyImage {
37+ objectName: "placeholderScreenshot"
38+ anchors {
39+ top: parent.top
40+ bottom: parent.bottom
41+ }
42+ scaleTo: "height"
43+ source: "broken_image"
44+ initialWidth: units.gu(13)
45+ visible: previewImageListView.count == 0
46+ }
47+
48+ delegate: LazyImage {
49+ anchors {
50+ top: parent.top
51+ bottom: parent.bottom
52+ }
53+ source: modelData ? modelData : ""
54+ scaleTo: "height"
55+ initialWidth: units.gu(13)
56+ }
57+ }
58+}
tests/qmltests/CMakeLists.txt+2
@@ -55,6 +55,8 @@ add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} $
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)
57add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
57add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58+add_qml_test(Dash/Previews PreviewImage IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59+add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
58add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
60add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
59add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
61add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
60 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
62 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
tests/qmltests/Dash/Previews/tst_PreviewImage.qml+53−2
@@ -1,6 +1,57 @@
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+
1import QtQuick 2.0
17import QtQuick 2.0
18+import QtTest 1.0
19+import "../../../../qml/Dash/Previews"
20+import Unity.Test 0.1 as UT
2
21
3Rectangle {
22Rectangle {
23+ id: root
4− width: 100
24+ width: units.gu(40)
5− height: 62
25+ height: units.gu(80)
26+ color: "lightgrey"
27+
28+ property var widgetData0: {
29+ "source": ""
30+ }
31+
32+ property var widgetData1: {
33+ "source": "../../graphics/phone_background.jpg",
34+ "zoomable": false
35+ }
36+
37+ PreviewImage {
38+ id: image
39+ width: parent.width
40+ widgetData: widgetData1
41+ }
42+
43+ UT.UnityTestCase {
44+ name: "PreviewImageTest"
45+ when: windowShown
46+
47+ function test_loadImage() {
48+ var lazyImage = findChild(image, "lazyImage");
49+
50+ image.widgetData = widgetData0;
51+ tryCompare(lazyImage.state, "default");
52+
53+ image.widgetData = widgetData1;
54+ tryCompare(lazyImage.state, "ready");
55+ }
56+ }
6}
57}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qmlnew file+56
@@ -0,0 +1,56 @@
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+
22+Rectangle {
23+ id: root
24+ width: units.gu(60)
25+ height: units.gu(80)
26+ color: "lightgrey"
27+
28+ property var sourcesModel0: {
29+ "sources": []
30+ }
31+
32+ property var sourcesModel1: {
33+ "sources": [
34+ "../../graphics/phone_background.jpg",
35+ "../../graphics/tablet_background.jpg",
36+ "../../graphics/clock@18.png"
37+ ]
38+ }
39+
40+ PreviewImageGallery {
41+ id: imageGallery
42+ width: parent.width
43+ widgetData: sourcesModel1
44+ }
45+
46+ UT.UnityTestCase {
47+ name: "PreviewImageGalleryTest"
48+ when: windowShown
49+
50+ function test_changeEmptyModel() {
51+ imageGallery.widgetData = sourcesModel0;
52+ var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
53+ compare(placeholderScreenshot.visible, true);
54+ }
55+ }
56+}