diff --git a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.html b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.html index 270edcecd..c76c50e09 100644 --- a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.html +++ b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.html @@ -24,14 +24,14 @@
+ [attr.aria-label]="'chatroom: ' + plainText(chat.name)">

@if ((chat.roles.length === 1) && (chat.roles.includes('mentor'))) { {{ utils.getUserRolesForUI('mentor') }} }
@if (chat.lastMessage) { -

+

} @else {

No messages.

} diff --git a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.spec.ts b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.spec.ts index 2b0f03367..bc4e35347 100644 --- a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.spec.ts +++ b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.spec.ts @@ -190,4 +190,27 @@ describe('ChatListComponent', () => { }); }); + describe('accessible chat text', () => { + beforeEach(() => { + (utils.decodeHtmlEntities as jasmine.Spy).and.callFake((value: string) => + UtilsService.prototype.decodeHtmlEntities.call({ document }, value)); + }); + + it('decodes entities and separates HTML blocks', () => { + expect(component.plainText('

A & B

Next
line
')).toBe('A & B Next line'); + expect(component.plainText('')).toBe(''); + }); + + it('keeps HTML event handlers inert when extracting a message label', async () => { + const marker = '__pr2808MessageExecuted'; + (window as any)[marker] = false; + try { + expect(component.plainText(`

Hello

`)).toBe('Hello'); + await new Promise(resolve => setTimeout(resolve, 100)); + expect((window as any)[marker]).toBeFalse(); + } finally { + delete (window as any)[marker]; + } + }); + }); }); diff --git a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.ts b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.ts index ebbd6f29d..2fe55e3d1 100644 --- a/projects/v3/src/app/pages/chat/chat-list/chat-list.component.ts +++ b/projects/v3/src/app/pages/chat/chat-list/chat-list.component.ts @@ -1,4 +1,5 @@ -import { ChangeDetectorRef, Component, Output, EventEmitter, NgZone, Input, OnDestroy } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; +import { Inject, ChangeDetectorRef, Component, Output, EventEmitter, NgZone, Input, OnDestroy } from '@angular/core'; import { Router, NavigationExtras } from '@angular/router'; import { BrowserStorageService } from '@v3/services/storage.service'; import { UtilsService } from '@v3/services/utils.service'; @@ -32,7 +33,8 @@ export class ChatListComponent implements OnDestroy { private storage: BrowserStorageService, private ngZone: NgZone, private cdr: ChangeDetectorRef, - private pusherService: PusherService + private pusherService: PusherService, + @Inject(DOCUMENT) private document: Document ) { this.isMobile = this.utils.isMobile(); this.utils.getEvent('chat:new-message') @@ -148,4 +150,20 @@ export class ChatListComponent implements OnDestroy { return this.utils.timeFormatter(date); } + /** + * Accessible names must be text. Last messages and channel names are stored as HTML. + */ + plainText(value: string): string { + if (!value) { + return ''; + } + const withBreaks = value + .replace(//gi, ' ') + .replace(/<\/(p|div|li|h[1-6])>/gi, ' '); + // Template contents are inert: message images and event handlers never activate. + const template = this.document.createElement('template'); + template.innerHTML = withBreaks; + return (template.content.textContent || '').replace(/\s+/g, ' ').trim(); + } + } diff --git a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.html b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.html index ad72598ef..47b66dd16 100644 --- a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.html +++ b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.html @@ -182,7 +182,7 @@ - diff --git a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.spec.ts b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.spec.ts index 3d36ff9ee..454ae28fc 100644 --- a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.spec.ts +++ b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.spec.ts @@ -791,4 +791,16 @@ describe('ChatRoomComponent', () => { }); }); + it('labels the created editable root rather than a message preview', () => { + const preview = document.createElement('div'); + preview.className = 'ql-editor'; + fixture.nativeElement.prepend(preview); + const root = document.createElement('div'); + root.contentEditable = 'true'; + (component.labelMessageEditor as any)({ root }); + expect(root.getAttribute('role')).toBe('textbox'); + expect(root.getAttribute('aria-multiline')).toBe('true'); + expect(root.getAttribute('aria-label')).toBe('Enter your message'); + expect(preview.hasAttribute('role')).toBeFalse(); + }); }); diff --git a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.ts b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.ts index 379f4edb6..d41dee0df 100644 --- a/projects/v3/src/app/pages/chat/chat-room/chat-room.component.ts +++ b/projects/v3/src/app/pages/chat/chat-room/chat-room.component.ts @@ -14,6 +14,7 @@ import { EditMessagePopupComponent } from '../edit-message-popup/edit-message-po import { Subject, Subscription, timer } from 'rxjs'; import { debounceTime, switchMap, takeUntil, tap } from 'rxjs/operators'; import { QuillModules } from 'ngx-quill'; +import type Quill from 'quill'; import { UppyFileData, UppyUploaderResponse, UppyUploaderService } from '../../../components/uppy-uploader/uppy-uploader.service'; enum ScrollPosition { @@ -361,6 +362,13 @@ export class ChatRoomComponent implements OnInit, OnDestroy, AfterViewInit { }, 500); } + labelMessageEditor(editor: Quill): void { + editor.root.setAttribute('role', 'textbox'); + editor.root.setAttribute('aria-multiline', 'true'); + editor.root.setAttribute('aria-label', $localize`Enter your message`); + this._setQuillToolbarAriaLabels(); + } + /** * Set aria-labels for Quill editor toolbar elements for accessibility */ diff --git a/projects/v3/src/app/pages/chat/chat.page.ts b/projects/v3/src/app/pages/chat/chat.page.ts index 919aa565e..5481a1d05 100644 --- a/projects/v3/src/app/pages/chat/chat.page.ts +++ b/projects/v3/src/app/pages/chat/chat.page.ts @@ -1,7 +1,22 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { UtilsService } from '@v3/services/utils.service'; @Component({ standalone: false, template: '', }) -export class ChatPage {} +export class ChatPage implements OnInit { + constructor(private utils: UtilsService) {} + + ngOnInit() { + this.setMessagesTitle(); + } + + ionViewDidEnter() { + this.setMessagesTitle(); + } + + private setMessagesTitle() { + this.utils.setPageTitle('Messages - Practera'); + } +} diff --git a/projects/v3/src/app/pages/home/home.page.html b/projects/v3/src/app/pages/home/home.page.html index 2e5c0af65..e21f86a12 100644 --- a/projects/v3/src/app/pages/home/home.page.html +++ b/projects/v3/src/app/pages/home/home.page.html @@ -134,48 +134,46 @@ [value]="display" role="tablist" aria-label="Content navigation tabs" i18n-aria-label> - Activities - { getIsPointsConfigured, select, true {Badges & Points} false {Badges} } @if (pulseCheckIndicatorEnabled === true && !isExpertWithoutTeam) { - Skill & Progress Surveys } - @switch (display) { - @case ('activities') { -
- -
+
+ @if (display === 'activities') { + } - @case ('badges') { -
- -
+
+
+ @if (display === 'badges') { + } - @case ('pulse-checks') { -
+
+ @if (pulseCheckIndicatorEnabled === true && !isExpertWithoutTeam) { +
+ @if (display === 'pulse-checks') { -
- } + } +
} +
@@ -190,14 +188,15 @@ i18n>Activity list
- @if (activitySearchText && filteredMilestones) { @@ -219,27 +218,30 @@ i18n-aria-label> @if ((activitySearchText ? filteredMilestones : milestones)?.length > 0) { @for (milestone of (activitySearchText ? filteredMilestones : milestones)!; track milestone) { - -
- @if (milestone.isLocked) { - - } -
+

+ +
+ @if (milestone.isLocked) { + + } +
+

@if (milestone?.description) { - diff --git a/projects/v3/src/app/pages/home/home.page.scss b/projects/v3/src/app/pages/home/home.page.scss index bbe4bac59..b160d48d9 100644 --- a/projects/v3/src/app/pages/home/home.page.scss +++ b/projects/v3/src/app/pages/home/home.page.scss @@ -1,3 +1,10 @@ +.milestone-heading { + margin: 0; + font-size: inherit; + font-weight: inherit; + line-height: inherit; +} + .milestone-name { &.locked { cursor: pointer; diff --git a/projects/v3/src/app/pages/home/home.page.spec.ts b/projects/v3/src/app/pages/home/home.page.spec.ts index 81cf18c88..51dde0b2d 100644 --- a/projects/v3/src/app/pages/home/home.page.spec.ts +++ b/projects/v3/src/app/pages/home/home.page.spec.ts @@ -399,16 +399,25 @@ describe('HomePage', () => { }); it('should set page title with experience name', async () => { + (TestBed.inject(Router) as unknown as { url: string }).url = '/v3/home'; await component.updateDashboard(); expect(utilsService.setPageTitle).toHaveBeenCalledWith('Test Experience'); }); it('should set page title with default when experience has no name', async () => { + (TestBed.inject(Router) as unknown as { url: string }).url = '/v3/home'; storageService.get.and.returnValue({}); await component.updateDashboard(); expect(utilsService.setPageTitle).toHaveBeenCalledWith('Practera'); }); + it('should not replace another page title when the dashboard refreshes off Home', async () => { + (TestBed.inject(Router) as unknown as { url: string }).url = '/v3/messages'; + utilsService.setPageTitle.calls.reset(); + await component.updateDashboard(); + expect(utilsService.setPageTitle).not.toHaveBeenCalled(); + }); + it('should set default lead image from experience card URL', async () => { await component.updateDashboard(); expect(component.defaultLeadImage).toBe('test-url'); @@ -478,4 +487,87 @@ describe('HomePage', () => { }); }); + describe('Ionic content tab accessibility', () => { + it('keeps Ionic segment controls and light DOM panel labels', () => { + const segment = fixture.nativeElement.querySelector('ion-segment'); + expect(segment).not.toBeNull(); + const tabs: HTMLElement[] = Array.from(fixture.nativeElement.querySelectorAll('ion-segment-button')); + expect(tabs.length).toBe(2); + tabs.forEach(tab => { + const panel = fixture.nativeElement.querySelector('#' + tab.getAttribute('aria-controls')); + expect(panel).not.toBeNull(); + expect(panel?.getAttribute('aria-labelledby')).toBe(tab.id); + }); + expect(fixture.nativeElement.querySelector('.content-tabs')).toBeNull(); + }); + + it('switches content through Ionic ionChange and refreshes badge points', () => { + const segment = fixture.nativeElement.querySelector('ion-segment'); + expect(segment).not.toBeNull(); + if (!segment) { return; } + component.achievements = []; + (achievementService as any).isPointsConfigured = true; + (achievementService as any).earnedPoints = 12; + segment.dispatchEvent(new CustomEvent('ionChange', { detail: { value: 'badges' } })); + fixture.detectChanges(); + expect(component.display).toBe('badges'); + expect(component.getEarnedPoints).toBe(12); + expect(component.getIsPointsConfigured).toBeTrue(); + expect(fixture.nativeElement.querySelector('#badges-panel').hidden).toBeFalse(); + expect(fixture.nativeElement.querySelector('#activities-panel').hidden).toBeTrue(); + }); + + describe('shadow DOM panel references', () => { + let host: HTMLIonColElement; + let tab: HTMLElement; + let native: HTMLButtonElement; + let panel: HTMLElement; + + beforeEach(() => { + host = document.createElement('ion-col'); + tab = document.createElement('ion-segment-button'); + tab.setAttribute('aria-controls', 'review-panel'); + native = document.createElement('button'); + (tab.shadowRoot || tab.attachShadow({ mode: 'open' })).append(native); + panel = document.createElement('div'); + panel.id = 'review-panel'; + host.append(tab, panel); + document.body.append(host); + component.activityCol = { el: host }; + }); + + afterEach(() => host.remove()); + + it('links the inner Ionic button to its light DOM panel by element reference', () => { + (component as any).linkContentTabs?.(); + expect(Array.from(native.ariaControlsElements || [])).toEqual([panel]); + expect(native.getAttribute('aria-controls')).not.toBe('review-panel'); + }); + + it('waits for Ionic hydration before linking a newly created button', async () => { + native.remove(); + (tab as any).componentOnReady = () => Promise.resolve().then(() => { + tab.shadowRoot!.append(native); + return tab; + }); + (component as any).linkContentTabs?.(); + await Promise.resolve(); + await Promise.resolve(); + expect(Array.from(native.ariaControlsElements || [])).toEqual([panel]); + }); + + it('keeps older browsers free of invalid shadow DOM ID references', () => { + const descriptor = Object.getOwnPropertyDescriptor(Element.prototype, 'ariaControlsElements')!; + Reflect.deleteProperty(Element.prototype, 'ariaControlsElements'); + try { + (component as any).linkContentTabs?.(); + expect(native.hasAttribute('aria-controls')).toBeFalse(); + expect(Object.hasOwn(native, 'ariaControlsElements')).toBeFalse(); + expect(tab.getAttribute('aria-controls')).toBe('review-panel'); + } finally { + Object.defineProperty(Element.prototype, 'ariaControlsElements', descriptor); + } + }); + }); + }); }); diff --git a/projects/v3/src/app/pages/home/home.page.ts b/projects/v3/src/app/pages/home/home.page.ts index afa84e078..abe8fafa1 100644 --- a/projects/v3/src/app/pages/home/home.page.ts +++ b/projects/v3/src/app/pages/home/home.page.ts @@ -65,6 +65,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked { @ViewChild('activityCol') activityCol: { el: HTMLIonColElement }; @ViewChild('activities', { static: false }) activities!: ElementRef; + @ViewChild('activityFilter') activityFilter?: { getInputElement?: () => Promise }; pulseCheckSkills: PulseCheckSkill[] = []; // project brief data from team storage @@ -74,6 +75,8 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked { // activity search/filter activitySearchText = ''; filteredMilestones: Milestone[] | null = null; + private activityFilterLabelRequested = false; + private pendingContentTabs = new WeakSet(); // Expose Math to template Math = Math; @@ -110,6 +113,72 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked { if (this.activities && this.isElementVisible(this.activities.nativeElement) && id !== null && this.milestones?.length > 0) { this.scrollToElement(id); } + + this.labelActivityFilter(); + this.linkContentTabs(); + } + + private isHomeUrl(): boolean { + const path = (this.router.url || '').split('?')[0].split('#')[0]; + return path.endsWith('/home'); + } + + /** + * Ionic's searchbar names its inner input "search text" and does not use the host aria-label. + * Point that input at the visible placeholder. + */ + private labelActivityFilter(): void { + if (!this.activityFilter?.getInputElement) { + this.activityFilterLabelRequested = false; + return; + } + if (this.activityFilterLabelRequested) { + return; + } + this.activityFilterLabelRequested = true; + Promise.resolve().then(() => this.activityFilter?.getInputElement?.()).then((input) => { + if (!input) { + this.activityFilterLabelRequested = false; + return; + } + input.setAttribute('aria-label', $localize`Filter by activity title or description`); + }).catch(() => { + this.activityFilterLabelRequested = false; + }); + } + + /** + * ID references cannot cross Ionic's shadow boundary. Newer browsers can + * link the native tab directly to a light DOM panel through element references. + * Older browsers retain Ionic's tab semantics without an invalid shadow IDREF. + */ + private linkContentTabs(): void { + const host = this.activityCol?.el; + if (!host) { + return; + } + host.querySelectorAll('ion-segment-button').forEach(button => { + const linkPanel = () => { + const native = button.shadowRoot?.querySelector('button'); + const controls = button.getAttribute('aria-controls'); + const panel = controls ? host.querySelector(`#${controls}`) : null; + if (native && panel && 'ariaControlsElements' in native && native.ariaControlsElements?.[0] !== panel) { + native.ariaControlsElements = [panel]; + } + }; + if (button.shadowRoot?.querySelector('button')) { + linkPanel(); + } else if (button.componentOnReady && !this.pendingContentTabs.has(button)) { + // A newly rendered Ionic element may hydrate after Angular checks the view. + this.pendingContentTabs.add(button); + button.componentOnReady().then(() => { + this.pendingContentTabs.delete(button); + if (host.isConnected) { + linkPanel(); + } + }).catch(() => this.pendingContentTabs.delete(button)); + } + }); } ngOnInit() { @@ -285,7 +354,10 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked { }); } - this.utils.setPageTitle(this.experience?.name || 'Practera'); + // Home stays mounted and can refresh after other navigations. Only retitle while Home is current. + if (this.isHomeUrl()) { + this.utils.setPageTitle(this.experience?.name || 'Practera'); + } this.defaultLeadImage = this.experience.cardUrl || 'assets/default-experience-image.svg'; // reset & load bookmarks diff --git a/projects/v3/src/app/personalised-header/personalised-header.component.html b/projects/v3/src/app/personalised-header/personalised-header.component.html index f0b5c99db..a19fc700a 100644 --- a/projects/v3/src/app/personalised-header/personalised-header.component.html +++ b/projects/v3/src/app/personalised-header/personalised-header.component.html @@ -8,7 +8,6 @@ class="support-btn" shape="round" size="small" - aria-label="Get help and support" i18n-aria-label i18n> Do you need help? diff --git a/projects/v3/src/app/services/experience.service.spec.ts b/projects/v3/src/app/services/experience.service.spec.ts index a4bea7cf3..1d7d23cd0 100644 --- a/projects/v3/src/app/services/experience.service.spec.ts +++ b/projects/v3/src/app/services/experience.service.spec.ts @@ -89,7 +89,7 @@ describe('ExperienceService', () => { expect(service).toBeTruthy(); }); - it('should initialise Pusher only after the selected experience is authenticated', async () => { + it('should authenticate the selected timeline before initialising Pusher', async () => { const callOrder: string[] = []; const sharedService = TestBed.inject(SharedService) as jasmine.SpyObj; const authService = TestBed.inject(AuthService) as jasmine.SpyObj; @@ -119,6 +119,10 @@ describe('ExperienceService', () => { await service.switchProgramAndNavigate(experience as any); + expect(authService.authenticate).toHaveBeenCalledWith({ + experienceUuid: 'experience-2', + timelineId: 222, + }); expect(callOrder).toEqual(['authenticate', 'pusher']); expect(storageService.setUser).toHaveBeenCalledWith({ apikey: 'new-api-key' }); expect(sharedService.initWebServices).toHaveBeenCalledTimes(1); diff --git a/projects/v3/src/app/services/experience.service.ts b/projects/v3/src/app/services/experience.service.ts index 7a1807c08..72270e422 100644 --- a/projects/v3/src/app/services/experience.service.ts +++ b/projects/v3/src/app/services/experience.service.ts @@ -355,6 +355,7 @@ export class ExperienceService { await this.switchProgram({ experience }); const authResponse = await firstValueFrom(this.authService.authenticate({ experienceUuid: experience.uuid, + timelineId: experience.timelineId, })); const apikey = authResponse?.data?.auth?.apikey;