on xenial help sign in
Need to wait until loaded is true to use the count property

Approved by: Michael Zanetti

commit461352260db08a86fe0b70a3f38269811b9dd4b9 authorAlbert Astals <albert.astals@canonical.com> dateTue 16 Dec 2014, 11:03 (12 years ago) parentf0a4ab97f3c417
4 files changed+26−34
qml/Dash/DashNavigationButton.qml+10−20 tests/mocks/Unity/fake_navigation.cpp+1−1 tests/mocks/Unity/fake_scope.cpp+2−7 tests/qmltests/Dash/tst_DashContent.qml+13−6
qml/Dash/DashNavigationButton.qml+10−20
@@ -188,36 +188,26 @@ AbstractButton {
188188 visible: root.showList
189189 }
190190
191+ property bool isFirstLoad: false
191192 onScopeChanged: {
192− setNewNavigation();
193+ navigationModel.clear();
194+ isFirstLoad = true;
193195 }
194−
195196 function setNewNavigation() {
196− navigationModel.clear();
197− if (scope && scope[hasNavigation]) {
198− var navigation = getNavigation(scope[currentNavigationId]);
199− if (navigation.count > 0) {
197+ if (isFirstLoad && currentNavigation && currentNavigation.loaded) {
198+ isFirstLoad = false;
199+ if (currentNavigation.count > 0) {
200200 navigationModel.append({"navigationId": scope[currentNavigationId], "nullifyNavigation": false});
201201 } else {
202− navigationModel.append({"navigationId": navigation.parentNavigationId, "nullifyNavigation": false});
202+ navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
203203 }
204204 }
205205 }
206−
207206 Connections {
208− target: scope
209− // This is duplicated since we can't have something based on the dynamic hasNavigation string property
210− onHasNavigationChanged: {
211− if (!root.isAltNavigation) {
212− setNewNavigation();
213− }
214− }
215− onHasAltNavigationChanged: {
216− if (root.isAltNavigation) {
217− setNewNavigation();
218− }
219− }
207+ target: currentNavigation
208+ onLoadedChanged: setNewNavigation();
220209 }
210+ onCurrentNavigationChanged: setNewNavigation();
221211
222212 InverseMouseArea {
223213 anchors.fill: navigationListView
tests/mocks/Unity/fake_navigation.cpp+1−1
@@ -88,7 +88,7 @@ bool Navigation::hidden() const
8888
8989int Navigation::rowCount(const QModelIndex & /*parent*/) const
9090{
91− if (!m_loaded || m_navigationId.startsWith("child") || m_navigationId == "middle3")
91+ if (!m_loaded || m_navigationId.startsWith("child") || m_navigationId.startsWith("altrootChild") || m_navigationId == "middle3")
9292 return 0;
9393 else
9494 return 8;
tests/mocks/Unity/fake_scope.cpp+2−7
@@ -36,7 +36,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
3636 , m_favorite(favorite)
3737 , m_isActive(false)
3838 , m_currentNavigationId("root")
39− , m_currentAltNavigationId("altroot")
39+ , m_currentAltNavigationId("altrootChild1")
4040 , m_previewRendererName("preview-generic")
4141 , m_categories(new Categories(categories, this))
4242 , m_openScope(nullptr)
@@ -297,12 +297,7 @@ unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const
297297 parentId = "altroot";
298298 parentLabel = "altroot";
299299 }
300− auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
301− if (id == "altroot") {
302− m_currentAltNavigationId = "altrootChild1";
303− Q_EMIT currentAltNavigationIdChanged();
304− }
305− return result;
300+ return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
306301}
307302
308303void Scope::setNavigationState(const QString &navigationId, bool isAltNavigation)
tests/qmltests/Dash/tst_DashContent.qml+13−6
@@ -288,12 +288,14 @@ Item {
288288 var dashNavigationButton = findChild(dashContentList.currentItem, "navigationButton");
289289 compare(dashNavigationButton.showList, false);
290290 waitForRendering(dashNavigationButton);
291− mouseClick(dashNavigationButton, 0, 0);
291+ mouseClick(dashNavigationButton, dashNavigationButton.width / 2, dashNavigationButton.height / 2);
292292 compare(dashNavigationButton.showList, true);
293293
294294 var navigationListView = findChild(dashNavigationButton, "navigationListView");
295− compare(navigationListView.count, 1);
296− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
295+ tryCompareFunction(function() {
296+ return navigationListView.currentItem &&
297+ navigationListView.currentItem.navigation &&
298+ navigationListView.currentItem.navigation.loaded; }, true);
297299
298300 waitForRendering(navigationListView);
299301 waitForRendering(navigationListView.currentItem);
@@ -410,8 +412,10 @@ Item {
410412 compare(dashNavigationButton.showList, true);
411413
412414 var navigationListView = findChild(dashNavigationButton, "navigationListView");
413− compare(navigationListView.count, 1);
414− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
415+ tryCompareFunction(function() {
416+ return navigationListView.currentItem &&
417+ navigationListView.currentItem.navigation &&
418+ navigationListView.currentItem.navigation.loaded; }, true);
415419
416420 waitForRendering(navigationListView);
417421 waitForRendering(navigationListView.currentItem);
@@ -475,7 +479,10 @@ Item {
475479 compare(dashAltNavigationButton.showList, true);
476480
477481 var navigationListView = findChild(dashAltNavigationButton, "navigationListView");
478− tryCompare(navigationListView.currentItem.navigation, "loaded", true);
482+ tryCompareFunction(function() {
483+ return navigationListView.currentItem &&
484+ navigationListView.currentItem.navigation &&
485+ navigationListView.currentItem.navigation.loaded; }, true);
479486
480487 var blackRect = findChild(dashNavigation, "blackRect");
481488 tryCompare(blackRect, "opacity", 0.5);