@@ -0,0 +1,232 @@
1+/*
2+ * Copyright 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/Filters"
21+import Unity.Test 0.1 as UT
22+import Unity 0.2
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(80)
28+ color: theme.palette.selected.background
29+
30+ QtObject {
31+ id: widgetData1
32+
33+ property real startValue
34+ property real endValue
35+ property bool hasStartValue
36+ property bool hasEndValue
37+ property string startPrefixLabel
38+ property string startPostfixLabel
39+ property string centralLabel
40+ property string endPrefixLabel
41+ property string endPostfixLabel
42+
43+ onStartValueChanged: {
44+ hasStartValue = true;
45+ }
46+
47+ onEndValueChanged: {
48+ hasEndValue = true;
49+ }
50+
51+ function eraseStartValue() {
52+ hasStartValue = false;
53+ }
54+
55+ function eraseEndValue() {
56+ hasEndValue = false;
57+ }
58+ }
59+
60+ Component.onCompleted: {
61+ generateData();
62+ }
63+
64+ function generateData() {
65+ widgetData1.startValue = startValue.text;
66+ widgetData1.endValue = endValue.text;
67+ widgetData1.hasStartValue = startValueHasValue.checked;
68+ widgetData1.hasEndValue = endValueHasValue.checked;
69+ widgetData1.startPrefixLabel = startValuePrefixLabel.text;
70+ widgetData1.startPostfixLabel = startValuePostfixLabel.text;
71+ widgetData1.centralLabel = centralLabel.text;
72+ widgetData1.endPrefixLabel = endValuePrefixLabel.text;
73+ widgetData1.endPostfixLabel = endValuePostfixLabel.text;
74+
75+ factory.widgetData = widgetData1;
76+ }
77+
78+ FilterWidgetFactory {
79+ id: factory
80+ widgetId: "testRangeInputFilter"
81+ widgetType: Filters.RangeInputFilter
82+ anchors {
83+ left: parent.left
84+ right: parent.right
85+ }
86+ clip: true
87+ }
88+
89+ Column {
90+ anchors.top: factory.bottom
91+ width: parent.width
92+ spacing: units.gu(1)
93+
94+ Text {
95+ text: "Values"
96+ }
97+
98+ Row {
99+ spacing: units.gu(1)
100+ Text {
101+ text: "Start Value Prefix Label"
102+ verticalAlignment: Text.AlignVCenter
103+ height: parent.height
104+ }
105+ TextField {
106+ id: startValuePrefixLabel
107+ text: "Pre1"
108+ }
109+ }
110+
111+ Row {
112+ spacing: units.gu(1)
113+ Text {
114+ text: "Start Value Postfix Label"
115+ verticalAlignment: Text.AlignVCenter
116+ height: parent.height
117+ }
118+ TextField {
119+ id: startValuePostfixLabel
120+ text: "Post1"
121+ }
122+ }
123+
124+ Row {
125+ spacing: units.gu(1)
126+ Text {
127+ text: "Central Label"
128+ verticalAlignment: Text.AlignVCenter
129+ height: parent.height
130+ }
131+ TextField {
132+ id: centralLabel
133+ text: "to"
134+ }
135+ }
136+
137+ Row {
138+ spacing: units.gu(1)
139+ Text {
140+ text: "End Value Prefix Label"
141+ verticalAlignment: Text.AlignVCenter
142+ height: parent.height
143+ }
144+ TextField {
145+ id: endValuePrefixLabel
146+ text: "Pre2"
147+ }
148+ }
149+
150+ Row {
151+ spacing: units.gu(1)
152+ Text {
153+ text: "End Value Postfix Label"
154+ verticalAlignment: Text.AlignVCenter
155+ height: parent.height
156+ }
157+ TextField {
158+ id: endValuePostfixLabel
159+ text: "Post2"
160+ }
161+ }
162+
163+ Row {
164+ spacing: units.gu(1)
165+ Text {
166+ text: "Start Value"
167+ verticalAlignment: Text.AlignVCenter
168+ height: parent.height
169+ }
170+ TextField {
171+ id: startValue
172+ text: "-1"
173+ }
174+ CheckBox {
175+ id: startValueHasValue
176+ }
177+ }
178+
179+
180+ Row {
181+ spacing: units.gu(1)
182+ Text {
183+ text: "End Value"
184+ verticalAlignment: Text.AlignVCenter
185+ height: parent.height
186+ }
187+ TextField {
188+ id: endValue
189+ text: "5"
190+ }
191+ CheckBox {
192+ id: endValueHasValue
193+ checked: true
194+ }
195+ }
196+
197+ Button {
198+ text: "Set Values"
199+ onClicked: root.generateData();
200+ }
201+ }
202+
203+ UT.UnityTestCase {
204+ name: "FilterRangeInput"
205+ when: windowShown
206+
207+ function init() {
208+ root.generateData();
209+ }
210+
211+ function test_initialStatus() {
212+ var startValueField = findChild(factory, "startValueField");
213+ compare(startValueField.text, "");
214+
215+ var endValueField = findChild(factory, "endValueField");
216+ compare(endValueField.text, "5");
217+ }
218+
219+ function test_dotStays() {
220+ var startValueField = findChild(factory, "startValueField");
221+ compare(startValueField.text, "");
222+
223+ startValueField.text = "4.5";
224+ compare(startValueField.text, "4.5");
225+ compare(widgetData1.startValue, 4.5);
226+
227+ startValueField.text = "4.";
228+ compare(startValueField.text, "4.");
229+ compare(widgetData1.startValue, 4);
230+ }
231+ }
232+}