import { describe, expect, it } from 'vitest'
import { renderWithProviders, screen } from '../../../test/utils'
import Bubble from './Bubble'
describe('Bubble', () => {
it.each([
[undefined, false],
[null, false],
['', false],
['caption', true],
[0, true],
])('renders caption %j according to its value', (text, present) => {
renderWithProviders(
child
)
const bubble = screen.getByTestId('bubble')
if (present) expect(bubble.querySelector('p')).not.toBeNull()
else expect(bubble.querySelector('p')).toBeNull()
expect(bubble).toHaveClass(present ? 'pb-0' : 'py-2')
})
it('maps variants, group positions, borders, and forwarded content', () => {
const { rerender } = renderWithProviders(
child
)
let bubble = screen.getByTestId('bubble')
expect(bubble).toHaveAttribute('data-group-position', 'middle')
expect(bubble).toHaveClass('custom')
expect(bubble).toHaveTextContent('child')
const darkMiddle = bubble.className
rerender(
child
)
bubble = screen.getByTestId('bubble')
const lightMiddle = bubble.className
expect(lightMiddle).not.toBe(darkMiddle)
rerender(
child
)
bubble = screen.getByTestId('bubble')
expect(bubble.className).not.toBe(lightMiddle)
const lightFirstBordered = bubble.className
rerender(
child
)
bubble = screen.getByTestId('bubble')
const lightFirstBorderless = bubble.className
expect(lightFirstBorderless).not.toBe(lightFirstBordered)
expect(lightFirstBordered.split(/\s+/)).toEqual(
expect.arrayContaining(lightFirstBorderless.split(/\s+/))
)
})
it('lets an explicit radius replace the group corner table', () => {
const radiusClassName = 'rounded-[20px]'
const widthClassName = 'w-fit'
const paddingClassName = 'p-0.5'
renderWithProviders(
child
)
const bubble = screen.getByTestId('bubble')
expect(bubble).toHaveClass(radiusClassName, widthClassName)
expect(bubble).toHaveClass(paddingClassName)
expect(bubble.className).not.toMatch(/rounded-tl-\[4px\]/)
})
})