import { describe, expect, it } from 'vitest'; import { classifyDirectory, groupArchiveDirectories } from './archive-grouping'; describe('classifyDirectory', () => { it('treats a bare profile directory as the base', () => { expect(classifyDirectory('0ct0ber19')).toEqual({ owner: '0ct0ber19', source: { kind: 'posts', dir: '0ct0ber19' }, }); }); it('recognises a reels sidecar', () => { expect(classifyDirectory('0ct0ber19 - reels')).toEqual({ owner: '0ct0ber19', source: { kind: 'reels', dir: '0ct0ber19 - reels' }, }); }); it('recognises a stories sidecar', () => { expect(classifyDirectory('story - cher_ryppo')).toEqual({ owner: 'cher_ryppo', source: { kind: 'stories', dir: 'story - cher_ryppo' }, }); }); it('splits highlight owner from title', () => { const { owner, source } = classifyDirectory('story highlights - 0ct0ber19 - Heestory'); expect(owner).toBe('0ct0ber19'); expect(source.kind).toBe('highlight'); expect(source.title).toBe('Heestory'); }); it.each([ ['story highlights - theoldtaylorswiftinsta - đź’™2014-1989 era', 'theoldtaylorswiftinsta', 'đź’™2014-1989 era'], ['story highlights - heejin_theworld - [Dall]', 'heejin_theworld', '[Dall]'], ['story highlights - official_artms - Cosmo Schedule', 'official_artms', 'Cosmo Schedule'], ['story highlights - 0ct0ber19 - Drawheeingâ €', '0ct0ber19', 'Drawheeingâ €'], ['story highlights - official_artms - G.C.I', 'official_artms', 'G.C.I'], ])('handles real-world title %s', (dir, owner, title) => { const result = classifyDirectory(dir); expect(result.owner).toBe(owner); expect(result.source.title).toBe(title); }); it('keeps titles containing " - " intact', () => { // The username is matched as a non-space run, so only the first separator // splits owner from title. const { owner, source } = classifyDirectory('story highlights - user - a - b'); expect(owner).toBe('user'); expect(source.title).toBe('a - b'); }); it('does not mistake a profile with spaces for a sidecar', () => { expect(classifyDirectory('Heejin_Bubble heejinmedia').source.kind).toBe('posts'); }); }); describe('groupArchiveDirectories', () => { const dirs = [ '0ct0ber19', '0ct0ber19 - reels', 'story - 0ct0ber19', 'story highlights - 0ct0ber19 - Heestory', 'story highlights - 0ct0ber19 - Drawheeingâ €', 'carlyraejepsen', ]; it('folds sidecars into their base profile', () => { const groups = groupArchiveDirectories(dirs); expect([...groups.keys()].sort()).toEqual(['0ct0ber19', 'carlyraejepsen']); expect(groups.get('0ct0ber19')).toHaveLength(5); expect(groups.get('carlyraejepsen')).toHaveLength(1); }); it('orders sources posts, reels, stories, then highlights by title', () => { const sources = groupArchiveDirectories(dirs).get('0ct0ber19')!; expect(sources.map(s => s.kind)).toEqual(['posts', 'reels', 'stories', 'highlight', 'highlight']); expect(sources.slice(3).map(s => s.title)).toEqual(['Drawheeingâ €', 'Heestory']); }); it('still groups a sidecar whose base profile is missing', () => { const groups = groupArchiveDirectories(['story - orphan']); expect(groups.get('orphan')).toEqual([{ kind: 'stories', dir: 'story - orphan' }]); }); it('is stable for an empty archive root', () => { expect(groupArchiveDirectories([]).size).toBe(0); }); });