diff --git a/projects/v3/src/app/app-routing.module.ts b/projects/v3/src/app/app-routing.module.ts
index 60bf2d14f..d1b304216 100644
--- a/projects/v3/src/app/app-routing.module.ts
+++ b/projects/v3/src/app/app-routing.module.ts
@@ -10,6 +10,7 @@ const routes: Routes = [
},
{
path: 'experiences',
+ title: 'Experiences - Practera',
loadChildren: () => import('./pages/experiences/experiences.module').then(m => m.ExperiencesPageModule),
canLoad: [AuthGuard],
},
diff --git a/projects/v3/src/app/pages/notifications/notifications.page.html b/projects/v3/src/app/pages/notifications/notifications.page.html
index 708743a63..863193612 100644
--- a/projects/v3/src/app/pages/notifications/notifications.page.html
+++ b/projects/v3/src/app/pages/notifications/notifications.page.html
@@ -3,13 +3,13 @@
Notifications
@if (mode === 'modal') {
-
+
}
@if (!mode) {
-
+
}
diff --git a/projects/v3/src/app/pages/notifications/notifications.page.spec.ts b/projects/v3/src/app/pages/notifications/notifications.page.spec.ts
index 0f7c8d9fa..cb5c5ba34 100644
--- a/projects/v3/src/app/pages/notifications/notifications.page.spec.ts
+++ b/projects/v3/src/app/pages/notifications/notifications.page.spec.ts
@@ -1,5 +1,5 @@
import { ComponentFixture, fakeAsync, flushMicrotasks, TestBed, waitForAsync } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { DefaultUrlSerializer, Router } from '@angular/router';
import { UtilsService } from '@v3/services/utils.service';
import { IonicModule, ModalController } from '@ionic/angular/lazy';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -12,6 +12,7 @@ import { NotificationsPage } from './notifications.page';
import { of } from 'rxjs';
import { MockRouter } from '@testingv3/mocked.service';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
+import { Title } from '@angular/platform-browser';
describe('NotificationsPage', () => {
let component: NotificationsPage;
@@ -50,13 +51,6 @@ describe('NotificationsPage', () => {
provide: Router,
useClass: MockRouter
},
- {
- provide: ModalController,
- useValue: jasmine.createSpyObj('ModalController', {
- 'dismiss': Promise.resolve(),
- 'getTop': Promise.resolve(true),
- }),
- },
{
provide: HomeService,
useValue: jasmine.createSpyObj('HomeService', ['getMilestones'], {
@@ -76,7 +70,14 @@ describe('NotificationsPage', () => {
component = fixture.componentInstance;
routerSpy = TestBed.inject(Router);
utilsSpy = TestBed.inject(UtilsService);
- modalSpy = TestBed.inject(ModalController);
+ modalSpy = jasmine.createSpyObj('ModalController', {
+ dismiss: Promise.resolve(true),
+ getTop: Promise.resolve(true),
+ });
+ (component as any).modalController = modalSpy;
+ (routerSpy as any).lastSuccessfulNavigation = () => null;
+ (routerSpy as any).parseUrl = (url: string) => new DefaultUrlSerializer().parse(url);
+ (routerSpy as any).navigateByUrl = jasmine.createSpy('navigateByUrl').and.returnValue(Promise.resolve(true));
notificationSpy = TestBed.inject(NotificationsService);
// reconfigure getTop to return truthy (global test.ts override sets it to null)
@@ -90,6 +91,37 @@ describe('NotificationsPage', () => {
});
describe('ngOnInit()', () => {
+ for (const title of ['Local Test Experience', 'Events - Practera', 'Peer feedback']) {
+ it(`preserves ${title} when Notifications is a drawer`, () => {
+ const titleService = TestBed.inject(Title);
+ const originalTitle = titleService.getTitle();
+ (utilsSpy.setPageTitle as jasmine.Spy).and.callFake(value => titleService.setTitle(value));
+ titleService.setTitle(title);
+ component.mode = 'modal';
+ try {
+ component.ngOnInit();
+ expect(titleService.getTitle()).toBe(title);
+ component.ngOnDestroy();
+ expect(titleService.getTitle()).toBe(title);
+ } finally {
+ titleService.setTitle(originalTitle);
+ }
+ });
+ }
+
+ it('uses the Notifications title for a routed page', () => {
+ const titleService = TestBed.inject(Title);
+ const originalTitle = titleService.getTitle();
+ (utilsSpy.setPageTitle as jasmine.Spy).and.callFake(value => titleService.setTitle(value));
+ try {
+ titleService.setTitle('Events - Practera');
+ component.ngOnInit();
+ expect(titleService.getTitle()).toBe('Notifications - Practera');
+ } finally {
+ titleService.setTitle(originalTitle);
+ }
+ });
+
it('should initiate subscriptions', () => {
utilsSpy.isEmpty = jasmine.createSpy('isEmpty').and.returnValue(false);
component.ngOnInit();
@@ -244,11 +276,86 @@ describe('NotificationsPage', () => {
describe('goBack()', () => {
it('should dismiss notification modal', () => {
+ component.mode = 'modal';
utilsSpy.isMobile = jasmine.createSpy('isMobile').and.returnValue(false);
component.goBack();
expect(modalSpy.dismiss).toHaveBeenCalled();
});
+
+ for (const mobile of [false, true]) {
+ it(`returns a direct Notifications page to Home (mobile=${mobile})`, async () => {
+ utilsSpy.isMobile = jasmine.createSpy('isMobile').and.returnValue(mobile);
+ component.window = { history: { length: 1, back: jasmine.createSpy('back') } };
+ await component.goBack();
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'home'], { replaceUrl: true });
+ expect(modalSpy.dismiss).not.toHaveBeenCalled();
+ expect(component.window.history.back).not.toHaveBeenCalled();
+ });
+
+ it(`returns to the recorded in-app destination (mobile=${mobile})`, async () => {
+ utilsSpy.isMobile = jasmine.createSpy('isMobile').and.returnValue(mobile);
+ (routerSpy as any).lastSuccessfulNavigation = () => ({ previousNavigation: { id: 1 } });
+ component.window = { history: {
+ length: 2,
+ state: { notificationsReturnUrl: '/v3/activity-mobile/11?view=feedback#answer' },
+ back: jasmine.createSpy('back'),
+ } };
+ await component.goBack();
+ expect(routerSpy.navigateByUrl).toHaveBeenCalledWith('/v3/activity-mobile/11?view=feedback#answer', { replaceUrl: true });
+ expect(component.window.history.back).not.toHaveBeenCalled();
+ expect(modalSpy.dismiss).not.toHaveBeenCalled();
+ expect(routerSpy.navigate).not.toHaveBeenCalled();
+ });
+ }
+
+ it('falls back to Home if redirect navigation has no browser history entry', async () => {
+ (routerSpy as any).lastSuccessfulNavigation = () => ({ previousNavigation: { id: 1 } });
+ component.window = { history: { length: 1, back: jasmine.createSpy('back') } };
+ await component.goBack();
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'home'], { replaceUrl: true });
+ expect(component.window.history.back).not.toHaveBeenCalled();
+ });
+
+ it('does not return direct entry to unrelated browser history', async () => {
+ component.window = { history: { length: 3, back: jasmine.createSpy('back') } };
+ await component.goBack();
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'home'], { replaceUrl: true });
+ expect(component.window.history.back).not.toHaveBeenCalled();
+ });
+
+ it('returns a cached direct entry to Home even after Angular navigated elsewhere', async () => {
+ (routerSpy as any).lastSuccessfulNavigation = () => ({ previousNavigation: { id: 2 } });
+ component.window = { history: { length: 3, state: { navigationId: 3 }, back: jasmine.createSpy('back') } };
+ await component.goBack();
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'home'], { replaceUrl: true });
+ expect(component.window.history.back).not.toHaveBeenCalled();
+ });
+
+ for (const returnUrl of ['/topic-mobile/11/22', '/assessment-mobile/assessment/11/8/11', '/experiences']) {
+ it(`returns to ${returnUrl}`, async () => {
+ component.window = { history: { state: { notificationsReturnUrl: returnUrl } } };
+ await component.goBack();
+ expect(routerSpy.navigateByUrl).toHaveBeenCalledWith(returnUrl, { replaceUrl: true });
+ });
+ }
+
+ for (const returnUrl of ['https://example.com/', '//example.com/', '/v3/notifications?from=home', '/%invalid', '/auth/logout']) {
+ it(`falls back to Home for an invalid return destination: ${returnUrl}`, async () => {
+ component.window = { history: { state: { notificationsReturnUrl: returnUrl } } };
+ await component.goBack();
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'home'], { replaceUrl: true });
+ expect(routerSpy.navigateByUrl).not.toHaveBeenCalled();
+ });
+ }
+
+ it('dismisses a modal even in a mobile layout', async () => {
+ component.mode = 'modal';
+ utilsSpy.isMobile = jasmine.createSpy('isMobile').and.returnValue(true);
+ await component.goBack();
+ expect(modalSpy.dismiss).toHaveBeenCalled();
+ expect(routerSpy.navigate).not.toHaveBeenCalled();
+ });
});
describe('keyboardEvent', () => {
diff --git a/projects/v3/src/app/pages/notifications/notifications.page.ts b/projects/v3/src/app/pages/notifications/notifications.page.ts
index eb83e4498..033ece1cb 100644
--- a/projects/v3/src/app/pages/notifications/notifications.page.ts
+++ b/projects/v3/src/app/pages/notifications/notifications.page.ts
@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Component, Inject, Input, NgZone, OnDestroy, OnInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';
-import { Router } from '@angular/router';
+import { PRIMARY_OUTLET, Router } from '@angular/router';
import { NotificationsService, TodoItem } from '@v3/app/services/notifications.service';
import { UtilsService } from '@v3/app/services/utils.service';
import { trigger, transition, useAnimation } from '@angular/animations';
@@ -49,7 +49,9 @@ export class NotificationsPage implements OnInit, OnDestroy {
}
ngOnInit() {
- this.utils.setPageTitle('Notifications - Practera');
+ if (this.mode !== 'modal') {
+ this.utils.setPageTitle('Notifications - Practera');
+ }
this.subscriptions.push(this.homeService.milestones$.subscribe(async milestones => {
if (milestones === null) {
this.homeService.getMilestones();
@@ -217,9 +219,22 @@ export class NotificationsPage implements OnInit, OnDestroy {
return;
}
- if (!this.isMobile) {
+ if (this.mode === 'modal') {
return this.dismiss();
}
- return this.window.history.back();
+ const returnUrl = this.window.history.state?.notificationsReturnUrl;
+ if (typeof returnUrl === 'string' && returnUrl.startsWith('/') && !returnUrl.startsWith('//')) {
+ try {
+ const segments = this.router.parseUrl(returnUrl).root.children[PRIMARY_OUTLET]?.segments || [];
+ const root = segments[0]?.path;
+ const allowedRoot = ['v3', 'experiences', 'topic-mobile', 'assessment-mobile'].includes(root);
+ if (allowedRoot && !(root === 'v3' && segments[1]?.path === 'notifications')) {
+ return this.router.navigateByUrl(returnUrl, { replaceUrl: true });
+ }
+ } catch {
+ // Invalid or stale navigation state should still provide a way back to Home.
+ }
+ }
+ return this.router.navigate(['v3', 'home'], { replaceUrl: true });
}
}
diff --git a/projects/v3/src/app/pages/review-desktop/review-desktop.page.spec.ts b/projects/v3/src/app/pages/review-desktop/review-desktop.page.spec.ts
index 13d637ea7..c57f42682 100644
--- a/projects/v3/src/app/pages/review-desktop/review-desktop.page.spec.ts
+++ b/projects/v3/src/app/pages/review-desktop/review-desktop.page.spec.ts
@@ -1,9 +1,9 @@
-import { ActivatedRoute } from '@angular/router';
+import { ActivatedRoute, convertToParamMap, DefaultUrlSerializer, Event as RouterEvent, NavigationEnd, NavigationStart, ParamMap, Router } from '@angular/router';
import { AssessmentService } from '@v3/services/assessment.service';
import { UtilsService } from '@v3/services/utils.service';
import { NotificationsService } from '@v3/services/notifications.service';
import { ReviewService } from '@v3/app/services/review.service';
-import { of, Subject } from 'rxjs';
+import { BehaviorSubject, of, Subject } from 'rxjs';
import { ReviewDesktopPage } from './review-desktop.page';
@@ -13,16 +13,29 @@ describe('ReviewDesktopPage', () => {
let reviewService: jasmine.SpyObj;
let notificationsService: jasmine.SpyObj;
let utilsService: jasmine.SpyObj;
+ let routerEvents: Subject;
+ let routerState: { url: string; events: Subject; parseUrl: Router['parseUrl'] };
+ let routeSnapshot: { paramMap: ParamMap };
+ let reviewsSource: BehaviorSubject;
+ let originalTitle: string;
const createComponent = ({
- submissionId = 1,
+ submissionId = undefined as number | undefined,
reviews = [] as any[],
assessment = { id: 99, pulseCheck: false } as any,
submission = { id: 100, status: 'pending review' } as any,
review = { id: 101 } as any,
} = {}) => {
- const paramMap$ = new Subject();
- const params$ = new Subject();
+ const paramMap$ = new BehaviorSubject(convertToParamMap(submissionId ? { submissionId: String(submissionId) } : {}));
+ const params$ = new BehaviorSubject(submissionId ? { submissionId: String(submissionId) } : {});
+ routerEvents = new Subject();
+ routerState = {
+ url: '/v3/review-desktop',
+ events: routerEvents,
+ parseUrl: url => new DefaultUrlSerializer().parse(url),
+ };
+ routeSnapshot = { paramMap: convertToParamMap(submissionId ? { submissionId: String(submissionId) } : {}) };
+ reviewsSource = new BehaviorSubject(reviews);
assessmentService = jasmine.createSpyObj('AssessmentService', [
'getAssessment',
@@ -36,7 +49,7 @@ describe('ReviewDesktopPage', () => {
});
reviewService = jasmine.createSpyObj('ReviewService', ['getReviews'], {
- reviews$: of(reviews),
+ reviews$: reviewsSource.asObservable(),
});
notificationsService = jasmine.createSpyObj('NotificationsService', [
@@ -47,10 +60,14 @@ describe('ReviewDesktopPage', () => {
utilsService = jasmine.createSpyObj('UtilsService', ['setPageTitle', 'isEmpty']);
utilsService.isEmpty.and.callFake((value) => value === null || value === undefined || value === '');
+ utilsService.setPageTitle.and.callFake(value => {
+ document.title = UtilsService.prototype.decodeHtmlEntities.call({ document }, value);
+ });
const activatedRoute = {
paramMap: paramMap$.asObservable(),
params: params$.asObservable(),
+ snapshot: routeSnapshot,
} as ActivatedRoute;
component = new ReviewDesktopPage(
@@ -61,17 +78,143 @@ describe('ReviewDesktopPage', () => {
notificationsService,
{ markForCheck: jasmine.createSpy('markForCheck') } as any,
{ run: jasmine.createSpy('ngZoneRun').and.callFake((fn: () => any) => fn()) } as any,
+ routerState as unknown as Router,
);
component.ngOnInit();
- paramMap$.next({});
- params$.next({ submissionId });
};
beforeEach(() => {
+ originalTitle = document.title;
createComponent();
});
+ afterEach(() => {
+ component.ngOnDestroy();
+ reviewsSource.complete();
+ document.title = originalTitle;
+ });
+
+ const navigate = (url: string, pageTitle?: string) => {
+ routerState.url = url;
+ if (pageTitle) document.title = pageTitle;
+ routerEvents.next(new NavigationEnd(2, url, url));
+ };
+
+ it('restores the empty Reviews title after returning from Events', () => {
+ navigate('/v3/events', 'Events - Practera');
+ navigate('/v3/review-desktop');
+ expect(document.title).toBe('Reviews - Practera');
+ });
+
+ for (const url of [
+ '/v3/review-desktop',
+ '/v3/review-desktop?view=details',
+ '/v3/review-desktop/33;view=details?tab=feedback#answer',
+ '/v3/review-desktop;view=details',
+ ]) {
+ it(`restores the selected review title on return to ${url}`, () => {
+ if (url.startsWith('/v3/review-desktop/33')) {
+ routeSnapshot.paramMap = convertToParamMap({ submissionId: '33' });
+ component.submissionId = 33;
+ }
+ component.goto({ assessmentId: 11, contextId: 22, submissionId: 33, name: 'Peer & feedback' } as any);
+ navigate('/v3/events', 'Events - Practera');
+ navigate(url);
+ expect(document.title).toBe('Peer & feedback');
+ });
+ }
+
+ it('preserves another page title when review data arrives in the background', () => {
+ navigate('/v3/events', 'Events - Practera');
+ reviewsSource.next([{ assessmentId: 11, contextId: 22, submissionId: 1, name: 'Background review' }]);
+ expect(document.title).toBe('Events - Practera');
+ navigate('/v3/review-desktop');
+ expect(document.title).toBe('Background review');
+ });
+
+ it('selects a pending review when the base route has no submissionId parameter', () => {
+ const pendingReview = { assessmentId: 11, contextId: 22, submissionId: 3, name: 'Review A', isDone: false };
+ reviewsSource.next([pendingReview]);
+ expect(component.currentReview).toEqual(pendingReview as any);
+ expect(document.title).toBe('Review A');
+ });
+
+ it('keeps the selected review when a cached base route refreshes its reviews', () => {
+ const first = { assessmentId: 11, contextId: 22, submissionId: 3, name: 'Review A', isDone: false };
+ const selected = { assessmentId: 12, contextId: 23, submissionId: 4, name: 'Review B', isDone: false };
+ reviewsSource.next([first, selected]);
+ component.goto(selected as any);
+ navigate('/v3/home', 'Local Test Experience');
+ const refreshed = { ...selected, name: 'Review B refreshed' };
+ reviewsSource.next([first, refreshed]);
+ expect(document.title).toBe('Local Test Experience');
+ navigate('/v3/review-desktop');
+ expect(component.currentReview).toEqual(refreshed as any);
+ expect(document.title).toBe('Review B refreshed');
+ });
+
+ it('advances to the next pending review when the selected review becomes completed', () => {
+ const first = { assessmentId: 11, contextId: 22, submissionId: 3, name: 'Review A', isDone: false };
+ const selected = { assessmentId: 12, contextId: 23, submissionId: 4, name: 'Review B', isDone: false };
+ reviewsSource.next([first, selected]);
+ component.goto(selected as any);
+ reviewsSource.next([first, { ...selected, isDone: true }]);
+ expect(component.currentReview).toEqual(first as any);
+ expect(document.title).toBe('Review A');
+ });
+
+ it('clears the selected review when refreshed data no longer contains reviews', () => {
+ component.goto({ assessmentId: 12, contextId: 23, submissionId: 4, name: 'Review B', isDone: false } as any);
+ reviewsSource.next([]);
+ expect(component.currentReview).toBeUndefined();
+ expect(document.title).toBe('Reviews - Practera');
+ });
+
+ it('clears a stale selected-review title when no review remains', () => {
+ component.goto({ assessmentId: 11, contextId: 22, submissionId: 33, name: 'Peer feedback' } as any);
+ component.goto(undefined as any);
+ navigate('/v3/events', 'Events - Practera');
+ navigate('/v3/review-desktop');
+ expect(document.title).toBe('Reviews - Practera');
+ expect(component.currentReview).toBeUndefined();
+ });
+
+ it('keeps the unnamed-review fallback on cached return', () => {
+ component.goto({ assessmentId: 11, contextId: 22, submissionId: 33, name: '' } as any);
+ navigate('/v3/events', 'Events - Practera');
+ navigate('/v3/review-desktop');
+ expect(document.title).toBe('Review');
+ });
+
+ it('does not retitle a similarly named route', () => {
+ navigate('/v3/review-desktop-other', 'Other page');
+ reviewsSource.next([{ assessmentId: 11, contextId: 22, submissionId: 1, name: 'Background review' }]);
+ expect(document.title).toBe('Other page');
+ });
+
+ it('does not overwrite the title of a different cached review page', () => {
+ routeSnapshot.paramMap = convertToParamMap({ submissionId: '33' });
+ routerState.url = '/v3/review-desktop/33';
+ component.goto({ assessmentId: 11, contextId: 22, submissionId: 33, name: 'First review' } as any);
+ navigate('/v3/review-desktop/44', 'Second review');
+ expect(document.title).toBe('Second review');
+ });
+
+ it('does not restore a title for an unfinished navigation', () => {
+ document.title = 'Events - Practera';
+ routerEvents.next(new NavigationStart(2, '/v3/review-desktop'));
+ expect(document.title).toBe('Events - Practera');
+ });
+
+ it('stops title updates from router and review streams after destruction', () => {
+ component.ngOnDestroy();
+ document.title = 'New page';
+ reviewsSource.next([{ assessmentId: 11, contextId: 22, submissionId: 1, name: 'Late review' }]);
+ navigate('/v3/review-desktop');
+ expect(document.title).toBe('New page');
+ });
+
it('should create', () => {
expect(component).toBeTruthy();
});
diff --git a/projects/v3/src/app/pages/review-desktop/review-desktop.page.ts b/projects/v3/src/app/pages/review-desktop/review-desktop.page.ts
index 7a4f36ee8..997c346bd 100644
--- a/projects/v3/src/app/pages/review-desktop/review-desktop.page.ts
+++ b/projects/v3/src/app/pages/review-desktop/review-desktop.page.ts
@@ -1,10 +1,11 @@
-import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
+import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit } from '@angular/core';
+import { ActivatedRoute, NavigationEnd, PRIMARY_OUTLET, Router } from '@angular/router';
import { Assessment, AssessmentReview, AssessmentService, Submission } from '@v3/app/services/assessment.service';
import { NotificationsService } from '@v3/app/services/notifications.service';
import { Review, ReviewService } from '@v3/app/services/review.service';
import { UtilsService } from '@v3/services/utils.service';
-import { BehaviorSubject, firstValueFrom } from 'rxjs';
+import { BehaviorSubject, firstValueFrom, Subject } from 'rxjs';
+import { filter, takeUntil } from 'rxjs/operators';
@Component({
standalone: false,
@@ -12,7 +13,8 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs';
templateUrl: './review-desktop.page.html',
styleUrls: ['./review-desktop.page.scss'],
})
-export class ReviewDesktopPage implements OnInit {
+export class ReviewDesktopPage implements OnInit, OnDestroy {
+ private readonly destroy$ = new Subject();
loading: boolean; // loading indicator (true = loading | false = done loaded)
savingText$: BehaviorSubject = new BehaviorSubject('');
btnDisabled$: BehaviorSubject = new BehaviorSubject(false);
@@ -35,38 +37,75 @@ export class ReviewDesktopPage implements OnInit {
private notificationsService: NotificationsService,
private cdr: ChangeDetectorRef,
private ngZone: NgZone,
+ private router: Router,
) { }
ngOnInit(): void {
- this.utils.setPageTitle('Reviews - Practera');
- this.assessmentService.assessment$.subscribe(res => {
+ this.updatePageTitle();
+ this.router.events.pipe(
+ filter(event => event instanceof NavigationEnd),
+ takeUntil(this.destroy$),
+ ).subscribe(() => {
+ this.ngZone.run(() => {
+ this.updatePageTitle();
+ this.cdr.markForCheck();
+ });
+ });
+ this.assessmentService.assessment$.pipe(takeUntil(this.destroy$)).subscribe(res => {
this.ngZone.run(() => { this.assessment = res; this.cdr.markForCheck(); });
});
- this.assessmentService.submission$.subscribe(res => {
+ this.assessmentService.submission$.pipe(takeUntil(this.destroy$)).subscribe(res => {
this.ngZone.run(() => { this.submission = res; this.cdr.markForCheck(); });
});
- this.assessmentService.review$.subscribe(res => {
+ this.assessmentService.review$.pipe(takeUntil(this.destroy$)).subscribe(res => {
this.ngZone.run(() => { this.review = res; this.cdr.markForCheck(); });
});
- this.route.paramMap.subscribe(_params => {
+ this.route.paramMap.pipe(takeUntil(this.destroy$)).subscribe(_params => {
this.reviewService.getReviews();
});
- this.route.params.subscribe(params => {
- this.submissionId = +params?.submissionId;
+ this.route.params.pipe(takeUntil(this.destroy$)).subscribe(params => {
+ this.ngZone.run(() => {
+ this.submissionId = +params?.submissionId || 0;
+ this.cdr.markForCheck();
+ });
});
- this.reviewService.reviews$.subscribe(reviews => {
+ this.reviewService.reviews$.pipe(takeUntil(this.destroy$)).subscribe(reviews => {
this.ngZone.run(() => {
this.reviews = reviews;
+ if (this.utils.isEmpty(this.submissionId) || this.submissionId === 0) {
+ // Preserve a cached selection, but advance after completing a review.
+ const selectedReview = reviews.find(review => review.submissionId === this.currentReview?.submissionId
+ && review.isDone === this.currentReview.isDone);
+ if (selectedReview) {
+ this.goto(selectedReview);
+ } else {
+ this.gotoFirstReview(reviews);
+ }
+ } else {
+ this.goto(reviews.find(re => re.submissionId === this.submissionId));
+ }
this.cdr.markForCheck();
});
- if (this.utils.isEmpty(this.submissionId) || this.submissionId === 0) {
- this.gotoFirstReview(reviews);
- } else if (reviews.length > 0) { // handle directlink
- this.goto(reviews.find(re => re.submissionId === this.submissionId));
- }
});
}
+ ngOnDestroy(): void {
+ this.destroy$.next();
+ this.destroy$.complete();
+ }
+
+ private updatePageTitle(): void {
+ // Ionic keeps this page subscribed while another tab is active.
+ const segments = this.router.parseUrl(this.router.url).root.children[PRIMARY_OUTLET]?.segments || [];
+ const routeSubmissionId = this.route.snapshot.paramMap.get('submissionId');
+ const currentSubmissionId = segments[2]?.path || null;
+ if (segments.length >= 2 && segments.length <= 3
+ && segments[0].path === 'v3' && segments[1].path === 'review-desktop'
+ && currentSubmissionId === routeSubmissionId) {
+ this.utils.setPageTitle(this.currentReview ? this.currentReview.name || 'Review' : 'Reviews - Practera');
+ }
+ }
+
/**
* Go to the first review of the review list for desktop
*/
@@ -87,13 +126,12 @@ export class ReviewDesktopPage implements OnInit {
}
goto(review: Review) {
+ this.currentReview = review;
+ this.noReview = !review;
+ this.updatePageTitle();
if (!review) {
- this.noReview = true;
return;
}
- this.noReview = false;
- this.currentReview = review;
- this.utils.setPageTitle(review?.name || 'Review');
this.assessmentService.getAssessment(review.assessmentId, 'review', 0, review.contextId, review.submissionId);
}
diff --git a/projects/v3/src/app/pages/settings/settings.page.spec.ts b/projects/v3/src/app/pages/settings/settings.page.spec.ts
index 5cb98ed72..914e93436 100644
--- a/projects/v3/src/app/pages/settings/settings.page.spec.ts
+++ b/projects/v3/src/app/pages/settings/settings.page.spec.ts
@@ -371,6 +371,39 @@ describe('SettingsPage', () => {
});
describe('openBadgeApp()', () => {
+ for (const event of [
+ new Event('click'),
+ new KeyboardEvent('keydown', { key: 'Enter' }),
+ new KeyboardEvent('keydown', { key: ' ' }),
+ ]) {
+ it(`waits for the Settings drawer to close before navigation (${event.type}, ${(event as KeyboardEvent).key || 'click'})`, async () => {
+ component.mode = 'modal';
+ let finishDismiss: (value: boolean) => void;
+ modalControllerSpy.dismiss.and.returnValue(new Promise(resolve => { finishDismiss = resolve; }));
+ routerSpy.navigate.and.returnValue(Promise.resolve(true));
+
+ const navigation = component.openBadgeApp(event);
+ expect(routerSpy.navigate).not.toHaveBeenCalled();
+ finishDismiss(true);
+ await navigation;
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'badges-certificates']);
+ });
+ }
+
+ it('does not dismiss an overlay when Settings is a routed page', async () => {
+ await component.openBadgeApp(new Event('click'));
+ expect(routerSpy.navigate).toHaveBeenCalledWith(['v3', 'badges-certificates']);
+ expect(modalControllerSpy.dismiss).not.toHaveBeenCalled();
+ });
+
+ it('does not navigate if drawer dismissal rejects', async () => {
+ component.mode = 'modal';
+ const error = new Error('Dismissal failed');
+ modalControllerSpy.dismiss.and.callFake(() => Promise.reject(error));
+ await expectAsync(Promise.resolve().then(() => component.openBadgeApp(new Event('click')))).toBeRejectedWith(error);
+ expect(routerSpy.navigate).not.toHaveBeenCalled();
+ });
+
it('navigates to badges-certificates on click', () => {
component.openBadgeApp(new Event('click'));
diff --git a/projects/v3/src/app/pages/settings/settings.page.ts b/projects/v3/src/app/pages/settings/settings.page.ts
index b18b1a3dd..b04f18b77 100644
--- a/projects/v3/src/app/pages/settings/settings.page.ts
+++ b/projects/v3/src/app/pages/settings/settings.page.ts
@@ -124,7 +124,7 @@ export class SettingsPage implements OnInit, OnDestroy {
}
dismiss() {
- this.modalController.dismiss({
+ return this.modalController.dismiss({
'dismissed': true
});
}
@@ -296,10 +296,13 @@ export class SettingsPage implements OnInit, OnDestroy {
return this.mailTo(event);
}
- openBadgeApp(event) {
+ async openBadgeApp(event): Promise {
if (event instanceof KeyboardEvent && event.key !== 'Enter' && event.key !== ' ') {
return;
}
- this.router.navigate(['v3', 'badges-certificates']);
+ if (this.mode === 'modal') {
+ await this.dismiss();
+ }
+ return this.router.navigate(['v3', 'badges-certificates']);
}
}
diff --git a/projects/v3/src/app/pages/tabs/tabs-routing.module.spec.ts b/projects/v3/src/app/pages/tabs/tabs-routing.module.spec.ts
index 4acde8fe5..3e5b91c55 100644
--- a/projects/v3/src/app/pages/tabs/tabs-routing.module.spec.ts
+++ b/projects/v3/src/app/pages/tabs/tabs-routing.module.spec.ts
@@ -5,6 +5,7 @@ import { provideRouter, Router } from '@angular/router';
import { RouterTestingHarness } from '@angular/router/testing';
import { BrowserStorageService } from '@v3/services/storage.service';
import { UtilsService } from '@v3/services/utils.service';
+import { AppRoutingModule } from '../../app-routing.module';
import { ChatPage } from '../chat/chat.page';
import { TabsPageRoutingModule } from './tabs-routing.module';
@@ -20,7 +21,7 @@ describe('Tab page titles', () => {
beforeEach(async () => {
experience = { name: 'Learning & Practice' };
TestBed.configureTestingModule({
- imports: [TabsPageRoutingModule],
+ imports: [AppRoutingModule, TabsPageRoutingModule],
declarations: [ChatPage],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
@@ -37,7 +38,14 @@ describe('Tab page titles', () => {
// Keep the production tab routes and title resolvers, replacing page data
// loading with an empty page so navigation needs no backend or learner login.
const tabs = router.config.find(route => route.children)?.children || [];
- router.resetConfig([{ path: 'v3', children: tabs.map(route => ({
+ const experiences = router.config.find(route => route.path === 'experiences');
+ router.resetConfig([{
+ ...experiences,
+ path: 'experiences',
+ loadChildren: undefined,
+ canLoad: undefined,
+ component: RoutedPage,
+ }, { path: 'v3', children: tabs.map(route => ({
...route,
children: undefined,
loadChildren: route.path === 'messages'
@@ -52,6 +60,17 @@ describe('Tab page titles', () => {
afterEach(() => title.setTitle(originalTitle));
+ it('restores the experience selector title after repeated visits to Events', async () => {
+ await router.navigateByUrl('/experiences');
+ for (let i = 0; i < 3; i++) {
+ await router.navigateByUrl('/v3/home');
+ await router.navigateByUrl('/v3/events');
+ expect(title.getTitle()).toBe('Events - Practera');
+ await router.navigateByUrl('/experiences');
+ expect(title.getTitle()).toBe('Experiences - Practera');
+ }
+ });
+
it('restores Events after Home → Events → Messages → Events, repeatedly', async () => {
await router.navigateByUrl('/v3/home');
// Simulate the first page creation; cached Ionic pages will not repeat it.
diff --git a/projects/v3/src/app/personalised-header/personalised-header.component.spec.ts b/projects/v3/src/app/personalised-header/personalised-header.component.spec.ts
index 378232474..dc31ea2f1 100644
--- a/projects/v3/src/app/personalised-header/personalised-header.component.spec.ts
+++ b/projects/v3/src/app/personalised-header/personalised-header.component.spec.ts
@@ -102,6 +102,17 @@ describe('PersonalisedHeaderComponent', () => {
expect(component).toBeTruthy();
});
+ it('records the current route when opening the mobile Notifications page', async () => {
+ utils.isMobile.and.returnValue(true);
+ (router as any).url = '/assessment-mobile/assessment/11/8/11?view=feedback#answer';
+ const button: HTMLElement = fixture.nativeElement.querySelector('.notify-btn');
+ button.click();
+ await fixture.whenStable();
+ expect(router.navigate).toHaveBeenCalledWith(['v3', 'notifications'], {
+ state: { notificationsReturnUrl: '/assessment-mobile/assessment/11/8/11?view=feedback#answer' },
+ });
+ });
+
it('should expose the accessWidget custom trigger before notifications', () => {
const accessibilityButton: HTMLElement = fixture.nativeElement.querySelector('.accessibility-btn');
diff --git a/projects/v3/src/app/personalised-header/personalised-header.component.ts b/projects/v3/src/app/personalised-header/personalised-header.component.ts
index 255cf3832..ec985f776 100644
--- a/projects/v3/src/app/personalised-header/personalised-header.component.ts
+++ b/projects/v3/src/app/personalised-header/personalised-header.component.ts
@@ -75,7 +75,9 @@ export class PersonalisedHeaderComponent implements OnInit, OnDestroy {
async notifications(): Promise {
if (this.isMobile) {
- return this.router.navigate(['v3', 'notifications']);
+ return this.router.navigate(['v3', 'notifications'], {
+ state: { notificationsReturnUrl: this.router.url },
+ });
}
const modal = await this.modalController.create({