Skip to content

Commit daba366

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(ui): cover avatar fallback size composition
1 parent 4f498b2 commit daba366

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/** @vitest-environment jsdom */
2+
import { act } from 'react'
3+
import { createRoot, type Root } from 'react-dom/client'
4+
import { afterEach, describe, expect, it } from 'vitest'
5+
import { Avatar, AvatarFallback } from './avatar'
6+
7+
let root: Root | undefined
8+
let container: HTMLDivElement | undefined
9+
10+
afterEach(() => {
11+
act(() => root?.unmount())
12+
container?.remove()
13+
})
14+
15+
describe('Avatar fallback sizing', () => {
16+
it('scopes xs sizing to its avatar while preserving explicit overrides', () => {
17+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
18+
container = document.createElement('div')
19+
document.body.appendChild(container)
20+
root = createRoot(container)
21+
act(() =>
22+
root?.render(
23+
<>
24+
<Avatar size='xs'>
25+
<AvatarFallback data-testid='xs'>A</AvatarFallback>
26+
</Avatar>
27+
<Avatar>
28+
<AvatarFallback data-testid='default'>BC</AvatarFallback>
29+
</Avatar>
30+
<Avatar size='xs'>
31+
<AvatarFallback data-testid='override' className='text-[7px]'>
32+
D
33+
</AvatarFallback>
34+
</Avatar>
35+
</>
36+
)
37+
)
38+
const xs = container.querySelector('[data-testid="xs"]')!
39+
const regular = container.querySelector('[data-testid="default"]')!
40+
const overridden = container.querySelector('[data-testid="override"]')!
41+
expect(xs.classList.contains('text-[8px]')).toBe(true)
42+
expect(xs.classList.contains('text-xs')).toBe(false)
43+
expect(regular.classList.contains('text-xs')).toBe(true)
44+
expect(regular.classList.contains('text-[8px]')).toBe(false)
45+
expect(overridden.classList.contains('text-[7px]')).toBe(true)
46+
expect(overridden.classList.contains('text-[8px]')).toBe(false)
47+
expect(overridden.classList.contains('text-xs')).toBe(false)
48+
})
49+
})

0 commit comments

Comments
 (0)