on xenial help sign in
Adapt test to new mock behaviour
commit49867a5491666464e39bc821444a3d719718bb67 authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 27 Jun 2016, 18:41 (10 years ago) parenta8aaf6b8e7cd74
6 files changed+78−73
qml/Dash/ScopesList.qml+1 tests/mocks/Unity/fake_scope.cpp+6−1 tests/mocks/Unity/fake_scope.h+1 tests/qmltests/Dash/tst_Dash.qml+56−71 tests/qmltests/Dash/tst_DashContent.qml+7−1 tests/qmltests/Dash/tst_GenericScopeView.qml+7
qml/Dash/ScopesList.qml+1
@@ -72,6 +72,7 @@ Item {
7272 }
7373
7474 Flickable {
75+ objectName: "scopesListFlickable"
7576 anchors {
7677 top: header.bottom
7778 bottom: parent.bottom
tests/mocks/Unity/fake_scope.cpp+6−1
@@ -39,6 +39,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
3939 , m_searching(false)
4040 , m_favorite(favorite)
4141 , m_isActive(false)
42+ , m_hasBeenActive(false)
4243 , m_hasNavigation(true)
4344 , m_hasPrimaryFilter(true)
4445 , m_currentNavigationId("root")
@@ -108,7 +109,7 @@ bool Scope::favorite() const
108109
109110unity::shell::scopes::CategoriesInterface* Scope::categories() const
110111{
111− return m_categories;
112+ return m_hasBeenActive ? m_categories : nullptr;
112113}
113114
114115unity::shell::scopes::SettingsModelInterface* Scope::settings() const
@@ -153,6 +154,10 @@ void Scope::setActive(const bool active)
153154 m_isActive = active;
154155 Q_EMIT isActiveChanged();
155156 }
157+ if (active && !m_hasBeenActive) {
158+ m_hasBeenActive = true;
159+ Q_EMIT categoriesChanged();
160+ }
156161}
157162
158163void Scope::setFavorite(const bool favorite)
tests/mocks/Unity/fake_scope.h+1
@@ -109,6 +109,7 @@ protected:
109109 bool m_searching;
110110 bool m_favorite;
111111 bool m_isActive;
112+ bool m_hasBeenActive;
112113 bool m_hasNavigation;
113114 bool m_hasPrimaryFilter;
114115 QString m_currentNavigationId;
tests/qmltests/Dash/tst_Dash.qml+56−71
@@ -112,6 +112,19 @@ Item {
112112 mouseClick(tile);
113113 }
114114
115+ function open_manage_dash() {
116+ // Show the manage dash
117+ touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
118+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
119+ tryCompare(bottomEdgeController, "progress", 1);
120+
121+ // Make sure stuff is loaded
122+ var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
123+ var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
124+ waitForRendering(favScopesListCategoryList);
125+ tryCompare(favScopesListCategoryList, "currentIndex", 0);
126+ }
127+
115128 function test_longNavigationFilterList() {
116129 // Select the scope with long navigation
117130 dash.setCurrentScope("LongPrimaryNavigation")
@@ -121,6 +134,7 @@ Item {
121134 var dashContentList = findChild(dashContent, "dashContentList")
122135 var searchButton = findChild(dashContentList.currentItem, "search_button")
123136 var extraPanel = findChild(dashContentList.currentItem, "peExtraPanel")
137+ waitForRendering(extraPanel);
124138 tryCompare(extraPanel, "visible", false)
125139
126140 // Open the primaryNavigationFilter
@@ -179,22 +193,16 @@ Item {
179193 }
180194
181195 function test_manage_dash_clickscope_unfavoritable() {
182− // Show the manage dash
183− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
184− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
185− tryCompare(bottomEdgeController, "progress", 1);
186−
187− // Make sure stuff is loaded
188− var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
189− var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
190− tryCompare(favScopesListCategoryList, "currentIndex", 0);
196+ open_manage_dash();
191197
192198 // Click scope star area is not visible (i.e. can't be unfavorited)
199+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
193200 var clickScope = findChild(favScopesListCategoryList, "delegateclickscope");
194201 var starArea = findChild(clickScope, "starArea");
195202 compare(starArea.visible, false);
196203
197204 // Go back
205+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
198206 var scopesList = findChild(dash, "scopesList");
199207 var scopesListPageHeader = findChild(scopesList, "pageHeader");
200208 var backButton = findChild(scopesListPageHeader, "innerPageHeader").leadingActionBar;
@@ -203,20 +211,14 @@ Item {
203211 }
204212
205213 function test_manage_dash_select_same_favorite() {
206− // Show the manage dash
207− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
208− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
209− tryCompare(bottomEdgeController, "progress", 1);
210−
211− // Make sure stuff is loaded
212− var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
213− var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
214− tryCompare(favScopesListCategoryList, "currentIndex", 0);
214+ open_manage_dash();
215215
216216 // Click in first item
217+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
217218 mouseClick(favScopesListCategoryList.currentItem);
218219
219220 // Make sure animation went back
221+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
220222 tryCompare(bottomEdgeController, "progress", 0);
221223
222224 var dashContentList = findChild(dash, "dashContentList");
@@ -224,31 +226,25 @@ Item {
224226 }
225227
226228 function test_manage_dash_select_different_favorite() {
227− // Show the manage dash
228− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
229− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
230− tryCompare(bottomEdgeController, "progress", 1);
231−
232− // Make sure stuff is loaded
233− var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
234− var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
235− tryCompare(favScopesListCategoryList, "currentIndex", 0);
229+ open_manage_dash();
236230
237231 // Click in second item
232+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
238233 favScopesListCategoryList.currentIndex = 1;
239234 mouseClick(favScopesListCategoryList.currentItem);
240235
241236 // Make sure animation went back
237+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
242238 tryCompare(bottomEdgeController, "progress", 0);
243239 var dashContentList = findChild(dash, "dashContentList");
244240 compare(dashContentList.currentIndex, 1);
245241 }
246242
247243 function test_manage_dash_select_non_favorite() {
248− // Show the manage dash
249− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
250− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
251− tryCompare(bottomEdgeController, "progress", 1);
244+ open_manage_dash();
245+
246+ // Ensure non favorites are visible
247+ flickToYEnd(findChild(dash,"scopesListFlickable"));
252248
253249 // Make sure stuff is loaded
254250 var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
@@ -268,6 +264,7 @@ Item {
268264 tryCompare(dashTempScopeItem, "visible", true);
269265
270266 // Check the manage dash is gone
267+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
271268 tryCompare(bottomEdgeController, "progress", 0);
272269
273270 // Go back
@@ -296,6 +293,7 @@ Item {
296293 tryCompare(bottomEdgeController, "progress", 1);
297294
298295 // Go back
296+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
299297 var scopesList = findChild(dash, "scopesList");
300298 var scopesListPageHeader = findChild(scopesList, "pageHeader");
301299 var backButton = findChild(scopesListPageHeader, "innerPageHeader").leadingActionBar;
@@ -358,10 +356,7 @@ Item {
358356 }
359357
360358 function test_manage_dash_store_no_favorites() {
361− // Show the manage dash
362− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
363− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
364− tryCompare(bottomEdgeController, "progress", 1);
359+ open_manage_dash();
365360
366361 // clear the favorite scopes
367362 scopes.clearFavorites();
@@ -379,6 +374,7 @@ Item {
379374
380375 spy.wait();
381376 compare(spy.signalArguments[0][0], "scope://com.canonical.scopes.clickstore");
377+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
382378 tryCompare(bottomEdgeController, "progress", 0);
383379 }
384380
@@ -387,17 +383,10 @@ Item {
387383 compare(dashContentList.currentIndex, 0);
388384 compare(dashContentList.currentItem.scopeId, "MockScope1");
389385
390− // Show the manage dash
391− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
392− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
393− tryCompare(bottomEdgeController, "progress", 1);
394−
395− // Make sure stuff is loaded
396− var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
397− var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
398− tryCompare(favScopesListCategoryList, "currentIndex", 0);
386+ open_manage_dash();
399387
400388 // Enter edit mode
389+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
401390 var scopesList = findChild(dash, "scopesList");
402391 var clickScope = findChild(favScopesListCategoryList, "delegateclickscope");
403392 mousePress(clickScope);
@@ -408,6 +397,7 @@ Item {
408397 touchFlick(starArea, 0, 0, 0, -units.gu(10));
409398
410399 // Exit edit mode and go back
400+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
411401 var scopesList = findChild(dash, "scopesList");
412402 var scopesListPageHeader = findChild(scopesList, "pageHeader");
413403 var backButton = findChild(scopesListPageHeader, "innerPageHeader").leadingActionBar;
@@ -429,17 +419,10 @@ Item {
429419 compare(dashContentList.currentIndex, 0);
430420 compare(dashContentList.currentItem.scopeId, "MockScope1");
431421
432− // Show the manage dash
433− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
434− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
435− tryCompare(bottomEdgeController, "progress", 1);
436−
437− // Make sure stuff is loaded
438− var favScopesListCategory = findChild(dash, "scopesListCategoryfavorites");
439− var favScopesListCategoryList = findChild(favScopesListCategory, "scopesListCategoryInnerList");
440− tryCompare(favScopesListCategoryList, "currentIndex", 0);
422+ open_manage_dash();
441423
442424 // Enter edit mode
425+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
443426 var scopesList = findChild(dash, "scopesList");
444427 var clickScope = findChild(favScopesListCategoryList, "delegateclickscope");
445428 mousePress(clickScope);
@@ -459,6 +442,8 @@ Item {
459442 mouseClick(backButton);
460443
461444 // Click on third scope
445+ var favScopesListCategoryList = findChild(findChild(dash, "scopesListCategoryfavorites"), "scopesListCategoryInnerList");
446+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
462447 var mockScope5 = findChild(favScopesListCategoryList, "delegateMockScope5");
463448 waitForRendering(mockScope5)
464449 mouseClick(mockScope5);
@@ -472,14 +457,12 @@ Item {
472457 compare(dashContentList.currentIndex, 0);
473458 compare(dashContentList.currentItem.scopeId, "MockScope1");
474459
475− // Show the manage dash
476− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
477− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
478− tryCompare(bottomEdgeController, "progress", 1);
460+ open_manage_dash();
479461
480462 var dashCommunicatorService = findInvisibleChild(dash, "dashCommunicatorService");
481463 dashCommunicatorService.mockSetCurrentScope(1, true, false);
482464
465+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
483466 tryCompare(bottomEdgeController, "progress", 0);
484467 tryCompare(dashContentList, "currentIndex", 1)
485468 }
@@ -507,10 +490,10 @@ Item {
507490 }
508491
509492 function test_close_temp_scope_preview_opening_scope() {
510− // Show the manage dash
511− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
512− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
513− tryCompare(bottomEdgeController, "progress", 1);
493+ open_manage_dash();
494+
495+ // Ensure non favorite scopes are visible
496+ flickToYEnd(findChild(dash, "scopesListFlickable"));
514497
515498 // Make sure stuff is loaded
516499 var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
@@ -530,6 +513,7 @@ Item {
530513 tryCompare(dashTempScopeItem, "visible", true);
531514
532515 // Check the manage dash is gone
516+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
533517 tryCompare(bottomEdgeController, "progress", 0);
534518
535519 // Open preview
@@ -580,12 +564,10 @@ Item {
580564 UriHandler.opened("scopes://clickscope");
581565 tryCompare(dashContentList, "currentIndex", 1);
582566
583− // Show the manage dash
584− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
585− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
586− tryCompare(bottomEdgeController, "progress", 1);
567+ open_manage_dash();
587568
588569 // UriHandler changes to a scope and closes the manage scopes
570+ var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
589571 UriHandler.opened("scopes://MockScope1");
590572 tryCompare(dashContentList, "currentIndex", 0);
591573 tryCompare(bottomEdgeController, "progress", 0);
@@ -603,11 +585,11 @@ Item {
603585 tryCompare(dashContent, "subPageShown", false);
604586
605587 // Go to a temp scope
606− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
607− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
608− tryCompare(bottomEdgeController, "progress", 1);
588+ open_manage_dash();
589+
609590 var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
610591 var nonfavScopesListCategoryList = findChild(nonfavScopesListCategory, "scopesListCategoryInnerList");
592+ flickToYEnd(findChild(dash, "scopesListFlickable"));
611593 tryCompare(nonfavScopesListCategoryList, "currentIndex", 0);
612594 mouseClick(nonfavScopesListCategoryList.currentItem);
613595 var dashTempScopeItem = findChild(dash, "dashTempScopeItem");
@@ -666,12 +648,15 @@ Item {
666648 function test_tempScopeItemXOnResize()
667649 {
668650 // Go to a temp scope
669− touchFlick(dash, dash.width / 2, dash.height - 1, dash.width / 2, units.gu(2));
670− var bottomEdgeController = findInvisibleChild(dash, "bottomEdgeController");
671− tryCompare(bottomEdgeController, "progress", 1);
651+ open_manage_dash();
652+
672653 var nonfavScopesListCategory = findChild(dash, "scopesListCategoryother");
673654 var nonfavScopesListCategoryList = findChild(nonfavScopesListCategory, "scopesListCategoryInnerList");
655+ var scopesListFlickable = findChild(dash, "scopesListFlickable");
674656 tryCompare(nonfavScopesListCategoryList, "currentIndex", 0);
657+
658+ // Ensure the non-favorites, located at the bottom, are visible
659+ flickToYEnd(scopesListFlickable);
675660 mouseClick(nonfavScopesListCategoryList.currentItem);
676661 var dashTempScopeItem = findChild(dash, "dashTempScopeItem");
677662 tryCompare(dashTempScopeItem, "x", 0);
tests/qmltests/Dash/tst_DashContent.qml+7−1
@@ -70,7 +70,7 @@ Item {
7070 function loadScopes() {
7171 scopeLoadedSpy.clear();
7272 scopesModel.load();
73− tryCompare(scopeLoadedSpy, "count", 6, 15000);
73+ tryCompare(scopeLoadedSpy, "count", 8, 15000);
7474 tryCompare(scopesModel, "loaded", true);
7575 tryCompareFunction(function() {
7676 var mockScope1Loader = findChild(shell, "scopeLoader0");
@@ -610,6 +610,12 @@ Item {
610610 }
611611
612612 function test_noDelegateCreationDestructionOnMove() {
613+ // Go to scope 1 and back so that items are created
614+ // and so this test makes sense
615+ dashContent.setCurrentScopeAtIndex(1);
616+ waitForRendering(dashContent);
617+ dashContent.setCurrentScopeAtIndex(0);
618+
613619 // Our cards are of type AbstractButton as defined in CardCreator.js
614620 // This gives also other things that are not cards but for our purpose it
615621 // does not matter
tests/qmltests/Dash/tst_GenericScopeView.qml+7
@@ -76,6 +76,7 @@ Item {
7676 tryCompare(scopes, "loaded", true);
7777
7878 genericScopeView.scope = scopes.getScope(2);
79+ genericScopeView.isCurrent = true;
7980 shell.width = units.gu(120);
8081 genericScopeView.categoryView.positionAtBeginning();
8182 waitForRendering(genericScopeView.categoryView);
@@ -116,6 +117,7 @@ Item {
116117 }
117118
118119 function test_isActive() {
120+ genericScopeView.isCurrent = false
119121 tryCompare(genericScopeView.scope, "isActive", false)
120122 genericScopeView.isCurrent = true
121123 tryCompare(genericScopeView.scope, "isActive", true)
@@ -140,6 +142,7 @@ Item {
140142 }
141143
142144 function test_searchQuery() {
145+ genericScopeView.isCurrent = false
143146 genericScopeView.scope = scopes.getScope(0);
144147 genericScopeView.scope.searchQuery = "test";
145148 genericScopeView.scope = scopes.getScope(1);
@@ -151,6 +154,7 @@ Item {
151154 }
152155
153156 function test_changeScope() {
157+ genericScopeView.isCurrent = false;
154158 genericScopeView.scope.searchQuery = "test"
155159 var originalScopeId = genericScopeView.scope.id;
156160 genericScopeView.scope = scopes.getScope(originalScopeId + 1)
@@ -458,6 +462,7 @@ Item {
458462 function test_seeAllTwoCategoriesScenario1() {
459463 mockScope.setId("mockScope");
460464 mockScope.setName("Mock Scope");
465+ mockScope.isActive = true;
461466 mockScope.categories.setCount(2);
462467 mockScope.categories.resultModel(0).setResultCount(50);
463468 mockScope.categories.resultModel(1).setResultCount(25);
@@ -501,6 +506,7 @@ Item {
501506 function test_seeAllTwoCategoriesScenario2() {
502507 mockScope.setId("mockScope");
503508 mockScope.setName("Mock Scope");
509+ mockScope.isActive = true;
504510 mockScope.categories.setCount(2);
505511 mockScope.categories.resultModel(0).setResultCount(25);
506512 mockScope.categories.resultModel(1).setResultCount(50);
@@ -629,6 +635,7 @@ Item {
629635 var category0 = findChild(categoryListView, "dashCategory0");
630636 waitForRendering(category0);
631637
638+ tryCompareFunction(function() { return category0.item != null; }, true);
632639 var cardGrid = category0.item;
633640 compare(cardGrid.cardTool.template["non-interactive"], true);
634641