on xenial help sign in
Test for bug #1316660

preview combo should autoscroll to make sure its child buttons are on screen

commitcbf0b891fe789852717122725f911320d2dd4d59 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 10 Feb 2015, 17:00 (12 years ago) parent3f18c22
3 files changed+42
qml/Dash/Previews/Preview.qml+1 tests/mocks/Unity/fake_previewwidgetmodel.cpp+10 tests/qmltests/Dash/Previews/tst_Preview.qml+31
qml/Dash/Previews/Preview.qml+1
@@ -65,6 +65,7 @@ Item {
6565
6666 delegate: ListView {
6767 id: column
68+ objectName: "previewListRow" + index
6869 anchors { top: parent.top; bottom: parent.bottom }
6970 width: row.columnWidth
7071 spacing: row.spacing
tests/mocks/Unity/fake_previewwidgetmodel.cpp+10
@@ -53,6 +53,16 @@ void PreviewWidgetModel::populateWidgets()
5353 PreviewData* preview_data = new PreviewData(QString("widget-%1").arg(i), QString("text"), attributes);
5454 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
5555 }
56+
57+ QVariantMap attributes;
58+ QVariantMap buttonData;
59+ buttonData["label"] = "Button";
60+ QVariantList buttons;
61+ buttons << buttonData << buttonData << buttonData;
62+ attributes["actions"] = QVariant::fromValue(buttons);
63+ PreviewData* preview_data = new PreviewData(QString("widget-21"), QString("actions"), attributes);
64+ m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
65+
5666 endResetModel();
5767
5868}
tests/qmltests/Dash/Previews/tst_Preview.qml+31
@@ -54,6 +54,11 @@ Rectangle {
5454 name: "Preview"
5555 when: windowShown
5656
57+ function init() {
58+ var widget = findChild(preview, "previewListRow0");
59+ widget.positionViewAtBeginning();
60+ }
61+
5762 function test_triggered() {
5863 waitForRendering(preview);
5964 var widget = findChild(preview, "widget-3");
@@ -102,5 +107,31 @@ Rectangle {
102107 return bottomLeft.y <= preview.height
103108 }, true);
104109 }
110+
111+ function test_comboEnsureVisible() {
112+ waitForRendering(preview);
113+
114+ // Scroll down
115+ var previewListRow0 = findChild(preview, "previewListRow0");
116+ touchFlick(preview, preview.width / 2, units.gu(20), preview.width / 2, units.gu(1));
117+ tryCompare(previewListRow0, "atYEnd", true);
118+ tryCompare(previewListRow0, "moving", false);
119+
120+ // Click on the combo
121+ var widget = findChild(preview, "widget-21");
122+ var initialWidgetHeight = widget.height;
123+ var moreLessButton = findChild(widget, "moreLessButton");
124+ mouseClick(moreLessButton);
125+
126+ // Make sure the combo is growing
127+ tryCompareFunction(function () { return widget.height > 2 * initialWidgetHeight; }, true);
128+
129+ // Wait for the combo to stop growing
130+ tryCompareFunction(function () { var currentWidgetHeight = widget.height; wait(200); return currentWidgetHeight === widget.height;}, true);
131+
132+ // Make sure the combo bottom is on the viewport
133+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
134+ verify(bottomLeft.y <= preview.height);
135+ }
105136 }
106137}