import { describe, expect, it } from 'vitest' import { attributesFromGenerator, hexToBucket, type GeneratorRecord } from './attributes.js' function gen(layers: Array<[string, string, string?]>, extra: Partial = {}): GeneratorRecord { return { bodyType: 'male', layers: layers.map(([id, title, main]) => ({ id, title, colors: main ? { main } : undefined })), ...extra, } } describe('hexToBucket', () => { it('buckets colours into named families', () => { expect(hexToBucket('#60974d')).toBe('green') expect(hexToBucket('#c71585')).toBe('pink') expect(hexToBucket('#101012')).toBe('black') expect(hexToBucket('#f2f2f2')).toBe('white') expect(hexToBucket('#634f30')).toBe('brown') expect(hexToBucket('not-a-hex')).toBeUndefined() expect(hexToBucket(undefined)).toBeUndefined() }) }) describe('attributesFromGenerator', () => { it('splits worn vs held, drops base layers, buckets colour', () => { const attrs = attributesFromGenerator( 'did:plc:a', 'Aria', gen([ ['body', 'Male Body', '#916241'], ['undies', 'Just Undies'], ['tops', 'Basic Shirt', '#60974d'], ['headwear', 'Hard Hat', '#ffcc00'], ['righthand', 'Game Controller', '#000000'], ]), ) expect(attrs).not.toBeNull() expect(attrs!.worn.map((t) => t.category).sort()).toEqual(['headwear', 'tops']) expect(attrs!.held.map((t) => t.title)).toEqual(['Game Controller']) expect(attrs!.worn.find((t) => t.category === 'tops')!.colorBucket).toBe('green') }) it('returns null for a generator with no clue-worthy layers', () => { expect(attributesFromGenerator('did:plc:x', 'X', gen([['body', 'Male Body'], ['undies', 'Just Undies']]))).toBeNull() }) it('buckets natural skin by lightness, fantasy skin by hue', () => { const skin = (hex: string) => attributesFromGenerator('did:plc:s', 'S', gen([['tops', 'Shirt', '#60974d']], { skin: { hex } }))!.skinBucket // natural, "roughly orange" tones → fair/light/tan/dark expect(skin('#f1d2b8')).toBe('fair') expect(skin('#916241')).toBe('tan') expect(skin('#3a2a1e')).toBe('dark') // vivid fantasy tints → named by colour family expect(skin('#2ecc71')).toBe('green') // orc expect(skin('#3050c0')).toBe('blue') expect(skin('#7d3cab')).toBe('purple') // tiefling }) })