on xenial help sign in
Add tests
3bac84cAndrea Cimitan
qml/Dash/Previews/PreviewImageGallery.qml+7−4
@@ -30,6 +30,7 @@ PreviewWidget {
30
30
31 ListView {
31 ListView {
32 id: previewImageListView
32 id: previewImageListView
33+ objectName: "previewImageListView"
33 spacing: units.gu(1)
34 spacing: units.gu(1)
34 anchors.fill: parent
35 anchors.fill: parent
35 orientation: ListView.Horizontal
36 orientation: ListView.Horizontal
@@ -50,6 +51,7 @@ PreviewWidget {
50 }
51 }
51
52
52 delegate: LazyImage {
53 delegate: LazyImage {
54+ objectName: "previewImage" + index
53 anchors {
55 anchors {
54 top: parent.top
56 top: parent.top
55 bottom: parent.bottom
57 bottom: parent.bottom
@@ -99,6 +101,7 @@ PreviewWidget {
99
101
100 ListView {
102 ListView {
101 id: slideShowListView
103 id: slideShowListView
104+ objectName: "slideShowListView"
102 anchors.fill: parent
105 anchors.fill: parent
103 orientation: ListView.Horizontal
106 orientation: ListView.Horizontal
104 highlightRangeMode: ListView.StrictlyEnforceRange
107 highlightRangeMode: ListView.StrictlyEnforceRange
@@ -144,8 +147,8 @@ PreviewWidget {
144 }
147 }
145
148
146 AbstractButton {
149 AbstractButton {
147− id: slideShowBackButton
150+ id: slideShowCloseButton
148− objectName: "slideShowBackButton"
151+ objectName: "slideShowCloseButton"
149 anchors {
152 anchors {
150 top: parent.top
153 top: parent.top
151 bottom: parent.bottom
154 bottom: parent.bottom
@@ -158,7 +161,7 @@ PreviewWidget {
158 Rectangle {
161 Rectangle {
159 anchors.fill: parent
162 anchors.fill: parent
160 color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
163 color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
161− visible: slideShowBackButton.pressed
164+ visible: slideShowCloseButton.pressed
162 }
165 }
163
166
164 Icon {
167 Icon {
@@ -167,7 +170,7 @@ PreviewWidget {
167 width: units.gu(2.5)
170 width: units.gu(2.5)
168 height: width
171 height: width
169 color: Theme.palette.normal.foregroundText
172 color: Theme.palette.normal.foregroundText
170− name: "back"
173+ name: "close"
171 }
174 }
172 }
175 }
173 }
176 }
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+50−1
@@ -21,7 +21,7 @@ import Unity.Test 0.1 as UT
21
21
22Rectangle {
22Rectangle {
23 id: root
23 id: root
24− width: units.gu(60)
24+ width: units.gu(80)
25 height: units.gu(80)
25 height: units.gu(80)
26 color: "lightgrey"
26 color: "lightgrey"
27
27
@@ -44,13 +44,62 @@ Rectangle {
44 }
44 }
45
45
46 UT.UnityTestCase {
46 UT.UnityTestCase {
47+ id: testCase
47 name: "PreviewImageGalleryTest"
48 name: "PreviewImageGalleryTest"
48 when: windowShown
49 when: windowShown
49
50
51+ property Item slideShow: findChild(imageGallery.rootItem, "slideShow")
52+ property Item slideShowCloseButton: findChild(slideShow, "slideShowCloseButton")
53+ property Item slideShowListView: findChild(slideShow, "slideShowListView")
54+
55+ function cleanup() {
56+ imageGallery.widgetData = sourcesModel1;
57+ slideShow.visible = false;
58+ }
59+
50 function test_changeEmptyModel() {
60 function test_changeEmptyModel() {
51 imageGallery.widgetData = sourcesModel0;
61 imageGallery.widgetData = sourcesModel0;
52 var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
62 var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
53 compare(placeholderScreenshot.visible, true);
63 compare(placeholderScreenshot.visible, true);
54 }
64 }
65+
66+ function test_slideShowOpenClose() {
67+ var image0 = findChild(imageGallery, "previewImage0");
68+ mouseClick(image0, image0.width / 2, image0.height / 2);
69+ tryCompare(slideShow, "visible", true);
70+ tryCompare(slideShow, "scale", 1.0);
71+ tryCompare(slideShowCloseButton, "visible", true);
72+ mouseClick(slideShowCloseButton, slideShowCloseButton.width / 2, slideShowCloseButton.height / 2);
73+ tryCompare(slideShow, "visible", false);
74+ }
75+
76+ function test_slideShowShowHideHeader() {
77+ var image0 = findChild(imageGallery, "previewImage0");
78+ mouseClick(image0, image0.width / 2, image0.height / 2);
79+ tryCompare(slideShow, "visible", true);
80+ tryCompare(slideShow, "scale", 1.0);
81+ tryCompare(slideShowCloseButton, "visible", true);
82+ mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
83+ tryCompare(slideShowCloseButton, "visible", false);
84+ mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
85+ tryCompare(slideShowCloseButton, "visible", true);
86+ }
87+
88+ function test_slideShowOpenCorrectImage_data() {
89+ return [
90+ { tag: "Image 0", index: 0 },
91+ { tag: "Image 1", index: 1 },
92+ { tag: "Image 2", index: 2 },
93+ ];
94+ }
95+
96+ function test_slideShowOpenCorrectImage(data) {
97+ var image = findChild(imageGallery, "previewImage" + data.index);
98+ mouseClick(image, image.width / 2, image.height / 2);
99+ tryCompare(slideShow, "visible", true);
100+ tryCompare(slideShow, "scale", 1.0);
101+ tryCompare(slideShowListView, "currentIndex", data.index);
102+ verify(image.source === slideShowListView.currentItem.source);
103+ }
55 }
104 }
56}
105}