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
main
Noel De Martin 2024-01-11 15:33:14 +01:00
parent 2200669b0f
commit 3621bc46a5
14 changed files with 58 additions and 37 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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}`;
}
}

View File

@ -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}`;
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}