@@ -0,0 +1,100 @@
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 "../../../../qml/Dash/Filters"
20+import Unity.Test 0.1 as UT
21+import Unity 0.2
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(60)
26+ height: units.gu(80)
27+ color: Theme.palette.selected.background
28+
29+ property var singleSelectionWidgetData
30+
31+ ListModel {
32+ id: optionsSingleSelect
33+ ListElement {
34+ label: "A"
35+ checked: false
36+ }
37+ ListElement {
38+ label: "B"
39+ checked: false
40+ }
41+ ListElement {
42+ label: "C"
43+ checked: false
44+ }
45+
46+ function setChecked(index, checked) {
47+ for (var i = 0; i < optionsSingleSelect.count; ++i)
48+ optionsSingleSelect.setProperty(i, "checked", false);
49+ optionsSingleSelect.setProperty(index, "checked", checked);
50+ }
51+ }
52+
53+ Component.onCompleted: {
54+ singleSelectionWidgetData = { label: "Hola", options: optionsSingleSelect }
55+ }
56+
57+ FilterWidgetFactory {
58+ id: factory
59+ widgetId: "testOptionSelectorFilter"
60+ widgetType: Filters.OptionSelectorFilter
61+ widgetData: singleSelectionWidgetData
62+ anchors {
63+ left: parent.left
64+ right: parent.right
65+ }
66+ }
67+
68+ UT.UnityTestCase {
69+ name: "FilterOptionSelector"
70+ when: windowShown
71+
72+ function test_optionSelector() {
73+ var initialHeight = factory.implicitHeight;
74+ var currentHeight = 0;
75+ // Open the selector
76+ mouseClick(factory);
77+ // wait for it to stop growing
78+ while (currentHeight != factory.implicitHeight) {
79+ currentHeight = factory.implicitHeight;
80+ wait(250);
81+ }
82+ verify(initialHeight < currentHeight);
83+
84+ // Check the first option
85+ var option0 = findChild(factory, "testOptionSelectorFilterlabel0");
86+ mouseClick(option0);
87+ verify(optionsSingleSelect.get(0).checked);
88+
89+ // Check the second option
90+ var option1 = findChild(factory, "testOptionSelectorFilterlabel1");
91+ mouseClick(option1);
92+ verify(!optionsSingleSelect.get(0).checked);
93+ verify(optionsSingleSelect.get(1).checked);
94+
95+ // Uncheck the second option
96+ mouseClick(option1);
97+ verify(!optionsSingleSelect.get(1).checked);
98+ }
99+ }
100+}