on xenial help sign in
Fix anchor in PreviewListView.qml.
cad788dMichał Sawicz
qml/Dash/PreviewListView.qml−8
@@ -65,14 +65,6 @@ Item {
65 maximumFlickVelocity: width * 5
65 maximumFlickVelocity: width * 5
66 cacheBuffer: 0
66 cacheBuffer: 0
67
67
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−
76 property bool open: false
68 property bool open: false
77
69
78 onOpenChanged: {
70 onOpenChanged: {
tests/mocks/Unity/fake_previewmodel.cpp+10−1
@@ -29,6 +29,7 @@
29
29
30PreviewModel::PreviewModel(QObject* parent)
30PreviewModel::PreviewModel(QObject* parent)
31 : unity::shell::scopes::PreviewModelInterface(parent)
31 : unity::shell::scopes::PreviewModelInterface(parent)
32+ , m_loaded(true)
32{
33{
33 // we have one column by default
34 // we have one column by default
34 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
35 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
@@ -49,7 +50,7 @@ int PreviewModel::widgetColumnCount() const
49
50
50bool PreviewModel::loaded() const
51bool PreviewModel::loaded() const
51{
52{
52− return true;
53+ return m_loaded;
53}
54}
54
55
55bool PreviewModel::processingAction() const
56bool PreviewModel::processingAction() const
@@ -71,3 +72,11 @@ QVariant PreviewModel::data(const QModelIndex& index, int role) const
71 return QVariant();
72 return QVariant();
72 }
73 }
73}
74}
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:
40 bool loaded() const override;
40 bool loaded() const override;
41 bool processingAction() const override;
41 bool processingAction() const override;
42
42
43+ Q_INVOKABLE void setLoaded(bool); // Only available for testing
44+
43private:
45private:
44 QList<PreviewWidgetModel*> m_previewWidgetModels;
46 QList<PreviewWidgetModel*> m_previewWidgetModels;
47+ bool m_loaded;
45};
48};
46
49
47Q_DECLARE_METATYPE(PreviewModel*)
50Q_DECLARE_METATYPE(PreviewModel*)
tests/mocks/Unity/fake_resultsmodel.cpp+5
@@ -29,6 +29,11 @@ ResultsModel::ResultsModel(int result_count, int categoryId, QObject* parent)
29{
29{
30}
30}
31
31
32+ResultsModel::ResultsModel(QObject *parent)
33+ : ResultsModel::ResultsModel(10, 1, parent)
34+{
35+}
36+
32QString ResultsModel::categoryId() const
37QString ResultsModel::categoryId() const
33{
38{
34 return QString::number(m_categoryId);
39 return QString::number(m_categoryId);
tests/mocks/Unity/fake_resultsmodel.h+1
@@ -29,6 +29,7 @@ class ResultsModel : public unity::shell::scopes::ResultsModelInterface
29
29
30public:
30public:
31 explicit ResultsModel(int result_count, int categoryId, QObject* parent = 0);
31 explicit ResultsModel(int result_count, int categoryId, QObject* parent = 0);
32+ explicit ResultsModel(QObject* parent = 0);
32
33
33 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
34 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
34 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
35 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)
47 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
47 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
48 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
48 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
49 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
49 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
50+ qmlRegisterType<ResultsModel>(uri, 0, 2, "FakeResultsModel");
50 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
51 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
51 qmlRegisterUncreatableType<PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", "Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.");
52 qmlRegisterUncreatableType<PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", "Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.");
52 qmlRegisterUncreatableType<PreviewStack>(uri, 0, 2, "PreviewStack", "Can't create new PreviewStack in QML. Get them from Scope instance.");
53 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)
39add_qml_benchmark(Dash CardBenchmark 1000)
39add_qml_benchmark(Dash CardBenchmark 1000)
40add_qml_test(Dash CardTool)
40add_qml_test(Dash CardTool)
41add_qml_test(Dash GenericScopeView)
41add_qml_test(Dash GenericScopeView)
42+add_qml_test(Dash PreviewListView)
42add_qml_test(Dash/Previews Preview)
43add_qml_test(Dash/Previews Preview)
43add_qml_test(Dash/Previews PreviewActions)
44add_qml_test(Dash/Previews PreviewActions)
44add_qml_test(Dash/Previews PreviewAudioPlayback)
45add_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+}