Sifa professional network frontend (Next.js, React, TailwindCSS) sifa.id/
at main 55 lines 1.8 kB view raw
1import { describe, it, expect } from 'vitest'; 2import { getPlatformInfo, PLATFORM_OPTIONS, getFaviconUrl } from '@/lib/platforms'; 3 4describe('getPlatformInfo', () => { 5 it('returns correct info for known platforms', () => { 6 expect(getPlatformInfo('github').label).toBe('GitHub'); 7 expect(getPlatformInfo('fediverse').label).toBe('Fediverse'); 8 expect(getPlatformInfo('website').label).toBe('Website'); 9 expect(getPlatformInfo('rss').label).toBe('RSS'); 10 }); 11 12 it('returns website fallback for unknown platforms', () => { 13 const info = getPlatformInfo('unknown'); 14 expect(info.label).toBe('Website'); 15 expect(info.icon).toBeDefined(); 16 }); 17 18 it('maps legacy "other" platform to website', () => { 19 const info = getPlatformInfo('other'); 20 expect(info.label).toBe('Website'); 21 }); 22}); 23 24describe('PLATFORM_OPTIONS', () => { 25 it('contains all expected platforms', () => { 26 const values = PLATFORM_OPTIONS.map((o) => o.value); 27 expect(values).toContain('github'); 28 expect(values).toContain('fediverse'); 29 expect(values).toContain('twitter'); 30 expect(values).toContain('website'); 31 expect(values).toContain('rss'); 32 }); 33 34 it('does not contain legacy "other" option', () => { 35 const values = PLATFORM_OPTIONS.map((o) => o.value); 36 expect(values).not.toContain('other'); 37 }); 38 39 it('has labels for all options', () => { 40 for (const opt of PLATFORM_OPTIONS) { 41 expect(opt.label).toBeTruthy(); 42 } 43 }); 44}); 45 46describe('getFaviconUrl', () => { 47 it('returns a Google favicon URL for valid URLs', () => { 48 const result = getFaviconUrl('https://example.com/page'); 49 expect(result).toBe('https://www.google.com/s2/favicons?domain=example.com&sz=32'); 50 }); 51 52 it('returns null for invalid URLs', () => { 53 expect(getFaviconUrl('not-a-url')).toBeNull(); 54 }); 55});