on xenial help sign in
Fix anchor in PreviewListView.qml.

Approved by: Andrea Cimitan

commitcad788d211a40f23ecbe6fcf67dbfd8675d576b0 authorMichał Sawicz <michal.sawicz@canonical.com> dateThu 14 Aug 2014, 01:28 (12 years ago) parent057380628302fa
8 files changed+108−9
qml/Dash/PreviewListView.qml−8 tests/mocks/Unity/fake_previewmodel.cpp+10−1 tests/mocks/Unity/fake_previewmodel.h+3 tests/mocks/Unity/fake_resultsmodel.cpp+5 tests/mocks/Unity/fake_resultsmodel.h+1 tests/mocks/Unity/fake_unity_plugin.cpp+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/tst_PreviewListView.qml+87
qml/Dash/PreviewListView.qml−8
@@ -65,14 +65,6 @@ Item {
6565 maximumFlickVelocity: width * 5
6666 cacheBuffer: 0
6767
68− // To be set before opening the preview
69− property string categoryId: ""
70−
71− // because the ListView is built asynchronous, setting the
72− // currentIndex directly won't work. We need to refresh it
73− // when the first preview is ready to be displayed.
74− property bool init: true
75−
7668 property bool open: false
7769
7870 onOpenChanged: {
tests/mocks/Unity/fake_previewmodel.cpp+10−1
@@ -29,6 +29,7 @@
2929
3030PreviewModel::PreviewModel(QObject* parent)
3131 : unity::shell::scopes::PreviewModelInterface(parent)
32+ , m_loaded(true)
3233{
3334 // we have one column by default
3435 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
@@ -49,7 +50,7 @@ int PreviewModel::widgetColumnCount() const
4950
5051bool PreviewModel::loaded() const
5152{
52− return true;
53+ return m_loaded;
5354}
5455
5556bool PreviewModel::processingAction() const
@@ -71,3 +72,11 @@ QVariant PreviewModel::data(const QModelIndex& index, int role) const
7172 return QVariant();
7273 }
7374}
75+
76+void PreviewModel::setLoaded(bool loaded)
77+{
78+ if (m_loaded != loaded) {
79+ m_loaded = loaded;
80+ Q_EMIT loadedChanged();
81+ }
82+}
tests/mocks/Unity/fake_previewmodel.h+3
@@ -40,8 +40,11 @@ public:
4040 bool loaded() const override;
4141 bool processingAction() const override;
4242
43+ Q_INVOKABLE void setLoaded(bool); // Only available for testing
44+
4345private:
4446 QList<PreviewWidgetModel*> m_previewWidgetModels;
47+ bool m_loaded;
4548};
4649
4750Q_DECLARE_METATYPE(PreviewModel*)
tests/mocks/Unity/fake_resultsmodel.cpp+5
@@ -29,6 +29,11 @@ ResultsModel::ResultsModel(int result_count, int categoryId, QObject* parent)
2929{
3030}
3131
32+ResultsModel::ResultsModel(QObject *parent)
33+ : ResultsModel::ResultsModel(10, 1, parent)
34+{
35+}
36+
3237QString ResultsModel::categoryId() const
3338{
3439 return QString::number(m_categoryId);
tests/mocks/Unity/fake_resultsmodel.h+1
@@ -29,6 +29,7 @@ class ResultsModel : public unity::shell::scopes::ResultsModelInterface
2929
3030public:
3131 explicit ResultsModel(int result_count, int categoryId, QObject* parent = 0);
32+ explicit ResultsModel(QObject* parent = 0);
3233
3334 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
3435 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
tests/mocks/Unity/fake_unity_plugin.cpp+1
@@ -47,6 +47,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4747 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4848 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
4949 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
50+ qmlRegisterType<ResultsModel>(uri, 0, 2, "FakeResultsModel");
5051 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
5152 qmlRegisterUncreatableType<PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", "Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.");
5253 qmlRegisterUncreatableType<PreviewStack>(uri, 0, 2, "PreviewStack", "Can't create new PreviewStack in QML. Get them from Scope instance.");
tests/qmltests/CMakeLists.txt+1
@@ -39,6 +39,7 @@ add_qml_test(Dash Card)
3939add_qml_benchmark(Dash CardBenchmark 1000)
4040add_qml_test(Dash CardTool)
4141add_qml_test(Dash GenericScopeView)
42+add_qml_test(Dash PreviewListView)
4243add_qml_test(Dash/Previews Preview)
4344add_qml_test(Dash/Previews PreviewActions)
4445add_qml_test(Dash/Previews PreviewAudioPlayback)
tests/qmltests/Dash/tst_PreviewListView.qmlnew file+87
@@ -0,0 +1,87 @@
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"
20+import Unity.Test 0.1 as UT
21+import Unity 0.2 as Unity
22+import Dash 0.1
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(60)
28+ color: Theme.palette.selected.background
29+
30+ Unity.MockScope {
31+ id: mockScope
32+ }
33+
34+ Unity.FakeResultsModel {
35+ id: mockResultsModel
36+ }
37+
38+ PreviewListView {
39+ id: listView
40+ anchors.fill: parent
41+ scope: mockScope
42+ scopeStyle: ScopeStyle { }
43+ }
44+
45+ UT.UnityTestCase {
46+ id: testCase
47+ name: "PreviewListView"
48+ when: windowShown
49+
50+ property MouseArea mouseArea: findChild(listView, "processingMouseArea")
51+
52+ SignalSpy {
53+ id: clickedSpy
54+ signalName: "clicked"
55+ target: testCase.mouseArea
56+ }
57+
58+ function init() {
59+ listView.model = mockResultsModel;
60+ listView.currentIndex = 1;
61+ listView.open = true;
62+ verify(testCase.mouseArea, "Can't find the processingMouseArea object.");
63+ }
64+
65+ function cleanup() {
66+ listView.open = false;
67+ listView.model = null;
68+ clickedSpy.clear();
69+ }
70+
71+ function test_notProcessing() {
72+ expectFail("", "processingMouseArea should not receive the click.");
73+ mouseClick(listView, listView.width / 2, listView.height / 2);
74+ clickedSpy.wait();
75+ }
76+
77+ function test_processing() {
78+ verify(listView.currentItem, "currentItem is not ready yet");
79+ listView.currentItem.previewModel.setLoaded(false);
80+
81+ tryCompare(listView, "processing", true);
82+
83+ mouseClick(listView, listView.width / 2, listView.height / 2);
84+ clickedSpy.wait();
85+ }
86+ }
87+}