You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sims-hq/packages/ui/test/avatar.test.ts

36 lines
1.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { avatarColors, avatarHue, initials } from '../src/avatar'
describe('initials', () => {
it('takes the first letter of the first two words', () => {
expect(initials('Acme UK Compliance Group')).toBe('AU')
expect(initials('hamiltel')).toBe('H')
})
it('falls back to ? for empty input', () => {
expect(initials('')).toBe('?')
expect(initials(' ')).toBe('?')
})
})
describe('avatarHue', () => {
it('is deterministic', () => {
expect(avatarHue('Hamiltel')).toBe(avatarHue('Hamiltel'))
})
it('stays in [0, 360)', () => {
for (const n of ['a', 'Acme', 'Zed Systems', '৪২']) {
const h = avatarHue(n)
expect(h).toBeGreaterThanOrEqual(0)
expect(h).toBeLessThan(360)
}
})
})
describe('avatarColors', () => {
it('returns hsl strings derived from the hue', () => {
const { bg, fg } = avatarColors('Hamiltel')
const h = avatarHue('Hamiltel')
expect(bg).toContain(`hsl(${h}`)
expect(fg).toContain(`hsl(${h}`)
})
})