// @vitest-environment happy-dom
//
// Detail-view wiring: the read-only "Información detallada del registro" dialog
// renders jsonb line-items through `ViewValue` → `StructuredViewValue` →
// `CollectionCell variant="inline"`. This locks in the regression fix: the
// detail view no longer dumps raw `JSON.stringify`, and an `item_fields` schema
// drives localized headers + resolved ref labels (the injected `{value,label}`
// sibling) — "Producto | Cantidad / Test | 10".
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
// Identity translator + a Spanish locale, matching the host dialog.
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (k: string) => k, i18n: { language: 'es' } }),
}))
import { ViewValue } from '../dialogs/dynamic-record'
afterEach(cleanup)
describe('detail-view jsonb line-items (ViewValue → inline CollectionCell)', () => {
const itemFields = [
{ key: 'product_id', label: 'Producto', ref: 'Product' },
{ key: 'quantity', label: 'Cantidad' },
]
it('renders the schema mini-table with resolved ref labels, not raw JSON', () => {
const { container } = render(
.
expect(screen.getByRole('columnheader', { name: 'Producto' })).toBeTruthy()
expect(container.querySelector('pre')).toBeNull()
})
it('renders a plain jsonb object as a localized pair list (not [object Object])', () => {
const { container } = render(
)
expect(screen.getByText('Precio:')).toBeTruthy()
expect(container.textContent).not.toContain('[object Object]')
})
it('keeps the "—" empty marker for an empty array', () => {
const { container } = render(
)
expect(container.textContent).toContain('—')
})
})