diff --git a/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts b/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts index 675bbe909ba..03703a9b4a4 100644 --- a/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts +++ b/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts @@ -8,12 +8,33 @@ afterEach(() => { vi.unstubAllGlobals() }) +type RuntimeDurationFormat = new ( + locale: string, + options: Record +) => { format: (duration: Record) => string } + +function runtimeNarrowDuration(locale: string, duration: Record): string { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the TS lib lacks Intl.DurationFormat; every runtime these tests run on has it. + const DurationFormat = (Intl as unknown as { DurationFormat: RuntimeDurationFormat }) + .DurationFormat + return new DurationFormat(locale, { + style: 'narrow', + secondsDisplay: 'always', + minutesDisplay: 'auto' + }).format({ hours: 0, ...duration }) +} + describe('formatElapsedTime', () => { it('formats with Intl in the given locale and keeps minutes once past an hour', () => { expect(formatElapsedTime(5_000, 'en')).toBe('5s') expect(formatElapsedTime(125_000, 'en')).toBe('2m 5s') expect(formatElapsedTime(3_605_000, 'en')).toBe('1h 0m 5s') - expect(formatElapsedTime(125_000, 'de')).toBe('2 Min., 5 Sek.') + // German goes through the runtime's own Intl.DurationFormat, not the English fallback. The exact + // words are CLDR data and differ by engine (V8/Electron: "2 Min., 5 Sek.", Bun/JSC: "2min 5s"), + // so the test compares with the runtime instead of pinning one engine's string (REG-4). + const german = formatElapsedTime(125_000, 'de') + expect(german).toBe(runtimeNarrowDuration('de', { minutes: 2, seconds: 5 })) + expect(german).not.toBe('2m 5s') }) it('falls back to the same English shape where Intl.DurationFormat is missing', () => {