From 3621bc46a5b743ca9f29ef4760a8fd41c27e0728 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 11 Jan 2024 15:33:14 +0100 Subject: [PATCH] MOBILE-3947 glossary: Fix tests There were some bugs in Angular v10 that countered this bug in our code, that's why it wasn't manifested until now. It seems to be related with the changes in createUrlTreeFromSegmentGroup. See https://github.com/angular/angular/commits/16.0.x/packages/router/src/create_url_tree.ts?since=2020-06-25&until=2024-01-11 --- src/addons/calendar/pages/event/event.ts | 6 ++++-- .../pages/competency/competency.page.ts | 8 +++++--- .../pages/submission-review/submission-review.ts | 6 ++++-- src/addons/mod/feedback/pages/attempt/attempt.ts | 8 +++++--- .../mod/forum/pages/discussion/discussion.ts | 6 ++++-- .../forum/pages/new-discussion/new-discussion.ts | 6 ++++-- src/addons/mod/glossary/pages/entry/entry.ts | 6 ++++-- .../mod/glossary/tests/behat/navigation.feature | 1 - .../pages/notification/notification.ts | 8 +++++--- .../items-management/list-items-manager.ts | 6 ++++-- .../items-management/routed-items-manager.ts | 16 +++++++--------- .../swipe-navigation-items-manager.ts | 6 ++++-- .../features/grades/pages/course/course.page.ts | 6 ++++-- src/core/features/user/pages/profile/profile.ts | 6 ++++-- 14 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/addons/calendar/pages/event/event.ts b/src/addons/calendar/pages/event/event.ts index 3aedbbeb8..27e64a067 100644 --- a/src/addons/calendar/pages/event/event.ts +++ b/src/addons/calendar/pages/event/event.ts @@ -639,8 +639,10 @@ class AddonCalendarEventsSwipeItemsManager extends CoreSwipeNavigationItemsManag /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.id; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.id; } } diff --git a/src/addons/competency/pages/competency/competency.page.ts b/src/addons/competency/pages/competency/competency.page.ts index 9431a03e9..8273d4428 100644 --- a/src/addons/competency/pages/competency/competency.page.ts +++ b/src/addons/competency/pages/competency/competency.page.ts @@ -36,7 +36,7 @@ import { ADDON_COMPETENCY_SUMMARY_PAGE } from '@addons/competency/competency.mod import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { AddonCompetencyPlanCompetenciesSource } from '@addons/competency/classes/competency-plan-competencies-source'; -import { ActivatedRouteSnapshot } from '@angular/router'; +import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { AddonCompetencyCourseCompetenciesSource } from '@addons/competency/classes/competency-course-competencies-source'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -350,8 +350,10 @@ class AddonCompetencyCompetenciesSwipeManager /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.competencyId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.competencyId; } } diff --git a/src/addons/mod/assign/pages/submission-review/submission-review.ts b/src/addons/mod/assign/pages/submission-review/submission-review.ts index 699ff3013..0c65440a7 100644 --- a/src/addons/mod/assign/pages/submission-review/submission-review.ts +++ b/src/addons/mod/assign/pages/submission-review/submission-review.ts @@ -245,8 +245,10 @@ class AddonModAssignSubmissionSwipeItemsManager extends CoreSwipeNavigationItems /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.submitId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.submitId; } } diff --git a/src/addons/mod/feedback/pages/attempt/attempt.ts b/src/addons/mod/feedback/pages/attempt/attempt.ts index afb1241e4..58c612a2d 100644 --- a/src/addons/mod/feedback/pages/attempt/attempt.ts +++ b/src/addons/mod/feedback/pages/attempt/attempt.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, OnDestroy, OnInit } from '@angular/core'; -import { ActivatedRouteSnapshot } from '@angular/router'; +import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; import { CoreNavigator } from '@services/navigator'; @@ -187,8 +187,10 @@ class AddonModFeedbackAttemptsSwipeManager extends CoreSwipeNavigationItemsManag /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.attemptId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.attemptId; } } diff --git a/src/addons/mod/forum/pages/discussion/discussion.ts b/src/addons/mod/forum/pages/discussion/discussion.ts index 0779c78fa..bf0f77308 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.ts @@ -893,8 +893,10 @@ class AddonModForumDiscussionDiscussionsSwipeManager extends AddonModForumDiscus /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return this.getSource().DISCUSSIONS_PATH_PREFIX + route.params.discussionId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return this.getSource().DISCUSSIONS_PATH_PREFIX + snapshot.params.discussionId; } } diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts index 8dc2a1563..052397773 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts @@ -699,8 +699,10 @@ class AddonModForumNewDiscussionDiscussionsSwipeManager extends AddonModForumDis /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return `${this.getSource().DISCUSSIONS_PATH_PREFIX}new/${route.params.timeCreated}`; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return `${this.getSource().DISCUSSIONS_PATH_PREFIX}new/${snapshot.params.timeCreated}`; } } diff --git a/src/addons/mod/glossary/pages/entry/entry.ts b/src/addons/mod/glossary/pages/entry/entry.ts index cc15c5dcb..3160c1818 100644 --- a/src/addons/mod/glossary/pages/entry/entry.ts +++ b/src/addons/mod/glossary/pages/entry/entry.ts @@ -367,8 +367,10 @@ class AddonModGlossaryEntryEntriesSwipeManager /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return `${this.getSource().GLOSSARY_PATH_PREFIX}entry/${route.params.entrySlug}`; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return `${this.getSource().GLOSSARY_PATH_PREFIX}entry/${snapshot.params.entrySlug}`; } } diff --git a/src/addons/mod/glossary/tests/behat/navigation.feature b/src/addons/mod/glossary/tests/behat/navigation.feature index fb6ac072b..855640abb 100644 --- a/src/addons/mod/glossary/tests/behat/navigation.feature +++ b/src/addons/mod/glossary/tests/behat/navigation.feature @@ -211,7 +211,6 @@ Feature: Test glossary navigation And I should find "Cashew" in the app And I should find "Acerola" in the app - @ci_jenkins_skip @ionic7_failure Scenario: Tablet navigation on glossary Given I entered the course "Course 1" as "student1" in the app And I change viewport size to "1200x640" in the app diff --git a/src/addons/notifications/pages/notification/notification.ts b/src/addons/notifications/pages/notification/notification.ts index a8f6258df..79e674175 100644 --- a/src/addons/notifications/pages/notification/notification.ts +++ b/src/addons/notifications/pages/notification/notification.ts @@ -20,7 +20,7 @@ import { AddonNotificationsHelper, } from '@addons/notifications/services/notifications-helper'; import { Component, OnDestroy, OnInit } from '@angular/core'; -import { ActivatedRouteSnapshot } from '@angular/router'; +import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; import { CoreContentLinksAction, CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; @@ -211,8 +211,10 @@ class AddonNotificationSwipeItemsManager extends CoreSwipeNavigationItemsManager /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.id; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.id; } } diff --git a/src/core/classes/items-management/list-items-manager.ts b/src/core/classes/items-management/list-items-manager.ts index 3ec31d484..035d0b845 100644 --- a/src/core/classes/items-management/list-items-manager.ts +++ b/src/core/classes/items-management/list-items-manager.ts @@ -239,13 +239,15 @@ export class CoreListItemsManager< /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { const segments: UrlSegment[] = []; while (route.firstChild) { route = route.firstChild; - segments.push(...route.url); + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + segments.push(...snapshot.url); } return segments.map(segment => segment.path).join('/').replace(/\/+/, '/').trim() || null; diff --git a/src/core/classes/items-management/routed-items-manager.ts b/src/core/classes/items-management/routed-items-manager.ts index a2e8bf514..c873b81f9 100644 --- a/src/core/classes/items-management/routed-items-manager.ts +++ b/src/core/classes/items-management/routed-items-manager.ts @@ -55,7 +55,7 @@ export abstract class CoreRoutedItemsManager< * @param route Page route. * @returns Path of the selected item in the given route. */ - protected abstract getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null; + protected abstract getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null; /** * Get the path of the selected item. @@ -63,7 +63,7 @@ export abstract class CoreRoutedItemsManager< * @param route Page route, if any. * @returns Path of the selected item. */ - protected getSelectedItemPath(route?: ActivatedRouteSnapshot | null): string | null { + protected getSelectedItemPath(route?: ActivatedRouteSnapshot | ActivatedRoute | null): string | null { if (!route) { return null; } @@ -76,14 +76,12 @@ export abstract class CoreRoutedItemsManager< * * @param route Current route. */ - protected updateSelectedItem(route: ActivatedRouteSnapshot | null = null): void { - route = route ?? this.getCurrentPageRoute()?.snapshot ?? null; + protected updateSelectedItem(route: ActivatedRouteSnapshot | ActivatedRoute | null = null): void { + route = route ?? this.getCurrentPageRoute() ?? null; const selectedItemPath = this.getSelectedItemPath(route); + const selectedItem = selectedItemPath ? (this.itemsMap?.[selectedItemPath] ?? null) : null; - const selectedItem = selectedItemPath - ? this.itemsMap?.[selectedItemPath] ?? null - : null; this.setSelectedItem(selectedItem); } @@ -106,7 +104,7 @@ export abstract class CoreRoutedItemsManager< // If this item is already selected, do nothing. const itemPath = this.getSource().getItemPath(item); - const selectedItemPath = this.getSelectedItemPath(route.snapshot); + const selectedItemPath = this.getSelectedItemPath(route); if (selectedItemPath === itemPath) { return; @@ -135,7 +133,7 @@ export abstract class CoreRoutedItemsManager< } // If the current page is already the index, do nothing. - const selectedItemPath = this.getSelectedItemPath(route.snapshot); + const selectedItemPath = this.getSelectedItemPath(route); if (selectedItemPath === null) { return; diff --git a/src/core/classes/items-management/swipe-navigation-items-manager.ts b/src/core/classes/items-management/swipe-navigation-items-manager.ts index f0be57a0c..71e9cb201 100644 --- a/src/core/classes/items-management/swipe-navigation-items-manager.ts +++ b/src/core/classes/items-management/swipe-navigation-items-manager.ts @@ -81,11 +81,13 @@ export class CoreSwipeNavigationItemsManager< /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { const segments: UrlSegment[] = []; while (route) { - segments.push(...route.url); + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + segments.push(...snapshot.url); if (!route.firstChild) { break; diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index 40d8d4ee4..a715394c3 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -330,8 +330,10 @@ class CoreGradesCourseParticipantsSwipeManager extends CoreSwipeNavigationItemsM /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.userId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.userId; } } diff --git a/src/core/features/user/pages/profile/profile.ts b/src/core/features/user/pages/profile/profile.ts index e056c0acd..64d97ed6a 100644 --- a/src/core/features/user/pages/profile/profile.ts +++ b/src/core/features/user/pages/profile/profile.ts @@ -253,8 +253,10 @@ class CoreUserSwipeItemsManager extends CoreSwipeNavigationItemsManager { /** * @inheritdoc */ - protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null { - return route.params.userId; + protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot | ActivatedRoute): string | null { + const snapshot = route instanceof ActivatedRouteSnapshot ? route : route.snapshot; + + return snapshot.params.userId; } }