mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-28 14:17:10 +01:00
Dates were rendered with the browser locale, ignoring the language chosen in Personal settings, so a user browsing in German still saw US-style dates. All date rendering now resolves its locale through a useDateLocale hook that returns the selected language, augmented with the region from navigator.languages when the language carries none (Intl reads a bare "en" as en-US). Applied to DateField, the rated/loved tooltips, the mobile user list and album release dates; the three inline timestamp tooltips now share a formatDateTime helper. Closes #229
32 lines
1,013 B
JavaScript
32 lines
1,013 B
JavaScript
import React from 'react'
|
|
import { render, screen } from '@testing-library/react'
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
import { DateField } from './DateField'
|
|
|
|
vi.mock('react-admin', async (importOriginal) => ({
|
|
...(await importOriginal()),
|
|
useLocale: vi.fn(),
|
|
}))
|
|
|
|
describe('<DateField>', () => {
|
|
const record = { id: '1', updatedAt: '2026-09-17T14:30:00Z' }
|
|
|
|
beforeEach(async () => {
|
|
vi.clearAllMocks()
|
|
vi.spyOn(navigator, 'languages', 'get').mockReturnValue([])
|
|
const { useLocale } = await import('react-admin')
|
|
vi.mocked(useLocale).mockReturnValue('de')
|
|
})
|
|
|
|
it('formats the date using the selected language', () => {
|
|
render(<DateField record={record} source="updatedAt" />)
|
|
expect(screen.getByText('17.9.2026')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders nothing when the date is not set', () => {
|
|
const { container } = render(
|
|
<DateField record={{ id: '1' }} source="updatedAt" />,
|
|
)
|
|
expect(container).toBeEmptyDOMElement()
|
|
})
|
|
})
|