Merge lp:~mzanetti/unity/phablet-test-dashpreview into lp:unity/phablet

Proposed by Michael Zanetti
Status: Merged
Approved by: Albert Astals Cid
Approved revision: no longer in the source branch.
Merged at revision: 506
Proposed branch: lp:~mzanetti/unity/phablet-test-dashpreview
Merge into: lp:unity/phablet
Diff against target: 222 lines (+178/-0)
3 files modified
Dash/DashPreview.qml (+4/-0)
tests/qmluitests/CMakeLists.txt (+1/-0)
tests/qmluitests/tst_DashPreview.qml (+173/-0)
To merge this branch: bzr merge lp:~mzanetti/unity/phablet-test-dashpreview
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+154741@code.launchpad.net

Commit message

added tests for DashPreview.qml

Description of the change

added tests for DashPreview.qml

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Dash/DashPreview.qml'
2--- Dash/DashPreview.qml 2013-03-20 11:12:44 +0000
3+++ Dash/DashPreview.qml 2013-03-21 17:08:01 +0000
4@@ -83,6 +83,7 @@
5
6 Label {
7 id: title
8+ objectName: "titleLabel"
9 anchors {
10 left: parent.left
11 right: parent.right
12@@ -134,6 +135,7 @@
13
14 Column {
15 id: leftColumn
16+ objectName: "leftColumn"
17 anchors {
18 left: parent.left
19 right: parent.right
20@@ -157,6 +159,7 @@
21 }
22
23 Image {
24+ objectName: "playButton"
25 anchors.centerIn: parent
26 visible: root.playable
27 readonly property bool bigButton: parent.width > units.gu(40)
28@@ -196,6 +199,7 @@
29
30 Column {
31 id: rightColumn
32+ objectName: "rightColumn"
33 height: childrenRect.height
34 anchors {
35 left: parent.left
36
37=== modified file 'tests/qmluitests/CMakeLists.txt'
38--- tests/qmluitests/CMakeLists.txt 2013-03-20 09:39:25 +0000
39+++ tests/qmluitests/CMakeLists.txt 2013-03-21 17:08:01 +0000
40@@ -26,3 +26,4 @@
41 add_qml_test(Greeter)
42 add_qml_test(ResponsiveGridView)
43 add_qml_test(Revealer)
44+add_qml_test(DashPreview)
45
46=== added file 'tests/qmluitests/tst_DashPreview.qml'
47--- tests/qmluitests/tst_DashPreview.qml 1970-01-01 00:00:00 +0000
48+++ tests/qmluitests/tst_DashPreview.qml 2013-03-21 17:08:01 +0000
49@@ -0,0 +1,173 @@
50+/*
51+ * Copyright 2013 Canonical Ltd.
52+ *
53+ * This program is free software; you can redistribute it and/or modify
54+ * it under the terms of the GNU General Public License as published by
55+ * the Free Software Foundation; version 3.
56+ *
57+ * This program is distributed in the hope that it will be useful,
58+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
59+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60+ * GNU General Public License for more details.
61+ *
62+ * You should have received a copy of the GNU General Public License
63+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
64+ */
65+
66+import QtQuick 2.0
67+import QtTest 1.0
68+import "../../Dash"
69+import Ubuntu.Components 0.1
70+
71+Item {
72+ id: root
73+ width: units.gu(120)
74+ height: units.gu(80)
75+
76+ property bool helper: false
77+
78+ UnityTestCase {
79+ name: "PreviewTest"
80+ when: windowShown
81+
82+ function test_close() {
83+ var title = findChild(preview, "titleLabel")
84+ mouseClick(title, 1, 1)
85+ compare(closeSpy.count, 1, "Close signal not emitted")
86+ }
87+
88+ function test_play_button_data() {
89+ return [
90+ {tag: "playable", playable: true},
91+ {tag: "not playable", playable: false}
92+ ]
93+ }
94+
95+ function test_play_button(data) {
96+ var playButton = findChild(preview, "playButton")
97+ preview.playable = data.playable
98+ compare(playButton.visible, data.playable)
99+ }
100+
101+ function test_play_button_click() {
102+ preview.playable = true
103+ var playButton = findChild(preview, "playButton")
104+ mouseClick(playButton, 1, 1)
105+ tryCompare(previewClickedSpy, "count", 1)
106+ }
107+
108+ function test_columns_data() {
109+ return [
110+ {tag: "1 columns", width: units.gu(5), height: units.gu(10), columns: 1},
111+ {tag: "2 columns", width: units.gu(50), height: units.gu(10), columns: 2}
112+ ]
113+ }
114+
115+ function test_columns(data) {
116+ var leftCol = findChild(preview, "leftColumn")
117+ var rightCol = findChild(preview, "rightColumn")
118+
119+ root.width = data.width
120+ root.height = data.height
121+
122+ // there are 2 columns in DashPreview. On portrait form factors
123+ // only the left one is used and the right one should be empty.
124+ // to find out if the content is in the correct column, we get a
125+ // reference to the column objects and search only the subtree
126+ // to see if the content is in the correct column.
127+ // 1 colum -> content should be in leftColumn
128+ // 2 colums -> content should be in rightColumn
129+
130+ switch(data.columns) {
131+ case 1:
132+ var testContent = findChild(leftCol, "testContent")
133+ compare(testContent.objectName, "testContent")
134+ break
135+ case 2:
136+ var testContent = findChild(rightCol, "testContent")
137+ compare(testContent.objectName, "testContent")
138+ break
139+ }
140+
141+ // reset to initial values to not disturb other tests
142+ root.width = units.gu(120)
143+ root.height = units.gu(80)
144+ }
145+
146+ // This test just checks if Components assigned to the
147+ // "buttons" property are actually put somewhere on the
148+ // screen. the mouseClick would fail if they are not used/painted
149+ function test_ensure_buttons_visible() {
150+ var button = findChild(preview, "buttonMouseArea")
151+ mouseClick(button, 1, 1)
152+ tryCompare(root, "helper", true)
153+ // reset to false in case any other test wants to use it
154+ root.helper = false
155+ }
156+
157+ }
158+
159+ DashPreview {
160+ id: preview
161+ anchors.fill: parent
162+ title: "Testing rocks, debugging sucks!"
163+ forceSquare: true
164+
165+ buttons: Row {
166+ width: parent.width
167+ height: units.gu(5)
168+ Rectangle {
169+ width: parent.width / 3
170+ height: parent.height
171+ color: "blue"
172+ MouseArea {
173+ id: buttonMouseArea
174+ objectName: "buttonMouseArea"
175+ anchors.fill: parent
176+ onClicked: root.helper = true
177+ }
178+ }
179+ Rectangle {
180+ width: parent.width / 3
181+ height: parent.height
182+ color: "green"
183+ }
184+ }
185+
186+ caption: Label { text: "Caption label" }
187+
188+ description: Column {
189+ id: testContent
190+ objectName: "testContent"
191+ width: parent.width
192+ height: units.gu(50)
193+ Rectangle {
194+ width: parent.width
195+ height: parent.height / 3
196+ color: "green"
197+ }
198+ Rectangle {
199+ width: parent.width
200+ height: parent.height / 3
201+ color: "red"
202+ }
203+ Rectangle {
204+ width: parent.width
205+ height: parent.height / 3
206+ color: "blue"
207+ }
208+ }
209+ }
210+
211+ SignalSpy {
212+ id: closeSpy
213+ target: preview
214+ signalName: "close"
215+ }
216+
217+ SignalSpy {
218+ id: previewClickedSpy
219+ target: preview
220+ signalName: "previewImageClicked"
221+ }
222+}

Subscribers

People subscribed via source and target branches