navidrome/ui/src/common/DateField.test.jsx
Deluan Quintão be8ec15168
feat(ui): format dates using the selected language (#6160)
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
2026-09-19 14:07:42 -04:00

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()
})
})