From cf9e70fb002bc19c79eab87ab195b2549ac9499b Mon Sep 17 00:00:00 2001 From: Robert Fuhrmann Date: Thu, 12 Sep 2024 13:13:47 +0200 Subject: [PATCH] feat(sbb-timetable-row): provide a11y footpaths (#3048) --------- Co-authored-by: Osman Minaz Co-authored-by: Robert Fuhrmann Co-authored-by: Jeri Peier --- .../core/timetable/access-leg-helper.spec.ts | 54 +++++++++ .../core/timetable/access-leg-helper.ts | 114 +++++++++++++----- .../pearl-chain-time.snapshot.spec.snap.js | 8 +- .../pearl-chain-time/pearl-chain-time.scss | 17 ++- .../pearl-chain-time/pearl-chain-time.ts | 4 + .../pearl-chain-time/readme.md | 1 + .../pearl-chain/pearl-chain.sample-data.ts | 29 +++++ .../timetable-row.snapshot.spec.snap.js | 1 + .../timetable-row/readme.md | 1 + .../timetable-row.sample-data.ts | 8 ++ .../timetable-row.snapshot.spec.ts | 7 +- .../timetable-row/timetable-row.stories.ts | 19 +++ .../timetable-row/timetable-row.ts | 10 ++ .../timetable-row.visual.spec.ts | 4 + tools/web-test-runner/preload-icons.ts | 1 + 15 files changed, 239 insertions(+), 39 deletions(-) diff --git a/src/elements-experimental/core/timetable/access-leg-helper.spec.ts b/src/elements-experimental/core/timetable/access-leg-helper.spec.ts index 25ddf7dd83..79c501e5b1 100644 --- a/src/elements-experimental/core/timetable/access-leg-helper.spec.ts +++ b/src/elements-experimental/core/timetable/access-leg-helper.spec.ts @@ -1,6 +1,7 @@ import { expect } from '@open-wc/testing'; import { + connectionTrip, defaultTrip, extendedEnterTimeTrip, } from '../../timetable-row/timetable-row.sample-data.js'; @@ -39,6 +40,43 @@ describe('getDepartureArrivalTimeAttribute', () => { }); }); + it('should return correct a11y time attributes', () => { + const { departureTimeAttribute, arrivalTimeAttribute } = getDepartureArrivalTimeAttribute( + defaultTrip.legs as Leg[], + 10, + 10, + 'en', + true, + ); + + expect(departureTimeAttribute).to.be.deep.equal({ + duration: 10, + icon: 'wheelchair-small', + text: 'minutes of walking time before departure:', + }); + expect(arrivalTimeAttribute).to.be.deep.equal({ + duration: 10, + icon: 'wheelchair-small', + text: 'minutes of walking time after arrival:', + }); + }); + + it('should return correct time attribute for connection-leg', () => { + const { departureTimeAttribute } = getDepartureArrivalTimeAttribute( + connectionTrip.legs as Leg[], + 10, + 0, + 'en', + true, + ); + + expect(departureTimeAttribute).to.be.deep.equal({ + duration: 30, + icon: 'walk-small', + text: 'Zu Fuss', + }); + }); + it('should returns extended departure time attribute', () => { const { departureTimeAttribute } = getDepartureArrivalTimeAttribute( extendedEnterTimeTrip.legs as Leg[], @@ -68,4 +106,20 @@ describe('getDepartureArrivalTimeAttribute', () => { text: 'Extended boarding time ', }); }); + + it('should return correct a11y time attribute with extended departure time', () => { + const { departureTimeAttribute } = getDepartureArrivalTimeAttribute( + extendedEnterTimeTrip.legs as Leg[], + 0, + 0, + 'en', + true, + ); + + expect(departureTimeAttribute).to.be.deep.equal({ + duration: 45, + icon: 'wheelchair-small', + text: 'minutes of walking time before departure:', + }); + }); }); diff --git a/src/elements-experimental/core/timetable/access-leg-helper.ts b/src/elements-experimental/core/timetable/access-leg-helper.ts index fe638ffa10..e9c7cfbf73 100644 --- a/src/elements-experimental/core/timetable/access-leg-helper.ts +++ b/src/elements-experimental/core/timetable/access-leg-helper.ts @@ -50,6 +50,8 @@ function getPTConnectionAttribute( function getFirstExtendedLegAttribute( leg: PtRideLeg | PtConnectionLeg, departureWalk: number, + a11yFootpath: boolean | undefined, + currentLanguage: string, ): IAccessAttribute | null { // Extended enter const extendedFirstLeg = isRideLeg(leg) @@ -64,8 +66,10 @@ function getFirstExtendedLegAttribute( return extendedFirstLeg ? { duration: (extractTimeAndString?.duration || 0) + (departureWalk || 0), - text: extractTimeAndString?.text || '', - icon: `sa-${extendedFirstLeg?.name?.toLowerCase()}`, + text: a11yFootpath + ? i18nWalkingDistanceDeparture[currentLanguage] + : extractTimeAndString?.text || '', + icon: a11yFootpath ? 'wheelchair-small' : `sa-${extendedFirstLeg?.name?.toLowerCase()}`, } : null; } @@ -73,7 +77,12 @@ function getFirstExtendedLegAttribute( /** * @returns the extended exit attribute of the PTRideLeg */ -function getLastExtendedLegAttribute(leg: Leg, arrivalWalk: number): IAccessAttribute | null { +function getLastExtendedLegAttribute( + leg: Leg, + arrivalWalk: number, + a11yFootpath: boolean | undefined, + currentLanguage: string, +): IAccessAttribute | null { // Extended exit const extendedLastLeg = isRideLeg(leg) ? (leg as PtRideLeg)?.serviceJourney?.notices?.filter((notice) => @@ -87,8 +96,10 @@ function getLastExtendedLegAttribute(leg: Leg, arrivalWalk: number): IAccessAttr return extendedLastLeg ? { duration: (extractTimeAndString?.duration || 0) + (arrivalWalk || 0), - text: extractTimeAndString?.text || '', - icon: `sa-${extendedLastLeg?.name?.toLowerCase()}`, + text: a11yFootpath + ? i18nWalkingDistanceArrival[currentLanguage] + : extractTimeAndString?.text || '', + icon: a11yFootpath ? 'wheelchair-small' : `sa-${extendedLastLeg?.name?.toLowerCase()}`, } : null; } @@ -104,7 +115,7 @@ function renderTransferTime( type?: 'departure' | 'arrival', ): TemplateResult { return html` - +