on xenial help sign in
Adding tests
commit91530f05cb7565718c6b11d5c7b4359e802a0b08 authorDiego Sarmentero <diego.sarmentero@gmail.com> dateSat 20 Jul 2013, 10:56 (13 years ago) parent6423926
8 files changed+306−37
Dash/Apps/AppInfo.qml+2 Dash/Apps/AppPreview.qml+12−10 Dash/Apps/AppReviews.qml+7−4 tests/qmltests/CMakeLists.txt+3 tests/qmltests/Dash/Apps/tst_AppInfo.qml+51 tests/qmltests/Dash/Apps/tst_AppPreview.qml+124 tests/qmltests/Dash/Apps/tst_AppReviews.qml+105 tests/qmltests/Dash/tst_DashPreview.qml+2−23
Dash/Apps/AppInfo.qml+2
@@ -62,6 +62,7 @@ Row {
6262
6363 Label {
6464 id: ratedLabel
65+ objectName: "ratedLabel"
6566 fontSize: "medium"
6667 color: "white"
6768 style: Text.Raised
@@ -73,6 +74,7 @@ Row {
7374
7475 Label {
7576 id: reviewsLabel
77+ objectName: "reviewsLabel"
7678 fontSize: "medium"
7779 color: "white"
7880 style: Text.Raised
Dash/Apps/AppPreview.qml+12−10
@@ -23,20 +23,19 @@ import "../../Components"
2323DashPreview {
2424 id: root
2525
26− signal download
27− signal open
2826 signal sendUserReview(string review)
2927
30− title: "" // FROM PREVIEW DATA (FIXME: need scope format data)
28+ title: root.previewData.title
3129
3230 header: AppScreenshotsList {
3331 height: units.gu(20)
3432
35− model: 0 // FROM PREVIEW DATA (FIXME: need scope format data)
33+ model: previewData.infoHints[0]
3634 }
3735
3836 buttons: GridView {
3937 id: buttons
38+ objectName: "gridButtons"
4039 model: root.previewData.actions
4140
4241 property int numOfRows: (count + 1) / 2
@@ -67,17 +66,17 @@ DashPreview {
6766 spacing: units.gu(1)
6867
6968 AppInfo {
70− appName: "" // FROM PREVIEW DATA (FIXME: need scope format data)
71− icon: "" // FROM PREVIEW DATA (FIXME: need scope format data)
72− rating: 0 // FROM PREVIEW DATA (FIXME: need scope format data)
73− rated: 0 // FROM PREVIEW DATA (FIXME: need scope format data)
74− reviews: 0 // FROM PREVIEW DATA (FIXME: need scope format data)
69+ appName: root.previewData.title
70+ icon: root.previewData.image
71+ rating: root.previewData.infoHints[1]
72+ rated: root.previewData.infoHints[2]
73+ reviews: root.previewData.infoHints[3]
7574
7675 width: root.width
7776 }
7877
7978 Label {
80− text: "" // FROM PREVIEW DATA (FIXME: need scope format data)
79+ text: root.previewData.description
8180 fontSize: "medium"
8281 color: Theme.palette.selected.backgroundText
8382 opacity: .6
@@ -118,11 +117,14 @@ DashPreview {
118117 ListItem.ThinDivider {}
119118
120119 AppReviews {
120+ objectName: "appReviews"
121121 anchors {
122122 left: parent.left
123123 right: parent.right
124124 }
125125
126+ model: root.previewData.infoHints[4]
127+
126128 onSendReview: root.sendUserReview(review);
127129 }
128130
Dash/Apps/AppReviews.qml+7−4
@@ -77,6 +77,7 @@ Column {
7777
7878 TextArea {
7979 id: reviewField
80+ objectName: "reviewField"
8081 placeholderText: i18n.tr("Review")
8182 width: parent.width
8283 height: units.gu(5)
@@ -94,6 +95,7 @@ Column {
9495
9596 Button {
9697 id: sendButton
98+ objectName: "sendButton"
9799 width: units.gu(10)
98100 color: Theme.palette.selected.foreground
99101 text: i18n.tr("Send")
@@ -119,6 +121,7 @@ Column {
119121 }
120122
121123 Repeater {
124+ objectName: "commentsArea"
122125 model: root.model
123126
124127 Column {
@@ -127,7 +130,7 @@ Column {
127130 Column {
128131
129132 Label {
130− text: "" // FROM PREVIEW DATA (FIXME: need scope format data)
133+ text: modelData.username
131134 fontSize: "medium"
132135 color: "white"
133136 opacity: .8
@@ -145,11 +148,11 @@ Column {
145148
146149 RatingStars {
147150 maximumRating: 10
148− rating: 0 // FROM PREVIEW DATA (FIXME: need scope format data)
151+ rating: modelData.rate
149152 }
150153
151154 Label {
152− text: "" // FROM PREVIEW DATA (FIXME: need scope format data)
155+ text: modelData.date
153156 fontSize: "medium"
154157 color: Theme.palette.selected.backgroundText
155158 opacity: .6
@@ -160,7 +163,7 @@ Column {
160163 }
161164
162165 Label {
163− text: "" // FROM PREVIEW DATA (FIXME: need scope format data)
166+ text: modelData.comment
164167 fontSize: "medium"
165168 color: Theme.palette.selected.backgroundText
166169 opacity: .6
tests/qmltests/CMakeLists.txt+3
@@ -46,6 +46,9 @@ add_qml_test(Dash ScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_D
4646add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins
4747 ${CMAKE_BINARY_DIR}/tests/mocks)
4848add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
49+add_qml_test(Dash/Apps AppInfo IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
50+add_qml_test(Dash/Apps AppReviews IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
51+add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
4952add_qml_test(Greeter Lockscreen IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
5053 PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5154add_qml_test(Greeter Tablet IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS}
tests/qmltests/Dash/Apps/tst_AppInfo.qmlnew file+51
@@ -0,0 +1,51 @@
1+/*
2+ * Copyright 2013 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 "../../../../Dash/Apps"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ width: units.gu(50)
24+ height: units.gu(40)
25+
26+ // The component under test
27+ AppInfo {
28+ id: appInfo
29+ anchors.fill: parent
30+ icon: ""
31+ appName: "App Info"
32+ rating: 6
33+ rated: 120
34+ reviews: 8
35+ }
36+
37+ UT.UnityTestCase {
38+ name: "RunningApplicationsGrid"
39+ when: windowShown
40+
41+ function test_rated() {
42+ var rated = findChild(appInfo, "ratedLabel");
43+ compare(rated.text, "(120)");
44+ }
45+
46+ function test_reviews() {
47+ var rated = findChild(appInfo, "reviewsLabel");
48+ compare(rated.text, "8 reviews");
49+ }
50+ }
51+}
tests/qmltests/Dash/Apps/tst_AppPreview.qmlnew file+124
@@ -0,0 +1,124 @@
1+/*
2+ * Copyright 2013 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 "../../../../Dash/Apps"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ id: root
24+ width: units.gu(60)
25+ height: units.gu(80)
26+
27+ property var calls
28+
29+ SignalSpy {
30+ id: sendPreviewSpy
31+ target: appPreview
32+ signalName: "sendUserReview"
33+ }
34+
35+ function get_actions() {
36+ var a1 = new Object();
37+ a1.id = 123;
38+ a1.displayName = "action1";
39+ var a2 = new Object();
40+ a2.id = 456;
41+ a2.displayName = "action2";
42+ var a3 = new Object();
43+ a3.id = 789;
44+ a3.displayName = "action3";
45+
46+ return [a1, a2, a3];
47+ }
48+
49+ function get_comments() {
50+ var commentary = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus a mi vitae augue rhoncus lobortis ut rutrum metus. Curabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.";
51+ var c1 = new Object();
52+ c1.username = "Unity User";
53+ c1.rate = 4;
54+ c1.date = "08/20/2013";
55+ c1.comment = commentary;
56+ var c2 = new Object();
57+ c2.username = "Unity User";
58+ c2.rate = 8;
59+ c2.date = "01/15/2013";
60+ c2.comment = commentary;
61+ var c3 = new Object();
62+ c3.username = "Unity User";
63+ c3.rate = 10;
64+ c3.date = "10/02/2013";
65+ c3.comment = commentary;
66+
67+ return [c1, c2, c3];
68+ }
69+
70+ function get_infohints() {
71+ var i1 = ["fake_image1.png", "fake_image2.png", "fake_image3.png"];
72+ var i2 = 8;
73+ var i3 = 120;
74+ var i4 = 8;
75+ var i5 = get_comments();
76+
77+ return [i1, i2, i3, i4, i5];
78+ }
79+
80+ function get_data() {
81+ var objData = new Object();
82+ objData.title = "Unity App";
83+ objData.image = "fake_image.png";
84+ objData.infoHints = get_infohints();
85+ objData.description = "This is an Application description";
86+ objData.actions = get_actions();
87+ objData.execute = prueba;
88+
89+ return objData;
90+ }
91+
92+ function prueba(id, data){
93+ root.calls[root.calls.length] = id;
94+ }
95+
96+ // The component under test
97+ AppPreview {
98+ id: appPreview
99+ anchors.fill: parent
100+
101+ previewData: get_data()
102+ }
103+
104+ UT.UnityTestCase {
105+ name: "AppReviews"
106+ when: windowShown
107+
108+ function test_actions() {
109+ root.calls = new Array();
110+ var buttons = findChild(appPreview, "gridButtons");
111+ compare(buttons.count, 3);
112+
113+ for(var i = 0; i < buttons.count; i++) {
114+ buttons.currentIndex = i;
115+ buttons.currentItem.clicked();
116+ }
117+
118+ var actions = get_actions();
119+ for(var i = 0; i < actions.length; i++) {
120+ compare(root.calls[i], actions[i].id);
121+ }
122+ }
123+ }
124+}
tests/qmltests/Dash/Apps/tst_AppReviews.qmlnew file+105
@@ -0,0 +1,105 @@
1+/*
2+ * Copyright 2013 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 "../../../../Dash/Apps"
20+import Unity.Test 0.1 as UT
21+
22+Item {
23+ id: root
24+ width: units.gu(50)
25+ height: units.gu(40)
26+
27+ property string _username: "Unity User"
28+ property int _rating: 8
29+ property string _date: "04/20/2013"
30+ property string _comment: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus a mi vitae augue rhoncus lobortis ut rutrum metus. Curabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh."
31+
32+ SignalSpy {
33+ id: sendReviewSpy
34+ target: appReviews
35+ signalName: "sendReview"
36+ }
37+
38+ function get_comments() {
39+ var c1 = new Object();
40+ c1.username = root._username;
41+ c1.rate = root._rating;
42+ c1.date = root._date;
43+ c1.comment = root._comment;
44+ var c2 = new Object();
45+ c2.username = root._username;
46+ c2.rate = root._rating;
47+ c2.date = root._date;
48+ c2.comment = root._comment;
49+ var c3 = new Object();
50+ c3.username = root._username;
51+ c3.rate = root._rating;
52+ c3.date = root._date;
53+ c3.comment = root._comment;
54+ var c4 = new Object();
55+ c4.username = root._username;
56+ c4.rate = root._rating;
57+ c4.date = root._date;
58+ c4.comment = root._comment;
59+
60+ return [c1, c2, c3, c4];
61+ }
62+
63+ // The component under test
64+ AppReviews {
65+ id: appReviews
66+ anchors.fill: parent
67+
68+ model: get_comments()
69+ }
70+
71+ UT.UnityTestCase {
72+ name: "AppReviews"
73+ when: windowShown
74+
75+ function test_state_nothing() {
76+ appReviews.state = "";
77+ var reviewField = findChild(appReviews, "reviewField");
78+ var sendButton = findChild(appReviews, "sendButton");
79+ compare(reviewField.width, appReviews.width);
80+ compare(sendButton.opacity, 0);
81+ }
82+
83+ function test_send_review() {
84+ var sendButton = findChild(appReviews, "sendButton");
85+ mouseClick(sendButton, 1, 1)
86+ compare(sendReviewSpy.count, 1, "SendReview signal not emitted");
87+ }
88+
89+ function test_comments() {
90+ var commentsArea = findChild(appReviews, "commentsArea");
91+ compare(commentsArea.count, 4);
92+ for(var i = 0; i < 4; i++) {
93+ var username = commentsArea.itemAt(i).children[0].children[0].text
94+ var rate = commentsArea.itemAt(i).children[0].children[1].children[0].rating
95+ var date = commentsArea.itemAt(i).children[0].children[1].children[1].text
96+ var comment = commentsArea.itemAt(i).children[1].text
97+ compare(username, root._username);
98+ compare(rate, root._rating);
99+ compare(date, root._date);
100+ compare(comment, root._comment);
101+ }
102+ }
103+
104+ }
105+}
tests/qmltests/Dash/tst_DashPreview.qml+2−23
@@ -32,7 +32,6 @@ Item {
3232 id: preview
3333 anchors.fill: parent
3434 title: "Testing rocks, debugging sucks!"
35− forceSquare: true
3635
3736 buttons: Row {
3837 width: parent.width
@@ -55,9 +54,9 @@ Item {
5554 }
5655 }
5756
58− caption: Label { text: "Caption label" }
57+ header: Label { text: "Caption label" }
5958
60− description: Column {
59+ body: Column {
6160 id: testContent
6261 objectName: "testContent"
6362 width: parent.width
@@ -102,26 +101,6 @@ Item {
102101 compare(closeSpy.count, 1, "Close signal not emitted")
103102 }
104103
105− function test_play_button_data() {
106− return [
107− {tag: "playable", playable: true},
108− {tag: "not playable", playable: false}
109− ]
110− }
111−
112− function test_play_button(data) {
113− var playButton = findChild(preview, "playButton")
114− preview.playable = data.playable
115− compare(playButton.visible, data.playable)
116− }
117−
118− function test_play_button_click() {
119− preview.playable = true
120− var playButton = findChild(preview, "playButton")
121− mouseClick(playButton, 1, 1)
122− tryCompare(previewClickedSpy, "count", 1)
123− }
124−
125104 function test_columns_data() {
126105 return [
127106 {tag: "1 columns", width: units.gu(5), height: units.gu(10), columns: 1},