on xenial help sign in
Test for FilterOptionSelector
commitbceccaa3ce4562028e9ebcbe40966f97df115ef1 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 13 Oct 2015, 11:50 (11 years ago) parent1f2536c
3 files changed+104
qml/Dash/Filters/FilterOptionSelector.qml+3 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Filters/tst_FilterOptionSelector.qml+100
qml/Dash/Filters/FilterOptionSelector.qml+3
@@ -21,6 +21,8 @@ import Ubuntu.Components.ListItems 1.2 as ListItems
2121/*! Option Selector Filter Widget. */
2222
2323FilterWidget {
24+ id: root
25+
2426 implicitHeight: expandingItem.height
2527
2628 ListItems.Expandable {
@@ -65,6 +67,7 @@ FilterWidget {
6567
6668 ListItems.Standard {
6769 text: label
70+ objectName: root.objectName + "label" + index;
6871
6972 Image {
7073 id: dropDown
tests/qmltests/CMakeLists.txt+1
@@ -45,6 +45,7 @@ add_unity8_qmltest(Dash/Previews PreviewTextSummary)
4545add_unity8_qmltest(Dash/Previews PreviewVideoPlayback)
4646add_unity8_qmltest(Dash/Previews PreviewWidgetFactory)
4747add_unity8_qmltest(Dash/Previews PreviewZoomableImage)
48+add_unity8_qmltest(Dash/Filters FilterOptionSelector)
4849add_unity8_qmltest(Dash/Filters FilterWidgetFactory)
4950add_unity8_qmltest(Dash/ScopeSettings ScopeSettingBoolean)
5051add_unity8_qmltest(Dash/ScopeSettings ScopeSettingList)
tests/qmltests/Dash/Filters/tst_FilterOptionSelector.qmlnew file+100
@@ -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+}