UNPKG

@prezly/theme-kit-core

Version:

Data layer and utility library for developing Prezly themes with JavaScript

42 lines 1.36 kB
import { generateUrlFromPattern } from "./generateUrlFromPattern.mjs"; describe('generateUrlFromPattern', () => { it('should generate a URL (without context)', () => { var href = generateUrlFromPattern('/:localeCode/media', { localeCode: 'en' }); expect(href).toBe('/en/media'); }); it('should generate a URL with optional variables (without context)', () => { var href = generateUrlFromPattern('/(:localeSlug/)media', { localeSlug: '' }); expect(href).toBe('/media'); }); it('should generate a URL based on the current locale', () => { var href = generateUrlFromPattern('/(:localeSlug/)media', { localeCode: 'fr' }, { defaultLocale: 'en', locales: ['en', 'nl', 'fr'] }); expect(href).toBe('/fr/media'); }); it('should generate a homepage URL based on the current locale', () => { var href = generateUrlFromPattern('/(:localeSlug/)media', { localeCode: 'en' }, { defaultLocale: 'en', locales: ['en', 'nl', 'fr'] }); expect(href).toBe('/media'); }); it('should generate a shortest possible locale slug', () => { var href = generateUrlFromPattern('/(:localeSlug/)media', { localeCode: 'nl_BE' }, { defaultLocale: 'en_US', locales: ['en_US', 'nl_BE', 'fr_FR'] }); expect(href).toBe('/nl/media'); }); });