on xenial help sign in
Added more tests
commit8a7d160b25cc0a43b358344417c2f835969f3bb2 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateMon 11 Aug 2014, 17:59 (12 years ago) parente53328c
16 files changed+524−216
qml/Dash/ScopeSettings/ScopeSetting.qml+3−3 qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+55 qml/Dash/ScopeSettings/ScopeSettingLabel.qml−51 qml/Dash/ScopeSettings/ScopeSettingList.qml+5−6 qml/Dash/ScopeSettings/ScopeSettingNumber.qml+42−23 qml/Dash/ScopeSettings/ScopeSettingString.qml+68 qml/Dash/ScopeSettings/ScopeSettingSwitch.qml−49 qml/Dash/ScopeSettings/ScopeSettings.qml+1−1 qml/Dash/ScopeSettings/ScopeSettingWidgetFactory.qml → qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+6−5 tests/qmltests/CMakeLists.txt+5−2 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingSwitch.qml → tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingBoolean.qml+13−18 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingLabel.qml−58 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingList.qml+75 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingNumber.qml+98 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingString.qml+88 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingsWidgetFactory.qml+65
qml/Dash/ScopeSettings/ScopeSetting.qml+3−3
@@ -28,9 +28,9 @@ Item {
2828
2929 readonly property real __margins: units.gu(2)
3030
31− /*! \brief This signal should be emitted when a setting action was triggered.
31+ /*! \brief This signal should be emitted when a setting action was updated.
3232 *
33− * \param new value
33+ * \param value the new setting value.
3434 */
35− signal triggered(var value)
35+ signal updated(var value)
3636}
qml/Dash/ScopeSettings/ScopeSettingBoolean.qmlnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2014 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.2
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
20+
21+ScopeSetting {
22+ id: root
23+
24+ ListItem.Empty {
25+ onClicked: {
26+ control.checked = !control.checked
27+ updated(control.checked)
28+ }
29+
30+ Label {
31+ anchors {
32+ left: parent.left
33+ leftMargin: __margins
34+ right: control.left
35+ rightMargin: units.gu(1)
36+ verticalCenter: parent.verticalCenter
37+ }
38+ text: widgetData.displayName
39+ elide: Text.ElideMiddle
40+ color: scopeStyle ? scopeStyle.foreground : "grey"
41+ }
42+
43+ CheckBox {
44+ id: control
45+ anchors {
46+ right: parent.right
47+ rightMargin: __margins
48+ verticalCenter: parent.verticalCenter
49+ }
50+ checked: widgetData.value
51+
52+ onTriggered: root.updated(checked)
53+ }
54+ }
55+}
qml/Dash/ScopeSettings/ScopeSettingLabel.qmldeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2014 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.2
18−import Ubuntu.Components 1.1
19−
20−ScopeSetting {
21− id: root
22− implicitHeight: units.gu(6)
23−
24− Label {
25− anchors {
26− left: parent.left
27− leftMargin: __margins
28− right: control.left
29− rightMargin: units.gu(1)
30− verticalCenter: parent.verticalCenter
31− }
32− text: widgetData.displayName
33− elide: Text.ElideMiddle
34− color: scopeStyle ? scopeStyle.foreground : "grey"
35− }
36−
37− TextField {
38− id: control
39− anchors {
40− right: parent.right
41− rightMargin: __margins
42− verticalCenter: parent.verticalCenter
43− }
44− text: widgetData.value
45−
46− onTriggered: root.triggered(text)
47− onActiveFocusChanged: {
48− if (!activeFocus) root.triggered(text);
49− }
50− }
51−}
qml/Dash/ScopeSettings/ScopeSettingList.qml+5−6
@@ -16,22 +16,21 @@
1616
1717import QtQuick 2.2
1818import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
1920
2021ScopeSetting {
2122 id: root
22− implicitHeight: optionSelector.implicitHeight
2323
24− OptionSelector {
25− id: optionSelector
24+ ListItem.ItemSelector {
25+ id: control
26+ objectName: "control"
2627 anchors {
2728 left: parent.left
2829 right: parent.right
29− top: parent.top
30− margins: __margins
3130 }
3231 text: widgetData.displayName
3332 model: widgetData.properties["values"]
3433
35− onSelectedIndexChanged: root.triggered(selectedIndex)
34+ onSelectedIndexChanged: root.updated(selectedIndex)
3635 }
3736}
qml/Dash/ScopeSettings/ScopeSettingNumber.qml+42−23
@@ -16,37 +16,56 @@
1616
1717import QtQuick 2.2
1818import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
1920
2021ScopeSetting {
2122 id: root
22− implicitHeight: units.gu(6)
2323
24− Label {
25− anchors {
26− left: parent.left
27− leftMargin: __margins
28− right: control.left
29− rightMargin: units.gu(1)
30− verticalCenter: parent.verticalCenter
24+ ListItem.Empty {
25+ onClicked: {
26+ control.focus = true;
27+ control.selectAll();
3128 }
32− text: widgetData.displayName
33− elide: Text.ElideMiddle
34− color: scopeStyle ? scopeStyle.foreground : "grey"
35− }
3629
37− TextField {
38− id: control
39− anchors {
40− right: parent.right
41− rightMargin: __margins
42− verticalCenter: parent.verticalCenter
30+ Label {
31+ anchors {
32+ left: parent.left
33+ leftMargin: __margins
34+ right: control.left
35+ rightMargin: units.gu(1)
36+ verticalCenter: parent.verticalCenter
37+ }
38+ text: widgetData.displayName
39+ elide: Text.ElideMiddle
40+ color: scopeStyle ? scopeStyle.foreground : "grey"
4341 }
44− text: widgetData.value
45− validator: DoubleValidator {}
4642
47− onTriggered: root.triggered(text)
48− onActiveFocusChanged: {
49− if (!activeFocus) root.triggered(text);
43+ TextField {
44+ id: control
45+ objectName: "control"
46+ anchors {
47+ right: parent.right
48+ rightMargin: __margins
49+ verticalCenter: parent.verticalCenter
50+ }
51+ text: widgetData.value
52+ width: units.gu(8)
53+ validator: DoubleValidator {}
54+ hasClearButton: false
55+
56+ function updateText() {
57+ if (acceptableInput) {
58+ text = displayText;
59+ root.updated(text);
60+ }
61+ }
62+
63+ onAccepted: updateText()
64+ onActiveFocusChanged: {
65+ if (!activeFocus) {
66+ updateText();
67+ }
68+ }
5069 }
5170 }
5271}
qml/Dash/ScopeSettings/ScopeSettingString.qmlnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 2014 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.2
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
20+
21+ScopeSetting {
22+ id: root
23+
24+ ListItem.Empty {
25+ onClicked: {
26+ control.focus = true;
27+ control.selectAll();
28+ }
29+
30+ Label {
31+ id: label
32+ anchors {
33+ left: parent.left
34+ leftMargin: __margins
35+ right: control.left
36+ rightMargin: units.gu(1)
37+ verticalCenter: parent.verticalCenter
38+ }
39+ text: widgetData.displayName
40+ elide: Text.ElideMiddle
41+ color: scopeStyle ? scopeStyle.foreground : "grey"
42+ }
43+
44+ TextField {
45+ id: control
46+ objectName: "control"
47+ anchors {
48+ right: parent.right
49+ rightMargin: __margins
50+ verticalCenter: parent.verticalCenter
51+ }
52+ width: units.gu(12)
53+ text: widgetData.value
54+
55+ function updateText() {
56+ text = displayText;
57+ root.updated(text);
58+ }
59+
60+ onAccepted: updateText()
61+ onActiveFocusChanged: {
62+ if (!activeFocus) {
63+ updateText();
64+ }
65+ }
66+ }
67+ }
68+}
qml/Dash/ScopeSettings/ScopeSettingSwitch.qmldeleted−49
@@ -1,49 +0,0 @@
1−/*
2− * Copyright (C) 2014 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.2
18−import Ubuntu.Components 1.1
19−
20−ScopeSetting {
21− id: root
22− implicitHeight: units.gu(6)
23−
24− Label {
25− anchors {
26− left: parent.left
27− leftMargin: __margins
28− right: control.left
29− rightMargin: units.gu(1)
30− verticalCenter: parent.verticalCenter
31− }
32− text: widgetData.displayName
33− elide: Text.ElideMiddle
34− color: scopeStyle ? scopeStyle.foreground : "grey"
35− }
36−
37− Switch {
38− id: control
39− objectName: "control"
40− anchors {
41− right: parent.right
42− rightMargin: __margins
43− verticalCenter: parent.verticalCenter
44− }
45− checked: widgetData.value
46−
47− onTriggered: root.triggered(checked)
48− }
49−}
qml/Dash/ScopeSettings/ScopeSettings.qml+1−1
@@ -29,6 +29,6 @@ ListView {
2929 widgetData: model
3030 scopeStyle: root.scopeStyle
3131
32− onTriggered: model.value = value;
32+ onUpdated: model.value = value;
3333 }
3434}
qml/Dash/ScopeSettings/ScopeSettingWidgetFactory.qml → qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qmlrenamed+6−5
@@ -28,17 +28,17 @@ Loader {
2828 property var widgetData: null
2929
3030 //! Triggered signal forwarded from the widgets.
31− signal triggered(var value)
31+ signal updated(var value)
3232
3333 source: widgetSource
3434
3535 //! \cond private
3636 property url widgetSource: {
3737 switch (widgetData.type) {
38− case "boolean": return "ScopeSettingSwitch.qml";
39− case "list": return "ScopeSettingSwitch.qml";
38+ case "boolean": return "ScopeSettingBoolean.qml";
39+ case "list": return "ScopeSettingList.qml";
4040 case "number": return "ScopeSettingNumber.qml";
41− case "string": return "ScopeSettingLabel.qml";
41+ case "string": return "ScopeSettingString.qml";
4242 default: return "";
4343 }
4444 }
@@ -46,10 +46,11 @@ Loader {
4646
4747 onLoaded: {
4848 item.widgetData = Qt.binding(function() { return root.widgetData } )
49+ item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
4950 }
5051
5152 Connections {
5253 target: root.item
53− onTriggered: root.triggered(value)
54+ onUpdated: root.updated(value)
5455 }
5556}
tests/qmltests/CMakeLists.txt+5−2
@@ -53,8 +53,11 @@ add_qml_test(Dash/Previews PreviewTextSummary)
5353add_qml_test(Dash/Previews PreviewVideoPlayback)
5454add_qml_test(Dash/Previews PreviewWidgetFactory)
5555add_qml_test(Dash/Previews PreviewZoomableImage)
56−add_qml_test(Dash/ScopeSettings ScopeSettingLabel)
57−add_qml_test(Dash/ScopeSettings ScopeSettingSwitch)
56+add_qml_test(Dash/ScopeSettings ScopeSettingBoolean)
57+add_qml_test(Dash/ScopeSettings ScopeSettingList)
58+add_qml_test(Dash/ScopeSettings ScopeSettingNumber)
59+add_qml_test(Dash/ScopeSettings ScopeSettingString)
60+add_qml_test(Dash/ScopeSettings ScopeSettingsWidgetFactory)
5861add_qml_test(Greeter Lockscreen ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5962add_qml_test(Greeter MultiGreeter ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
6063add_qml_test(Greeter SingleGreeter ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingSwitch.qml → tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingBoolean.qmlrenamed+13−18
@@ -15,6 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18+import Ubuntu.Components 1.1
1819import QtTest 1.0
1920import "../../../../qml/Dash/ScopeSettings"
2021import Unity.Test 0.1 as UT
@@ -25,38 +26,32 @@ Rectangle {
2526 height: units.gu(80)
2627
2728 property var settingData: {
28− "displayName" : "Fake boolean setting",
29+ "displayName" : "Mock boolean setting",
2930 "value": true
3031 }
3132
32− ScopeSettingSwitch {
33− id: scopeSettingSwitch
33+ ScopeSettingBoolean {
34+ id: scopeSetting
3435 widgetData: settingData
35− width: units.gu(40)
36−
37− Rectangle {
38− anchors.fill: parent
39− color: "red"
40− opacity: 0.1
41− }
36+ width: parent.width
4237 }
4338
4439 SignalSpy {
45− id: triggeredSpy
46− target: scopeSettingSwitch
47− signalName: "triggered"
40+ id: spy
41+ target: scopeSetting
42+ signalName: "updated"
4843 }
4944
5045 UT.UnityTestCase {
5146 id: testCase
52− name: "ScopeSettingSwitchTest"
47+ name: "ScopeSettingBooleanTest"
5348 when: windowShown
5449
55− function test_triggered() {
56− var control = findChild(scopeSettingSwitch, "control");
50+ function test_updated() {
51+ var control = findChild(scopeSetting, "control");
5752 mouseClick(control, control.width / 2, control.height / 2);
58− triggeredSpy.wait();
59− compare(triggeredSpy.signalArguments[0][0], false);
53+ spy.wait();
54+ compare(spy.signalArguments[0][0], false);
6055 }
6156 }
6257}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingLabel.qmldeleted−58
@@ -1,58 +0,0 @@
1−/*
2− * Copyright 2014 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/Dash/ScopeSettings"
20−import Unity.Test 0.1 as UT
21−
22−Rectangle {
23− id: root
24− width: units.gu(40)
25− height: units.gu(80)
26−
27− property var settingData: {
28− "displayName" : "Fake label setting",
29− "value": "fake label"
30− }
31−
32− ScopeSettingLabel {
33− id: scopeSettingLabel
34− widgetData: settingData
35− width: units.gu(40)
36−
37− Rectangle {
38− anchors.fill: parent
39− color: "red"
40− opacity: 0.1
41− }
42− }
43−
44− SignalSpy {
45− id: triggeredSpy
46− target: scopeSettingSwitch
47− signalName: "triggered"
48− }
49−
50− UT.UnityTestCase {
51− id: testCase
52− name: "ScopeSettingLabelTest"
53− when: windowShown
54−
55− function test_triggered() {
56− }
57− }
58−}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingList.qmlnew file+75
@@ -0,0 +1,75 @@
1+/*
2+ * Copyright 2014 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 Ubuntu.Components 1.1
19+import QtTest 1.0
20+import "../../../../qml/Dash/ScopeSettings"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+
28+ property var settingData: {
29+ "displayName" : "Mock list setting",
30+ "properties": { "values" : [ "first", "second", "third" ] }
31+ }
32+
33+ ScopeSettingList {
34+ id: scopeSetting
35+ widgetData: settingData
36+ width: parent.width
37+ }
38+
39+ SignalSpy {
40+ id: spy
41+ target: scopeSetting
42+ signalName: "updated"
43+ }
44+
45+ UT.UnityTestCase {
46+ id: testCase
47+ name: "ScopeSettingListTest"
48+ when: windowShown
49+
50+ property var control: findChild(scopeSetting, "control")
51+
52+ function init() {
53+ control.selectedIndex = 0;
54+ spy.clear();
55+ }
56+
57+ function test_updated_data() {
58+ return [
59+ { tag: "current", index: 0, updated: false },
60+ { tag: "second", index: 1, updated: true },
61+ { tag: "third", index: 2, updated: true }
62+ ]
63+ }
64+
65+ function test_updated(data) {
66+ control.selectedIndex = data.index;
67+ if (data.updated) {
68+ spy.wait();
69+ compare(spy.signalArguments[0][0], data.index);
70+ } else {
71+ compare(spy.count, 0);
72+ }
73+ }
74+ }
75+}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingNumber.qmlnew file+98
@@ -0,0 +1,98 @@
1+/*
2+ * Copyright 2014 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 Ubuntu.Components 1.1
19+import QtTest 1.0
20+import "../../../../qml/Dash/ScopeSettings"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+
28+ property var settingData: {
29+ "displayName" : "Mock number setting",
30+ "value": 0.2
31+ }
32+
33+ ScopeSettingNumber {
34+ id: scopeSetting
35+ widgetData: settingData
36+ width: parent.width
37+ }
38+
39+ SignalSpy {
40+ id: spy
41+ target: scopeSetting
42+ signalName: "updated"
43+ }
44+
45+ UT.UnityTestCase {
46+ id: testCase
47+ name: "ScopeSettingNumberTest"
48+ when: windowShown
49+
50+ property var control: findChild(scopeSetting, "control")
51+ property real newNumber: 11.7
52+
53+ function init() {
54+ spy.clear();
55+ control.focus = false;
56+ control.text = settingData.value;
57+ }
58+
59+ function test_updated_on_unfocus() {
60+ mouseClick(control, control.width / 2, control.height / 2);
61+ control.selectAll();
62+ control.cut();
63+ control.insert(0, newNumber);
64+ control.focus = false;
65+ spy.wait();
66+ verify(spy.signalArguments[0][0] == newNumber);
67+ }
68+
69+ function test_updated_on_accepted() {
70+ mouseClick(control, control.width / 2, control.height / 2);
71+ control.selectAll();
72+ control.cut();
73+ control.insert(0, newNumber);
74+ control.accepted();
75+ spy.wait();
76+ verify(spy.signalArguments[0][0] == newNumber);
77+ }
78+
79+ function test_selection_on_listitem_click() {
80+ mouseClick(scopeSetting, 0, scopeSetting.height / 2);
81+ compare(control.focus, true);
82+ // we're checking that selectAll() is being called by omitting it here
83+ control.cut();
84+ control.insert(0, newNumber);
85+ verify(control.displayText == newNumber);
86+ }
87+
88+ function test_unacceptableInput() {
89+ mouseClick(control, control.width / 2, control.height / 2);
90+ control.selectAll();
91+ control.cut();
92+ control.insert(0, "not valid");
93+ control.accepted();
94+ compare(spy.count, 0);
95+ compare(control.displayText, "");
96+ }
97+ }
98+}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingString.qmlnew file+88
@@ -0,0 +1,88 @@
1+/*
2+ * Copyright 2014 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 Ubuntu.Components 1.1
19+import QtTest 1.0
20+import "../../../../qml/Dash/ScopeSettings"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+
28+ property var settingData: {
29+ "displayName" : "Mock string setting",
30+ "value": "mock string"
31+ }
32+
33+ ScopeSettingString {
34+ id: scopeSetting
35+ widgetData: settingData
36+ width: parent.width
37+ }
38+
39+ SignalSpy {
40+ id: spy
41+ target: scopeSetting
42+ signalName: "updated"
43+ }
44+
45+ UT.UnityTestCase {
46+ id: testCase
47+ name: "ScopeSettingStringTest"
48+ when: windowShown
49+
50+ property var control: findChild(scopeSetting, "control")
51+ property string newText: "new text to compare"
52+
53+ function init() {
54+ spy.clear();
55+ control.focus = false;
56+ control.text = settingData.value;
57+ }
58+
59+ function test_updated_on_unfocus() {
60+ mouseClick(control, control.width / 2, control.height / 2);
61+ control.selectAll();
62+ control.cut();
63+ control.insert(0, newText);
64+ control.focus = false;
65+ spy.wait();
66+ compare(spy.signalArguments[0][0], newText);
67+ }
68+
69+ function test_updated_on_accepted() {
70+ mouseClick(control, control.width / 2, control.height / 2);
71+ control.selectAll();
72+ control.cut();
73+ control.insert(0, newText);
74+ control.accepted();
75+ spy.wait();
76+ compare(spy.signalArguments[0][0], newText);
77+ }
78+
79+ function test_selection_on_listitem_click() {
80+ mouseClick(scopeSetting, 0, scopeSetting.height / 2);
81+ compare(control.focus, true);
82+ // we're checking that selectAll() is being called by omitting it here
83+ control.cut();
84+ control.insert(0, newText);
85+ compare(control.displayText, newText);
86+ }
87+ }
88+}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingsWidgetFactory.qmlnew file+65
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright 2014 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 Ubuntu.Components 1.1
19+import QtTest 1.0
20+import "../../../../qml/Dash/ScopeSettings"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+
28+ property var settingData: {
29+ "type": "",
30+ "displayName" : "Mock setting",
31+ "value": "1",
32+ "properties": { "values" : [ "first", "second", "third" ] }
33+ }
34+
35+ ScopeSettingsWidgetFactory {
36+ id: scopeSettingsWidgetFactory
37+ anchors {
38+ left: parent.left
39+ right: parent.right
40+ }
41+ }
42+
43+ UT.UnityTestCase {
44+ id: testCase
45+ name: "ScopeSettingWidgetFactoryTest"
46+ when: windowShown
47+
48+ function test_mapping_data() {
49+ return [
50+ { tag: "Boolean", type: "boolean", source: "ScopeSettingBoolean.qml" },
51+ { tag: "List", type: "list", source: "ScopeSettingList.qml" },
52+ { tag: "Number", type: "number", source: "ScopeSettingNumber.qml" },
53+ { tag: "String", type: "string", source: "ScopeSettingString.qml" }
54+ ];
55+ }
56+
57+ function test_mapping(data) {
58+ var newSettingData = settingData;
59+ newSettingData.type = data.type;
60+ scopeSettingsWidgetFactory.widgetData = newSettingData;
61+
62+ verify(("" + scopeSettingsWidgetFactory.source).indexOf(data.source) != -1);
63+ }
64+ }
65+}