on xenial help sign in
Added more tests
8a7d160Andrea Cimitan
qml/Dash/ScopeSettings/ScopeSetting.qml+3−3
@@ -28,9 +28,9 @@ Item {
28
28
29 readonly property real __margins: units.gu(2)
29 readonly property real __margins: units.gu(2)
30
30
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.
32 *
32 *
33− * \param new value
33+ * \param value the new setting value.
34 */
34 */
35− signal triggered(var value)
35+ signal updated(var value)
36}
36}
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 @@
16
16
17import QtQuick 2.2
17import QtQuick 2.2
18import Ubuntu.Components 1.1
18import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
19
20
20ScopeSetting {
21ScopeSetting {
21 id: root
22 id: root
22− implicitHeight: optionSelector.implicitHeight
23
23
24− OptionSelector {
24+ ListItem.ItemSelector {
25− id: optionSelector
25+ id: control
26+ objectName: "control"
26 anchors {
27 anchors {
27 left: parent.left
28 left: parent.left
28 right: parent.right
29 right: parent.right
29− top: parent.top
30− margins: __margins
31 }
30 }
32 text: widgetData.displayName
31 text: widgetData.displayName
33 model: widgetData.properties["values"]
32 model: widgetData.properties["values"]
34
33
35− onSelectedIndexChanged: root.triggered(selectedIndex)
34+ onSelectedIndexChanged: root.updated(selectedIndex)
36 }
35 }
37}
36}
qml/Dash/ScopeSettings/ScopeSettingNumber.qml+42−23
@@ -16,37 +16,56 @@
16
16
17import QtQuick 2.2
17import QtQuick 2.2
18import Ubuntu.Components 1.1
18import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.0 as ListItem
19
20
20ScopeSetting {
21ScopeSetting {
21 id: root
22 id: root
22− implicitHeight: units.gu(6)
23
23
24− Label {
24+ ListItem.Empty {
25− anchors {
25+ onClicked: {
26− left: parent.left
26+ control.focus = true;
27− leftMargin: __margins
28− right: control.left
27+ control.selectAll();
29− rightMargin: units.gu(1)
30− verticalCenter: parent.verticalCenter
31 }
28 }
32− text: widgetData.displayName
33− elide: Text.ElideMiddle
34− color: scopeStyle ? scopeStyle.foreground : "grey"
35− }
36
29
37− TextField {
30+ Label {
31+ anchors {
32+ left: parent.left
33+ leftMargin: __margins
38− id: control
34+ right: control.left
39− anchors {
40− right: parent.right
41− rightMargin: __margins
35+ rightMargin: units.gu(1)
42− verticalCenter: parent.verticalCenter
36+ verticalCenter: parent.verticalCenter
37+ }
38+ text: widgetData.displayName
39+ elide: Text.ElideMiddle
40+ color: scopeStyle ? scopeStyle.foreground : "grey"
43 }
41 }
44− text: widgetData.value
45− validator: DoubleValidator {}
46
42
47− onTriggered: 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()
48− onActiveFocusChanged: {
64+ onActiveFocusChanged: {
49− if (!activeFocus) root.triggered(text);
65+ if (!activeFocus) {
66+ updateText();
67+ }
68+ }
50 }
69 }
51 }
70 }
52}
71}
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 {
29 widgetData: model
29 widgetData: model
30 scopeStyle: root.scopeStyle
30 scopeStyle: root.scopeStyle
31
31
32− onTriggered: model.value = value;
32+ onUpdated: model.value = value;
33 }
33 }
34}
34}
qml/Dash/ScopeSettings/ScopeSettingWidgetFactory.qml → qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qmlrenamed+6−5
@@ -28,17 +28,17 @@ Loader {
28 property var widgetData: null
28 property var widgetData: null
29
29
30 //! Triggered signal forwarded from the widgets.
30 //! Triggered signal forwarded from the widgets.
31− signal triggered(var value)
31+ signal updated(var value)
32
32
33 source: widgetSource
33 source: widgetSource
34
34
35 //! \cond private
35 //! \cond private
36 property url widgetSource: {
36 property url widgetSource: {
37 switch (widgetData.type) {
37 switch (widgetData.type) {
38− case "boolean": return "ScopeSettingSwitch.qml";
38+ case "boolean": return "ScopeSettingBoolean.qml";
39− case "list": return "ScopeSettingSwitch.qml";
39+ case "list": return "ScopeSettingList.qml";
40 case "number": return "ScopeSettingNumber.qml";
40 case "number": return "ScopeSettingNumber.qml";
41− case "string": return "ScopeSettingLabel.qml";
41+ case "string": return "ScopeSettingString.qml";
42 default: return "";
42 default: return "";
43 }
43 }
44 }
44 }
@@ -46,10 +46,11 @@ Loader {
46
46
47 onLoaded: {
47 onLoaded: {
48 item.widgetData = Qt.binding(function() { return root.widgetData } )
48 item.widgetData = Qt.binding(function() { return root.widgetData } )
49+ item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
49 }
50 }
50
51
51 Connections {
52 Connections {
52 target: root.item
53 target: root.item
53− onTriggered: root.triggered(value)
54+ onUpdated: root.updated(value)
54 }
55 }
55}
56}
tests/qmltests/CMakeLists.txt+5−2
@@ -53,8 +53,11 @@ add_qml_test(Dash/Previews PreviewTextSummary)
53add_qml_test(Dash/Previews PreviewVideoPlayback)
53add_qml_test(Dash/Previews PreviewVideoPlayback)
54add_qml_test(Dash/Previews PreviewWidgetFactory)
54add_qml_test(Dash/Previews PreviewWidgetFactory)
55add_qml_test(Dash/Previews PreviewZoomableImage)
55add_qml_test(Dash/Previews PreviewZoomableImage)
56−add_qml_test(Dash/ScopeSettings ScopeSettingLabel)
56+add_qml_test(Dash/ScopeSettings ScopeSettingBoolean)
57+add_qml_test(Dash/ScopeSettings ScopeSettingList)
57−add_qml_test(Dash/ScopeSettings ScopeSettingSwitch)
58+add_qml_test(Dash/ScopeSettings ScopeSettingNumber)
59+add_qml_test(Dash/ScopeSettings ScopeSettingString)
60+add_qml_test(Dash/ScopeSettings ScopeSettingsWidgetFactory)
58add_qml_test(Greeter Lockscreen ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
61add_qml_test(Greeter Lockscreen ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
59add_qml_test(Greeter MultiGreeter ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
62add_qml_test(Greeter MultiGreeter ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
60add_qml_test(Greeter SingleGreeter ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
63add_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 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import Ubuntu.Components 1.1
18import QtTest 1.0
19import QtTest 1.0
19import "../../../../qml/Dash/ScopeSettings"
20import "../../../../qml/Dash/ScopeSettings"
20import Unity.Test 0.1 as UT
21import Unity.Test 0.1 as UT
@@ -25,38 +26,32 @@ Rectangle {
25 height: units.gu(80)
26 height: units.gu(80)
26
27
27 property var settingData: {
28 property var settingData: {
28− "displayName" : "Fake boolean setting",
29+ "displayName" : "Mock boolean setting",
29 "value": true
30 "value": true
30 }
31 }
31
32
32− ScopeSettingSwitch {
33+ ScopeSettingBoolean {
33− id: scopeSettingSwitch
34+ id: scopeSetting
34 widgetData: settingData
35 widgetData: settingData
35− width: units.gu(40)
36+ width: parent.width
36−
37− Rectangle {
38− anchors.fill: parent
39− color: "red"
40− opacity: 0.1
41− }
42 }
37 }
43
38
44 SignalSpy {
39 SignalSpy {
45− id: triggeredSpy
40+ id: spy
46− target: scopeSettingSwitch
41+ target: scopeSetting
47− signalName: "triggered"
42+ signalName: "updated"
48 }
43 }
49
44
50 UT.UnityTestCase {
45 UT.UnityTestCase {
51 id: testCase
46 id: testCase
52− name: "ScopeSettingSwitchTest"
47+ name: "ScopeSettingBooleanTest"
53 when: windowShown
48 when: windowShown
54
49
55− function test_triggered() {
50+ function test_updated() {
56− var control = findChild(scopeSettingSwitch, "control");
51+ var control = findChild(scopeSetting, "control");
57 mouseClick(control, control.width / 2, control.height / 2);
52 mouseClick(control, control.width / 2, control.height / 2);
58− triggeredSpy.wait();
53+ spy.wait();
59− compare(triggeredSpy.signalArguments[0][0], false);
54+ compare(spy.signalArguments[0][0], false);
60 }
55 }
61 }
56 }
62}
57}
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+}