on xenial help sign in
Unit tests
8e6a811Albert Astals
qml/Dash/Previews/PreviewActionButton.qml+1−1
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17+import QtQuick 2.0
17import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
18
19
19Button {
20Button {
@@ -21,7 +22,6 @@ Button {
21
22
22 property var data: null
23 property var data: null
23 objectName: "button" + (data && data.id || "")
24 objectName: "button" + (data && data.id || "")
24− // TODO missing property for color
25 color: Theme.palette.selected.foreground
25 color: Theme.palette.selected.foreground
26 text: data && data.label || ""
26 text: data && data.label || ""
27 iconSource: data && data.icon || ""
27 iconSource: data && data.icon || ""
qml/Dash/Previews/PreviewActionCombo.qml+2−2
@@ -31,7 +31,7 @@ Item {
31 id: moreButton
31 id: moreButton
32 property bool expanded: false
32 property bool expanded: false
33
33
34− objectName: "button1"
34+ objectName: "moreLessButton"
35 text: !expanded ? i18n.tr("More...") : i18n.tr("Less...")
35 text: !expanded ? i18n.tr("More...") : i18n.tr("Less...")
36 gradient: UbuntuColors.orangeGradient
36 gradient: UbuntuColors.orangeGradient
37 onClicked: expanded = !expanded
37 onClicked: expanded = !expanded
@@ -51,7 +51,7 @@ Item {
51 id: actionRepeater
51 id: actionRepeater
52
52
53 delegate: Button {
53 delegate: Button {
54− objectName: "button" + index
54+ objectName: "button" + modelData.id
55 text: modelData.label || ""
55 text: modelData.label || ""
56 iconSource: modelData.icon || ""
56 iconSource: modelData.icon || ""
57 gradient: UbuntuColors.orangeGradient
57 gradient: UbuntuColors.orangeGradient
qml/Dash/Previews/PreviewActions.qml+6−1
@@ -16,6 +16,11 @@
16
16
17import QtQuick 2.1
17import QtQuick 2.1
18
18
19+/*! This preview widget shows a either one button, two buttons or one button
20+ * and a combo button depending on the number of items in widgetData["actions"].
21+ * For each of the items we recognize the fields "label", "icon" and "id".
22+ */
23+
19PreviewWidget {
24PreviewWidget {
20 id: root
25 id: root
21
26
@@ -36,7 +41,7 @@ PreviewWidget {
36 if (button) {
41 if (button) {
37 item.data = actions[1];
42 item.data = actions[1];
38 } else if (combo) {
43 } else if (combo) {
39− item.model = actions.splice(1)
44+ item.model = actions.slice(1)
40 }
45 }
41 }
46 }
42 Connections {
47 Connections {
qml/Dash/Previews/PreviewWidget.qml+1−1
@@ -22,7 +22,7 @@ Item {
22 /// type:bool Specifies the preview widget being currently used or not
22 /// type:bool Specifies the preview widget being currently used or not
23 property bool isCurrentPreview: true
23 property bool isCurrentPreview: true
24
24
25− // The id of the widget
25+ //! The id of the widget
26 property string widgetId
26 property string widgetId
27
27
28 /// Variable used to contain widget's data
28 /// Variable used to contain widget's data
tests/qmltests/Dash/Previews/tst_PreviewActions.qml+52−5
@@ -45,22 +45,30 @@ Rectangle {
45 ]
45 ]
46 }
46 }
47
47
48+ SignalSpy {
49+ id: spy
50+ signalName: "triggered"
51+ }
52+
48 Column {
53 Column {
49 spacing: units.gu(1)
54 spacing: units.gu(1)
50
55
51 PreviewActions {
56 PreviewActions {
57+ id: oneAction
52 widgetId: "button"
58 widgetId: "button"
53 widgetData: actionDataOneAction
59 widgetData: actionDataOneAction
54 onTriggered: console.log("triggered", widgetId, actionId, data);
60 onTriggered: console.log("triggered", widgetId, actionId, data);
55 }
61 }
56
62
57 PreviewActions {
63 PreviewActions {
64+ id: buttonAndCombo
58 widgetId: "buttonAndCombo"
65 widgetId: "buttonAndCombo"
59 widgetData: actionDataFiveActions
66 widgetData: actionDataFiveActions
60 onTriggered: console.log("triggered", widgetId, actionId, data);
67 onTriggered: console.log("triggered", widgetId, actionId, data);
61 }
68 }
62
69
63 PreviewActions {
70 PreviewActions {
71+ id: twoActions
64 widgetId: "2buttons"
72 widgetId: "2buttons"
65 widgetData: actionDataTwoActions
73 widgetData: actionDataTwoActions
66 onTriggered: console.log("triggered", widgetId, actionId, data);
74 onTriggered: console.log("triggered", widgetId, actionId, data);
@@ -71,11 +79,50 @@ Rectangle {
71 name: "PreviewActionTest"
79 name: "PreviewActionTest"
72 when: windowShown
80 when: windowShown
73
81
74− function test_changeEmptyModel() {
82+ function checkButtonPressSignal(target, id, buttonNumber)
75− wait(5000);
83+ {
76−// imageGallery.widgetData = sourcesModel0;
84+ var button = findChild(root, "button" + id);
77−// var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
85+ verify(button != null);
78−// compare(placeholderScreenshot.visible, true);
86+ spy.target = target;
87+ spy.clear();
88+ mouseClick(button, button.width / 2, button.height / 2);
89+ compare(spy.count, 1);
90+ compare(spy.signalArguments[0][0], target.widgetId);
91+ compare(spy.signalArguments[0][1], id);
92+ compare(spy.signalArguments[0][2], target.widgetData["actions"][buttonNumber]);
93+ }
94+
95+ function test_checkButtons_data() {
96+ return [
97+ {tag: "oneActionButton", target: oneAction, id: "someid", buttonNumber: 0 },
98+ {tag: "twobuttonsButton0", target: twoActions, id: "someid1", buttonNumber: 0 },
99+ {tag: "twobuttonsButton1", target: twoActions, id: "someid2", buttonNumber: 1 },
100+ {tag: "buttonAndComboButton0", target: buttonAndCombo, id: "someid3", buttonNumber: 0 }
101+ ]
102+ }
103+
104+ function test_checkButtons(data) {
105+ checkButtonPressSignal(data.target, data.id, data.buttonNumber)
106+ }
107+
108+ function test_comboButton_data() {
109+ return [
110+ {tag: "button1", id: "someid4", buttonNumber: 1 },
111+ {tag: "button2", id: "someid5", buttonNumber: 2 },
112+ {tag: "button3", id: "someid6", buttonNumber: 3 },
113+ {tag: "button4", id: "someid7", buttonNumber: 4 }
114+ ]
115+ }
116+
117+ function test_comboButton(data) {
118+ var button = findChild(root, "moreLessButton");
119+ verify(button != null);
120+ var twoActionsY = twoActions.y
121+ mouseClick(button, button.width / 2, button.height / 2);
122+ tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
123+ checkButtonPressSignal(buttonAndCombo, data.id, data.buttonNumber);
124+ mouseClick(button, button.width / 2, button.height / 2);
125+ tryCompare(twoActions, "y", twoActionsY);
79 }
126 }
80 }
127 }
81}
128}