Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>A &amp; B</p><div>Next<br>line</div>')).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(`<p>Hello</p><img src="data:image/png;base64,invalid" onerror="window.${marker}=true">`)).toBe('Hello');
await new Promise(resolve => setTimeout(resolve, 100));
expect((window as any)[marker]).toBeFalse();
} finally {
delete (window as any)[marker];
}
});
});
});
11 changes: 8 additions & 3 deletions projects/v3/src/app/pages/chat/chat-list/chat-list.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -158,7 +160,10 @@ export class ChatListComponent implements OnDestroy {
const withBreaks = value
.replace(/<br\s*\/?>/gi, ' ')
.replace(/<\/(p|div|li|h[1-6])>/gi, ' ');
return this.utils.decodeHtmlEntities(withBreaks).replace(/\s+/g, ' ').trim();
// 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<ion-grid class="white-bg">
<ion-row nowrap class="ion-no-padding">
<ion-col [size]="12" class="ion-align-self-center ion-no-padding">
<quill-editor aria-label="Enter your message" i18n-aria-label
<quill-editor
customToolbarPosition="top"
[modules]="editorModules"
[classes]="isMobile ? 'editor-class' : 'editor-class desktop'"
Expand All @@ -192,7 +192,7 @@
placeholder="Enter your message"
[(ngModel)]="typingMessage"
(ngModelChange)="typing()"
(onEditorCreated)="labelMessageEditor()"
(onEditorCreated)="labelMessageEditor($event)"
i18n-placeholder
></quill-editor>
</ion-col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
18 changes: 6 additions & 12 deletions projects/v3/src/app/pages/chat/chat-room/chat-room.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -357,11 +358,14 @@ export class ChatRoomComponent implements OnInit, OnDestroy, AfterViewInit {

// Set aria-labels for Quill toolbar elements (WCAG 4.1.2)
setTimeout(() => {
this.labelMessageEditor();
this._setQuillToolbarAriaLabels();
}, 500);
}

labelMessageEditor(): void {
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();
}

Expand Down Expand Up @@ -401,16 +405,6 @@ export class ChatRoomComponent implements OnInit, OnDestroy, AfterViewInit {
if (videoInput && !videoInput.getAttribute('aria-label')) {
videoInput.setAttribute('aria-label', 'Enter video embed URL');
}

// Quill's contenteditable is not exposed as a named textbox unless these are set on .ql-editor.
const messageEditor = componentElement.querySelector('.ql-editor') as HTMLElement;
if (messageEditor) {
messageEditor.setAttribute('role', 'textbox');
messageEditor.setAttribute('aria-multiline', 'true');
if (!messageEditor.getAttribute('aria-label')) {
messageEditor.setAttribute('aria-label', $localize`Enter your message`);
}
}
}

/**
Expand Down
27 changes: 14 additions & 13 deletions projects/v3/src/app/pages/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,24 @@
}
</ion-segment>

@switch (display) {
@case ('activities') {
<div role="tabpanel" id="activities-panel" [attr.aria-labelledby]="'activities-tab'">
<ng-container *ngTemplateOutlet="activityList"></ng-container>
</div>
<div role="tabpanel" id="activities-panel" aria-labelledby="activities-tab" [hidden]="display !== 'activities'">
@if (display === 'activities') {
<ng-container *ngTemplateOutlet="activityList"></ng-container>
}
@case ('badges') {
<div role="tabpanel" id="badges-panel" [attr.aria-labelledby]="'badges-tab'">
<ng-container *ngTemplateOutlet="badgePoints"></ng-container>
</div>
</div>
<div role="tabpanel" id="badges-panel" aria-labelledby="badges-tab" [hidden]="display !== 'badges'">
@if (display === 'badges') {
<ng-container *ngTemplateOutlet="badgePoints"></ng-container>
}
@case ('pulse-checks') {
<div role="tabpanel" id="pulse-checks-panel" [attr.aria-labelledby]="'pulse-checks-tab'">
</div>
@if (pulseCheckIndicatorEnabled === true && !isExpertWithoutTeam) {
<div role="tabpanel" id="pulse-checks-panel" aria-labelledby="pulse-checks-tab" [hidden]="display !== 'pulse-checks'">
@if (display === 'pulse-checks') {
<ng-container *ngTemplateOutlet="pulseChecks"></ng-container>
</div>
}
}
</div>
}

</ion-col>

</ion-row>
Expand Down
83 changes: 83 additions & 0 deletions projects/v3/src/app/pages/home/home.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,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);
}
});
});
});
});
37 changes: 25 additions & 12 deletions projects/v3/src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
activitySearchText = '';
filteredMilestones: Milestone[] | null = null;
private activityFilterLabelRequested = false;
private pendingContentTabs = new WeakSet<HTMLElement>();

// Expose Math to template
Math = Math;
Expand Down Expand Up @@ -135,7 +136,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
return;
}
this.activityFilterLabelRequested = true;
this.activityFilter.getInputElement().then((input) => {
Promise.resolve().then(() => this.activityFilter?.getInputElement?.()).then((input) => {
if (!input) {
this.activityFilterLabelRequested = false;
return;
Expand All @@ -147,23 +148,35 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
}

/**
* ion-segment-button already exposes an inner tab. Copy the panel relationship onto that tab.
* The host id stays in light DOM so the tab panel aria-labelledby can still find it.
* 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: Element) => {
const segmentButton = button as HTMLElement;
const native = segmentButton.shadowRoot?.querySelector('button');
if (!native) {
return;
}
const controls = segmentButton.getAttribute('aria-controls');
if (controls && native.getAttribute('aria-controls') !== controls) {
native.setAttribute('aria-controls', controls);
host.querySelectorAll<HTMLIonSegmentButtonElement>('ion-segment-button').forEach(button => {
const linkPanel = () => {
const native = button.shadowRoot?.querySelector('button');
const controls = button.getAttribute('aria-controls');
const panel = controls ? host.querySelector<HTMLElement>(`#${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));
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion projects/v3/src/app/services/experience.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SharedService>;
const authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions projects/v3/src/app/services/experience.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading