UNPKG

@prezly/theme-kit-core

Version:

Data layer and utility library for developing Prezly themes with JavaScript

39 lines 2.01 kB
import { matchLocaleSlug } from "./matchLocaleSlug.mjs"; describe('matchLocaleSlug', () => { it('should match enabled locales by full locale slug', () => { var locales = ['nl_BE', 'nl_NL', 'en']; expect(matchLocaleSlug('nl-be', locales)).toBe('nl_BE'); expect(matchLocaleSlug('nl-nl', locales)).toBe('nl_NL'); expect(matchLocaleSlug('en', locales)).toBe('en'); }); it('should return undefined if no active locale matches locale slug', () => { var locales = ['nl_BE', 'nl_NL', 'en']; expect(matchLocaleSlug('fr-be', locales)).toBeUndefined(); expect(matchLocaleSlug('en-us', locales)).toBeUndefined(); expect(matchLocaleSlug('de-de', locales)).toBeUndefined(); }); it('should match locale by lang code slug', () => { var locales = ['nl_BE', 'en_US', 'fr_BE']; expect(matchLocaleSlug('nl', locales)).toBe('nl_BE'); expect(matchLocaleSlug('fr', locales)).toBe('fr_BE'); expect(matchLocaleSlug('en', locales)).toBe('en_US'); }); it('should match locale by region code slug', () => { var locales = ['nl_BE', 'en_GB', 'en_US']; expect(matchLocaleSlug('be', locales)).toBe('nl_BE'); expect(matchLocaleSlug('gb', locales)).toBe('en_GB'); expect(matchLocaleSlug('us', locales)).toBe('en_US'); }); it('should never match locale by number-only region code slug', () => { var locales = ['es_ES', 'es_419']; expect(matchLocaleSlug('419', locales)).toBeUndefined(); }); it('should pick locale in the given order of preference if multiple match against th shortened lang code', () => { expect(matchLocaleSlug('en', ['en_GB', 'en_US', 'nl_BE'])).toBe('en_GB'); expect(matchLocaleSlug('en', ['nl_BE', 'en_US', 'en_GB'])).toBe('en_US'); }); it('should pick locale in the given order of preference if multiple match against th shortened region code', () => { expect(matchLocaleSlug('be', ['nl_BE', 'fr_BE', 'en_GB'])).toBe('nl_BE'); expect(matchLocaleSlug('be', ['en_GB', 'fr_BE', 'nl_BE'])).toBe('fr_BE'); }); });