fix(cms): resolve internal CTA links per locale via a page selector (MITHOME-123)
The home hero CTA stored a free-text href "/kapcsolat" that predated the locale-prefixed routing (MITHOME-114), so the main call-to-action led to a 404. Internal targets were typed by hand and could never follow the locale or its translated slug. CTA links now choose between an internal page (home/about/services/ contact/privacy/terms) and an external URL. Page links are resolved per request with localePath(), giving /hu/kapcsolat and /en/contact; external links (webmail) keep their localized href. A Payload migration converts existing internal paths to page links on the published global and every draft/version, idempotently and independent of the locale migration's order. The global-doc iteration shared with MITHOME-111 moved to src/lib/migrate-global-docs.ts; the JSON seed emits the new shape too. Verified on a copy of the staging DB: both migrations ran on startup, /hu and /en CTAs point to their contact pages (200), webmail unchanged, admin shows the selector, toggles the fields and blocks publishing a URL link without a URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
38d34fab4c
commit
e8ff7adeb5
@@ -0,0 +1,50 @@
|
||||
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()
|
||||
},
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user