on xenial help sign in
Add tests
commit3bac84c0ad2abbff9b9317a5e0a5d18133f7b866 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateMon 29 Sep 2014, 16:35 (12 years ago) parente2e94dd
2 files changed+57−5
qml/Dash/Previews/PreviewImageGallery.qml+7−4 tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+50−1
qml/Dash/Previews/PreviewImageGallery.qml+7−4
@@ -30,6 +30,7 @@ PreviewWidget {
3030
3131 ListView {
3232 id: previewImageListView
33+ objectName: "previewImageListView"
3334 spacing: units.gu(1)
3435 anchors.fill: parent
3536 orientation: ListView.Horizontal
@@ -50,6 +51,7 @@ PreviewWidget {
5051 }
5152
5253 delegate: LazyImage {
54+ objectName: "previewImage" + index
5355 anchors {
5456 top: parent.top
5557 bottom: parent.bottom
@@ -99,6 +101,7 @@ PreviewWidget {
99101
100102 ListView {
101103 id: slideShowListView
104+ objectName: "slideShowListView"
102105 anchors.fill: parent
103106 orientation: ListView.Horizontal
104107 highlightRangeMode: ListView.StrictlyEnforceRange
@@ -144,8 +147,8 @@ PreviewWidget {
144147 }
145148
146149 AbstractButton {
147− id: slideShowBackButton
148− objectName: "slideShowBackButton"
150+ id: slideShowCloseButton
151+ objectName: "slideShowCloseButton"
149152 anchors {
150153 top: parent.top
151154 bottom: parent.bottom
@@ -158,7 +161,7 @@ PreviewWidget {
158161 Rectangle {
159162 anchors.fill: parent
160163 color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
161− visible: slideShowBackButton.pressed
164+ visible: slideShowCloseButton.pressed
162165 }
163166
164167 Icon {
@@ -167,7 +170,7 @@ PreviewWidget {
167170 width: units.gu(2.5)
168171 height: width
169172 color: Theme.palette.normal.foregroundText
170− name: "back"
173+ name: "close"
171174 }
172175 }
173176 }
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+50−1
@@ -21,7 +21,7 @@ import Unity.Test 0.1 as UT
2121
2222Rectangle {
2323 id: root
24− width: units.gu(60)
24+ width: units.gu(80)
2525 height: units.gu(80)
2626 color: "lightgrey"
2727
@@ -44,13 +44,62 @@ Rectangle {
4444 }
4545
4646 UT.UnityTestCase {
47+ id: testCase
4748 name: "PreviewImageGalleryTest"
4849 when: windowShown
4950
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+
5060 function test_changeEmptyModel() {
5161 imageGallery.widgetData = sourcesModel0;
5262 var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
5363 compare(placeholderScreenshot.visible, true);
5464 }
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+ }
55104 }
56105}