_label` sibling when key has no _id suffix', () => {
render(
)
openPopover('1 item')
expect(screen.getByRole('cell', { name: 'Balanceo' })).toBeTruthy()
})
it('accepts a bare string sibling for a ref field', () => {
render(
)
openPopover('1 item')
expect(screen.getByRole('cell', { name: 'Aceite 5W30' })).toBeTruthy()
})
it('falls back to a truncated uuid when the ref sibling is missing', () => {
render(
)
openPopover('1 item')
expect(screen.getByRole('cell', { name: '550e8400…' })).toBeTruthy()
})
it('keeps the locale-aware count noun on the badge', () => {
render(
)
expect(screen.getByText('2 ítems')).toBeTruthy()
})
it('renders non-ref fields via formatScalar under the schema header', () => {
render(
)
openPopover('1 item')
expect(screen.getByRole('cell', { name: '7' })).toBeTruthy()
})
it('mirrors the schema labels + resolved ref values in the badge title', () => {
render(
)
const title =
screen.getByText('1 item').closest('[title]')!.getAttribute('title') ?? ''
expect(title).toContain('Producto: Llanta 195/65')
expect(title).toContain('Cantidad: 2')
expect(title).not.toContain('550e8400')
})
it('is unchanged (generic prettify) when no itemFields are provided', () => {
render(
)
// Generic dict path: the badge title carries the prettified headers and
// the raw (unresolved) values, exactly as before.
const title =
screen.getByText('1 ítem').closest('[title]')!.getAttribute('title') ?? ''
expect(title).toContain('Producto:')
expect(title).toContain('Cantidad: 2')
})
})
describe('CollectionCell variant="inline" (detail view)', () => {
const itemFields = [
{ key: 'product_id', label: 'Producto', ref: 'Product' },
{ key: 'quantity', label: 'Cantidad' },
]
it('renders the mini-table DIRECTLY with no popover trigger / badge', () => {
render(
)
// The table is in the DOM immediately — no click needed.
expect(screen.getByRole('table')).toBeTruthy()
// No count-badge trigger ("1 item") is rendered in inline mode.
expect(screen.queryByText('1 item')).toBeNull()
})
it('uses localized schema headers + resolved ref labels (no raw uuid/JSON)', () => {
const { container } = render(
)
// "Producto | Cantidad / Test | 10"
expect(screen.getByRole('columnheader', { name: 'Producto' })).toBeTruthy()
expect(screen.getByRole('columnheader', { name: 'Cantidad' })).toBeTruthy()
expect(screen.getByRole('cell', { name: 'Test' })).toBeTruthy()
expect(screen.getByRole('cell', { name: '10' })).toBeTruthy()
// The raw uuid must not leak, and there is no JSON.stringify block.
expect(screen.queryByText('550e8400…')).toBeNull()
expect(container.querySelector('pre')).toBeNull()
expect(container.textContent).not.toContain('550e8400-e29b')
})
it('falls back to a generic localized mini-table when no itemFields (no raw JSON)', () => {
const { container } = render(
)
// Generic dict path still drives the header; no JSON dump.
expect(screen.getByRole('columnheader', { name: 'Producto' })).toBeTruthy()
expect(screen.getByRole('cell', { name: '2' })).toBeTruthy()
expect(container.querySelector('pre')).toBeNull()
})
it('renders a plain object as an inline localized pair list (no popover)', () => {
render(
)
// Pair list is rendered directly; the badge "+N" preview is not used.
expect(screen.getByText('Precio:')).toBeTruthy()
expect(screen.getByText('Cantidad:')).toBeTruthy()
expect(screen.queryByRole('table')).toBeNull()
})
it('renders a scalar array as an inline list directly', () => {
render(
)
// Full list, no "+2" overflow badge.
expect(screen.getByText('e')).toBeTruthy()
expect(screen.queryByText('a, b, c +2')).toBeNull()
})
it('keeps the muted dash for empty / null values', () => {
const { container: empty } = render(
)
expect(empty.textContent).toBe('-')
const { container: nul } = render(
)
expect(nul.textContent).toBe('-')
})
})