on xenial help sign in
Better fix for tests for the old bug and for a new one introduced by the previous fix
commitfd9dd23d8b0c8851a4eb7351d21a9a7240fef0a4 authorAlbert Astals <albert.astals@canonical.com> dateTue 28 Jan 2014, 16:57 (13 years ago) parent145ccae
5 files changed+61−29
qml/Dash/GenericScopeView.qml+4−4 qml/Dash/PreviewListView.qml+9−8 tests/mocks/Unity/fake_scope.cpp+4−4 tests/mocks/Unity/fake_scopes.cpp+1−1 tests/qmltests/Dash/tst_GenericScopeView.qml+43−12
qml/Dash/GenericScopeView.qml+4−4
@@ -186,10 +186,10 @@ FocusScope {
186186 onClicked: {
187187 // Prepare the preview in case activate() triggers a preview only
188188 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
189− previewListView.needsInit = true;
190189 previewListView.categoryId = categoryId
191190 previewListView.categoryDelegate = rendererLoader.item
192191 previewListView.model = target.model;
192+ previewListView.init = true;
193193 previewListView.currentIndex = index;
194194
195195 var item = target.model.get(index);
@@ -207,10 +207,10 @@ FocusScope {
207207 }
208208 onPressAndHold: {
209209 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
210− previewListView.needsInit = true;
211210 previewListView.categoryId = categoryId
212211 previewListView.categoryDelegate = rendererLoader.item
213212 previewListView.model = target.model;
213+ previewListView.init = true;
214214 previewListView.currentIndex = index;
215215 previewListView.open = true
216216
@@ -364,7 +364,7 @@ FocusScope {
364364 Connections {
365365 target: scopeView.scope
366366 onPreviewReady: {
367− if (previewListView.needsInit) {
367+ if (previewListView.init) {
368368 // Preview was triggered because of a click on the item. Need to expand now.
369369 if (!previewListView.open) {
370370 previewListView.open = true
@@ -372,8 +372,8 @@ FocusScope {
372372
373373 var index = previewListView.currentIndex
374374 previewListView.currentIndex = -1
375− previewListView.needsInit = false
376375 previewListView.currentIndex = index
376+ previewListView.init = false
377377 }
378378 previewListView.currentItem.previewData = preview
379379 }
qml/Dash/PreviewListView.qml+9−8
@@ -28,7 +28,7 @@ Item {
2828 property alias onScreen: previewListView.onScreen
2929 property alias categoryId: previewListView.categoryId
3030 property alias categoryDelegate: previewListView.categoryDelegate
31− property alias needsInit: previewListView.needsInit
31+ property alias init: previewListView.init
3232 property alias model: previewListView.model
3333 property alias currentIndex: previewListView.currentIndex
3434 property alias currentItem: previewListView.currentItem
@@ -82,14 +82,16 @@ Item {
8282 // because the ListView is built asynchronous, setting the
8383 // currentIndex directly won't work. We need to refresh it
8484 // when the first preview is ready to be displayed.
85− property bool needsInit: true
85+ property bool init: true
8686
8787 PreviewDelegateMapper {
8888 id: previewDelegateMapper
8989 }
9090
91− onCurrentIndexChanged: {
92− if (needsInit) {
91+ onCurrentIndexChanged: positionListView();
92+
93+ function positionListView() {
94+ if (!open) {
9395 return;
9496 }
9597
@@ -98,11 +100,9 @@ Item {
98100 categoryView.expandedCategoryId = categoryId
99101 }
100102
101− if (open) {
102− categoryDelegate.highlightIndex = currentIndex
103− }
103+ categoryDelegate.highlightIndex = currentIndex
104104
105− if (model !== undefined) {
105+ if (!init && model !== undefined) {
106106 var item = model.get(currentIndex)
107107 scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
108108 }
@@ -141,6 +141,7 @@ Item {
141141 onScreen = true;
142142 categoryDelegate.highlightIndex = currentIndex;
143143 pageHeader.unfocus();
144+ positionListView();
144145 } else {
145146 // Cancel any pending preview requests or actions
146147 if (previewListView.currentItem.previewData !== undefined) {
tests/mocks/Unity/fake_scope.cpp+4−4
@@ -36,9 +36,9 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
3636 , m_visible(visible)
3737 , m_searching(false)
3838 , m_isActive(false)
39+ , m_previewRendererName("preview-generic")
3940 , m_categories(new Categories(this))
4041 , m_results(new DeeListModel(this))
41− , m_previewRendererName("preview-generic")
4242{
4343 DeeModel* results_model = create_results_model(20, 300);
4444 m_categories->setResultModel(results_model);
@@ -155,7 +155,6 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
155155 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
156156 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
157157{
158− Q_UNUSED(uri);
159158 Q_UNUSED(icon_hint);
160159 Q_UNUSED(category);
161160 Q_UNUSED(result_type);
@@ -165,7 +164,8 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
165164 Q_UNUSED(dnd_uri);
166165 Q_UNUSED(metadata);
167166
168− m_timer.start();
167+ if (uri != "uri://result.2")
168+ m_timer.start();
169169}
170170
171171void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
@@ -202,7 +202,7 @@ DeeModel* create_categories_model(unsigned category_count) {
202202 for(unsigned i = 0; i < category_count; ++i)
203203 {
204204 dee_model_append(category_model,
205− std::to_string(i).c_str(),
205+ (i == 2) ? "installed" : std::to_string(i).c_str(),
206206 ("Category "+std::to_string(i)).c_str(),
207207 "gtk-apply",
208208 i % 2 == 0 ? "grid" : "carousel",
tests/mocks/Unity/fake_scopes.cpp+1−1
@@ -54,7 +54,7 @@ Scopes::~Scopes()
5454void Scopes::updateScopes()
5555{
5656 clear();
57− addScope(new Scope("MockScope1", "People", true, this));
57+ addScope(new Scope("applications.scope", "People", true, this));
5858 addScope(new Scope("MockScope2", "Music", false, this));
5959 addScope(new Scope("home.scope", "Home", true, this));
6060 addScope(new ApplicationsScope(true, this));
tests/qmltests/Dash/tst_GenericScopeView.qml+43−12
@@ -87,19 +87,26 @@ Item {
8787 tryCompare(previewListView, "open", false);
8888 }
8989
90− function openPreview() {
91− var categoryListView = findChild(genericScopeView, "categoryListView");
92− categoryListView.positionAtBeginning();
93−
90+ function openPreview(filterGridName, willOpen) {
91+ if (filterGridName === undefined)
92+ filterGridName = "0";
93+ if (willOpen === undefined)
94+ willOpen = true;
9495 tryCompareFunction(function() {
95− var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
96− return tile != undefined;
96+ var filterGrid = findChild(genericScopeView, filterGridName);
97+ console.log(filterGrid)
98+ if (filterGrid != null) {
99+ var tile = findChild(filterGrid, "delegate0");
100+ return tile != undefined;
101+ }
102+ return false;
97103 },
98104 true);
99− var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
105+ var tile = findChild(findChild(genericScopeView, filterGridName), "delegate0");
106+ console.log(tile, tile.x, tile.y, tile.width, tile.height)
100107 mouseClick(tile, tile.width / 2, tile.height / 2);
101− tryCompare(previewListView, "open", true);
102− tryCompare(openEffect, "gap", 1);
108+ tryCompare(previewListView, "open", willOpen);
109+ tryCompare(openEffect, "gap", willOpen ? 1 : 0);
103110 }
104111
105112 function checkArrowPosition(index) {
@@ -129,6 +136,8 @@ Item {
129136
130137 function test_previewOpenClose() {
131138 tryCompare(previewListView, "open", false);
139+ var categoryListView = findChild(genericScopeView, "categoryListView");
140+ categoryListView.positionAtBeginning();
132141
133142 openPreview();
134143
@@ -168,6 +177,9 @@ Item {
168177 }
169178
170179 function test_previewCycle() {
180+ var categoryListView = findChild(genericScopeView, "categoryListView");
181+ categoryListView.positionAtBeginning();
182+
171183 tryCompare(previewListView, "open", false);
172184 tryCompare(openEffect, "gap", 0);
173185
@@ -222,8 +234,13 @@ Item {
222234 }
223235
224236 function test_show_spinner() {
237+ var categoryListView = findChild(genericScopeView, "categoryListView");
238+ waitForRendering(categoryListView);
239+ categoryListView.contentY = units.gu(13);
225240 openPreview();
226241 var previewLoader = findChild(previewListView, "previewLoader0");
242+ compare(previewLoader.source.toString().split("/").pop(), "DashPreviewPlaceholder.qml");
243+ compare(categoryListView.contentY, 0)
227244 tryCompare(previewLoader, "progress", 1.0);
228245 tryCompareFunction(function() { return previewLoader.item != undefined; }, true);
229246
@@ -295,13 +312,13 @@ Item {
295312
296313 function test_filter_expand_expand() {
297314 // wait for the item to be there
298− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader2") != undefined; }, true);
315+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeaderinstalled") != undefined; }, true);
299316
300317 var categoryListView = findChild(genericScopeView, "categoryListView");
301318 categoryListView.contentY = categoryListView.height;
302319
303− var header2 = findChild(genericScopeView, "dashSectionHeader2")
304− var category2 = findChild(genericScopeView, "dashCategory2")
320+ var header2 = findChild(genericScopeView, "dashSectionHeaderinstalled")
321+ var category2 = findChild(genericScopeView, "dashCategoryinstalled")
305322 var category2FilterGrid = category2.children[0].children[0].children[0];
306323 verify(UT.Util.isInstanceOf(category2FilterGrid, "FilterGrid"));
307324
@@ -330,6 +347,20 @@ Item {
330347 tryCompare(category2, "filtered", true);
331348 tryCompare(category2FilterGrid, "filter", true);
332349 }
350+
351+ function test_no_move_y_no_preview() {
352+ waitForRendering(genericScopeView);
353+ var categoryListView = findChild(genericScopeView, "categoryListView");
354+ waitForRendering(categoryListView);
355+ var category = findChild(genericScopeView, "dashCategoryinstalled")
356+ categoryListView.contentY = category.y;
357+ waitForRendering(categoryListView);
358+ var contentYBefore = categoryListView.contentY
359+ openPreview("installed", false); // This actually doesn't open anything because we
360+ // have code so that the item of installed
361+ // does activate instead of preview and never shows a preview
362+ compare(categoryListView.contentY, contentYBefore);
363+ }
333364 }
334365 }
335366