@@ -0,0 +1,86 @@
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 "../../../qml/Components"
20+import Ubuntu.Components 0.1
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(10)
27+ color: "black"
28+
29+ Rating {
30+ id: rating
31+ anchors.centerIn: parent
32+ maximumValue: 5
33+ size: 5
34+ value: 3
35+ }
36+
37+ UT.UnityTestCase {
38+ name: "RatingTest"
39+ when: windowShown
40+
41+ function init() {
42+ rating.maximumValue = 5;
43+ rating.size = 5
44+ rating.value = 3;
45+ }
46+
47+ function test_interactive_rating_data() {
48+ return [
49+ {tag: "1st icon without interactive", interactive: false, size: 5, maximumValue: 5, index: 0, value: 3},
50+ {tag: "1st icon", interactive: true, size: 5, maximumValue: 5, index: 0, value: 1},
51+ {tag: "1st icon size 10", interactive: true, size: 10, maximumValue: 10, index: 0, value: 1},
52+ {tag: "3rd icon size 10 small maximumValue", interactive: true, size: 10, maximumValue: 5, index: 2, value: 1.5},
53+ {tag: "2nd icon with big maximumValue", interactive: true, size: 5, maximumValue: 100, index: 1, value: 40},
54+ {tag: "last icon", interactive: true, size: 5, maximumValue: 5, index: 4, value: 5},
55+ ];
56+ }
57+
58+ function test_interactive_rating(data) {
59+ rating.interactive = data.interactive;
60+ rating.maximumValue = data.maximumValue;
61+ rating.size = data.size;
62+
63+ var averageIconWidth = rating.width / rating.size;
64+ mouseClick(rating, averageIconWidth * data.index + averageIconWidth / 2, rating.height / 2);
65+ compare(rating.value, data.value);
66+
67+ rating.interactive = false;
68+ }
69+
70+ function test_effectiveValue_data() {
71+ return [
72+ {tag: "negative", value: -3, expectedValue: 0},
73+ {tag: "ranged value", value: 2, expectedValue: 2},
74+ {tag: "big", value: 200, expectedValue: rating.maximumValue},
75+ {tag: "min", value: 0, expectedValue: 0},
76+ {tag: "max", value: rating.maximumValue, expectedValue: rating.maximumValue}
77+ ];
78+ }
79+
80+ function test_effectiveValue(data) {
81+ rating.value = data.value;
82+ wait(1000)
83+ compare(rating.effectiveValue, data.expectedValue, "effectiveValue not calculated correctly")
84+ }
85+ }
86+}