on xenial help sign in
Add more tests and fix review comments.
commit8fa3cc42436ae48147203e15b07abff2d4c9c24c authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 7 Feb 2014, 10:57 (13 years ago) parent20c47f3
4 files changed+36−9
qml/Dash/Previews/Preview.qml+4 qml/Dash/Previews/PreviewWidgetFactory.qml+1−3 tests/mocks/Unity/scopes-ng/fake_preview_model.cpp+5−6 tests/qmltests/Dash/Previews/tst_Preview.qml+26
qml/Dash/Previews/Preview.qml+4
@@ -72,6 +72,8 @@ Item {
7272
7373 model: previewModel
7474
75+ Behavior on contentY { UbuntuNumberAnimation { } }
76+
7577 delegate: PreviewWidgetFactory {
7678 widgetId: model.widgetId
7779 widgetType: model.type
@@ -85,6 +87,8 @@ Item {
8587 }
8688
8789 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
90+
91+ onHeightChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
8892 }
8993 }
9094 }
qml/Dash/Previews/PreviewWidgetFactory.qml+1−3
@@ -16,8 +16,6 @@
1616 */
1717
1818import QtQuick 2.0
19−import Ubuntu.Components 0.1
20−import Unity 0.1
2119
2220//! \brief This component loads the widgets based on widgetData["type"].
2321
@@ -40,7 +38,7 @@ Loader {
4038 signal triggered(string widgetId, string actionId, var data)
4139
4240 source: {
43− switch (type) {
41+ switch (widgetType) {
4442 case "audio": return "PreviewAudioPlayback.qml";
4543 case "text": return "PreviewTextSummary.qml";
4644 case "gallery": return "PreviewImageGallery.qml";
tests/mocks/Unity/scopes-ng/fake_preview_model.cpp+5−6
@@ -51,17 +51,16 @@ void PreviewModel::populateWidgets()
5151{
5252 beginResetModel();
5353 m_previewWidgets.clear();
54− endResetModel();
55− beginInsertRows(QModelIndex(), 0, 4);
56− for (int i = 0; i <= 5; ++i) {
54+ for (int i = 0; i <= 20; i++) {
5755 // FIXME: the API will expose nicer getters soon, use those!
5856 QVariantMap attributes;
59− attributes["text"] = QVariant::fromValue(QString("Text"));
60− attributes["title"] = QVariant::fromValue(QString("Title"));
57+ attributes["text"] = QVariant::fromValue(QString("Widget %1").arg(i));
58+ attributes["title"] = QVariant::fromValue(QString("Title %1").arg(i));
6159 PreviewData* preview_data = new PreviewData(QString("widget-%1").arg(i), QString("text"), attributes);
6260 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
6361 }
64− endInsertRows();
62+ endResetModel();
63+
6564}
6665
6766void PreviewModel::triggered(QString widgetId, QString actionId, QVariantMap data)
tests/qmltests/Dash/Previews/tst_Preview.qml+26
@@ -57,6 +57,7 @@ Rectangle {
5757 when: windowShown
5858
5959 function test_triggered() {
60+ waitForRendering(preview);
6061 var widget = findChild(preview, "widget-3");
6162
6263 compare(typeof widget, "object", "Could not find the widget object.");
@@ -73,6 +74,7 @@ Rectangle {
7374 }
7475
7576 function test_showProcessing() {
77+ waitForRendering(preview);
7678 var widget = findChild(preview, "widget-3");
7779 widget.triggered(widget.widgetId, "mockAction", {"mock": "data"});
7880
@@ -84,5 +86,29 @@ Rectangle {
8486
8587 tryCompare(processing, "enabled", false);
8688 }
89+
90+ function test_containOnFocus() {
91+ waitForRendering(preview);
92+ var widget = findChild(preview, "widget-13");
93+
94+ widget.forceActiveFocus();
95+
96+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
97+
98+ tryCompareFunction(function () { return bottomLeft.y <= preview.height }, true);
99+ }
100+
101+ function test_containOnGrow() {
102+ waitForRendering(preview);
103+ var widget = findChild(preview, "widget-13");
104+
105+ widget.forceActiveFocus();
106+ widget.height += 200;
107+
108+ tryCompareFunction(function () {
109+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
110+ return bottomLeft.y <= preview.height
111+ }, true);
112+ }
87113 }
88114}