@@ -0,0 +1,95 @@
1+/*
2+ * Copyright 2014,2015 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.4
18+import QtTest 1.0
19+import Ubuntu.Components 1.3
20+import "../../../../qml/Dash/Previews"
21+import Unity.Test 0.1 as UT
22+
23+Flickable {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+ contentHeight: factory.implicitHeight
28+
29+ property var reviewsEmpty: {
30+ "reviews": [ ]
31+ }
32+
33+ Item {
34+ id: widgetData500
35+ property var reviews: []
36+ }
37+
38+ PreviewWidgetFactory {
39+ id: factory
40+ anchors.fill: parent
41+ widgetType: "reviews"
42+ parentFlickable: root
43+ }
44+
45+ Component.onCompleted: {
46+ for (var i = 0; i < 500; ++i) {
47+ widgetData500.reviews.push({ author: "Some dude", review: "Very cool app" + i });
48+ }
49+ factory.widgetData = widgetData500;
50+ }
51+
52+ UT.UnityTestCase {
53+ name: "PreviewRatingDisplayTest"
54+ when: windowShown
55+
56+ function test_creation_speed() {
57+ factory.parentFlickable = null;
58+ factory.widgetData = reviewsEmpty;
59+ waitForRendering(root);
60+
61+ var start = new Date().getTime();
62+ factory.widgetData = widgetData500;
63+ waitForRendering(root);
64+ var end = new Date().getTime();
65+ var time500 = end - start;
66+
67+ factory.widgetData = reviewsEmpty;
68+ waitForRendering(root);
69+
70+ factory.parentFlickable = root;
71+ start = new Date().getTime();
72+ factory.widgetData = widgetData500;
73+ waitForRendering(root);
74+ end = new Date().getTime();
75+ var timeRanges500 = end - start;
76+
77+ // Measurements show it's usually like 20 times faster
78+ // but we set the range at 8 times fast to make sure it's not an unstable test
79+ verify(timeRanges500 * 8 < time500);
80+ }
81+
82+ function test_check_indexes() {
83+ // Check that item 499 isn't there on startup but if we scroll down
84+ // it will be there
85+ var reviewItem499 = findChild(factory, "reviewItem499");
86+ verify(reviewItem499 === null);
87+
88+ flickToYEnd(root);
89+
90+ var reviewItem499 = findChild(factory, "reviewItem499");
91+ verify(reviewItem499 !== null);
92+ }
93+ }
94+}
95+