on xenial help sign in
Unit tests
commit8e6a8115ede0c45f32dddb596e78abb91b59882e authorAlbert Astals <albert.astals@canonical.com> dateThu 6 Feb 2014, 13:18 (13 years ago) parentc251e13
5 files changed+62−10
qml/Dash/Previews/PreviewActionButton.qml+1−1 qml/Dash/Previews/PreviewActionCombo.qml+2−2 qml/Dash/Previews/PreviewActions.qml+6−1 qml/Dash/Previews/PreviewWidget.qml+1−1 tests/qmltests/Dash/Previews/tst_PreviewActions.qml+52−5
qml/Dash/Previews/PreviewActionButton.qml+1−1
@@ -14,6 +14,7 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17+import QtQuick 2.0
1718import Ubuntu.Components 0.1
1819
1920Button {
@@ -21,7 +22,6 @@ Button {
2122
2223 property var data: null
2324 objectName: "button" + (data && data.id || "")
24− // TODO missing property for color
2525 color: Theme.palette.selected.foreground
2626 text: data && data.label || ""
2727 iconSource: data && data.icon || ""
qml/Dash/Previews/PreviewActionCombo.qml+2−2
@@ -31,7 +31,7 @@ Item {
3131 id: moreButton
3232 property bool expanded: false
3333
34− objectName: "button1"
34+ objectName: "moreLessButton"
3535 text: !expanded ? i18n.tr("More...") : i18n.tr("Less...")
3636 gradient: UbuntuColors.orangeGradient
3737 onClicked: expanded = !expanded
@@ -51,7 +51,7 @@ Item {
5151 id: actionRepeater
5252
5353 delegate: Button {
54− objectName: "button" + index
54+ objectName: "button" + modelData.id
5555 text: modelData.label || ""
5656 iconSource: modelData.icon || ""
5757 gradient: UbuntuColors.orangeGradient
qml/Dash/Previews/PreviewActions.qml+6−1
@@ -16,6 +16,11 @@
1616
1717import QtQuick 2.1
1818
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+
1924PreviewWidget {
2025 id: root
2126
@@ -36,7 +41,7 @@ PreviewWidget {
3641 if (button) {
3742 item.data = actions[1];
3843 } else if (combo) {
39− item.model = actions.splice(1)
44+ item.model = actions.slice(1)
4045 }
4146 }
4247 Connections {
qml/Dash/Previews/PreviewWidget.qml+1−1
@@ -22,7 +22,7 @@ Item {
2222 /// type:bool Specifies the preview widget being currently used or not
2323 property bool isCurrentPreview: true
2424
25− // The id of the widget
25+ //! The id of the widget
2626 property string widgetId
2727
2828 /// Variable used to contain widget's data
tests/qmltests/Dash/Previews/tst_PreviewActions.qml+52−5
@@ -45,22 +45,30 @@ Rectangle {
4545 ]
4646 }
4747
48+ SignalSpy {
49+ id: spy
50+ signalName: "triggered"
51+ }
52+
4853 Column {
4954 spacing: units.gu(1)
5055
5156 PreviewActions {
57+ id: oneAction
5258 widgetId: "button"
5359 widgetData: actionDataOneAction
5460 onTriggered: console.log("triggered", widgetId, actionId, data);
5561 }
5662
5763 PreviewActions {
64+ id: buttonAndCombo
5865 widgetId: "buttonAndCombo"
5966 widgetData: actionDataFiveActions
6067 onTriggered: console.log("triggered", widgetId, actionId, data);
6168 }
6269
6370 PreviewActions {
71+ id: twoActions
6472 widgetId: "2buttons"
6573 widgetData: actionDataTwoActions
6674 onTriggered: console.log("triggered", widgetId, actionId, data);
@@ -71,11 +79,50 @@ Rectangle {
7179 name: "PreviewActionTest"
7280 when: windowShown
7381
74− function test_changeEmptyModel() {
75− wait(5000);
76−// imageGallery.widgetData = sourcesModel0;
77−// var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
78−// compare(placeholderScreenshot.visible, true);
82+ function checkButtonPressSignal(target, id, buttonNumber)
83+ {
84+ var button = findChild(root, "button" + id);
85+ verify(button != null);
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);
79126 }
80127 }
81128}