mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
Merge pull request #442 from nwparker/cloud/reg4-clock-locale
Test: worktree-creation clock's German format follows the runtime's CLDR (REG-4)
This commit is contained in:
@@ -8,12 +8,33 @@ afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
type RuntimeDurationFormat = new (
|
||||
locale: string,
|
||||
options: Record<string, string>
|
||||
) => { format: (duration: Record<string, number>) => string }
|
||||
|
||||
function runtimeNarrowDuration(locale: string, duration: Record<string, number>): 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', () => {
|
||||
|
||||
Reference in New Issue
Block a user