import { internalPathToPageKey, resolveCtaHref } from './cta-link' describe('resolveCtaHref (MITHOME-123)', () => { // Exploration: a CTA pointing at an internal page must follow the locale // routing (MITHOME-114) — the legacy free-text "/kapcsolat" was a 404. it.each([ ['hu', '/hu/kapcsolat'], ['en', '/en/contact'], ] as const)('should link a contact-page CTA to the %s contact page', (locale, expected) => { expect(resolveCtaHref({ linkType: 'page', page: 'contact' }, locale)).toBe(expected) }) it('should link a home-page CTA to the locale home', () => { expect(resolveCtaHref({ linkType: 'page', page: 'home' }, 'en')).toBe('/en') }) // Preservation: external links (e.g. webmail) keep their stored URL. it('should keep the stored URL for external links', () => { expect(resolveCtaHref({ linkType: 'url', href: 'https://mail.mozdit.hu' }, 'en')).toBe('https://mail.mozdit.hu') }) it('should treat a record without linkType as a URL link (pre-migration data)', () => { expect(resolveCtaHref({ href: 'https://mail.mozdit.hu' }, 'hu')).toBe('https://mail.mozdit.hu') }) it('should fall back to the locale home when a page link has no page selected', () => { expect(resolveCtaHref({ linkType: 'page', page: null }, 'hu')).toBe('/hu') }) }) describe('internalPathToPageKey', () => { it.each([ ['/kapcsolat', 'contact'], ['/hu/kapcsolat', 'contact'], ['/en/contact', 'contact'], ['/hu/rolunk/', 'about'], ['/', 'home'], ['/hu', 'home'], ['/en', 'home'], ])('should map %s to %s', (path, key) => { expect(internalPathToPageKey(path)).toBe(key) }) it.each(['https://mail.mozdit.hu', '/nincs-ilyen', '/hu/kapcsolat/extra', 'mailto:info@mozdit.hu', ''])( 'should not map %s', (path) => { expect(internalPathToPageKey(path)).toBeUndefined() }, ) })