import { describe, it, expect } from 'vitest'; import { groupCategoriesByFirstLetter } from '../group-categories-by-first-letter'; const items = [ { title: 'Amateur', name: 'amateur', videosCount: 10, guid: '1', icon: '', is_top: false }, { title: 'Anal', name: 'anal', videosCount: 5, guid: '2', icon: '', is_top: true }, { title: 'Big Tits', name: 'big-tits', videosCount: 20, guid: '3', icon: '', is_top: false }, { title: '69', name: '69', videosCount: 8, guid: '4', icon: '', is_top: false }, ]; describe('groupCategoriesByFirstLetter', () => { it('группирует по первой букве title', () => { const result = groupCategoriesByFirstLetter(items as any, 'title', 'en'); expect(Object.keys(result)).toContain('A'); expect(Object.keys(result)).toContain('B'); expect(result['A']).toHaveLength(2); expect(result['B']).toHaveLength(1); }); it('цифры попадают в POST', () => { const result = groupCategoriesByFirstLetter(items as any, 'title', 'en'); expect(result['POST']).toHaveLength(1); expect(result['POST'][0].name).toBe('69'); }); it('кастомный nonLetterKey', () => { const result = groupCategoriesByFirstLetter(items as any, 'title', 'en', 'OTHER'); expect(result['OTHER']).toHaveLength(1); }); it('POST ключ идёт последним', () => { const result = groupCategoriesByFirstLetter(items as any, 'title', 'en'); const keys = Object.keys(result); expect(keys[keys.length - 1]).toBe('POST'); }); it('пустой массив', () => { const result = groupCategoriesByFirstLetter([], 'title', 'en'); expect(result).toEqual({}); }); it('не массив → пустой результат', () => { const result = groupCategoriesByFirstLetter(null as any, 'title', 'en'); expect(result).toEqual({}); }); });