UNPKG

@prezly/theme-kit-core

Version:

Data layer and utility library for developing Prezly themes with JavaScript

41 lines (40 loc) 2.4 kB
"use strict"; var _matchLocaleSlug = require("./matchLocaleSlug.cjs"); describe('matchLocaleSlug', () => { it('should match enabled locales by full locale slug', () => { var locales = ['nl_BE', 'nl_NL', 'en']; expect((0, _matchLocaleSlug.matchLocaleSlug)('nl-be', locales)).toBe('nl_BE'); expect((0, _matchLocaleSlug.matchLocaleSlug)('nl-nl', locales)).toBe('nl_NL'); expect((0, _matchLocaleSlug.matchLocaleSlug)('en', locales)).toBe('en'); }); it('should return undefined if no active locale matches locale slug', () => { var locales = ['nl_BE', 'nl_NL', 'en']; expect((0, _matchLocaleSlug.matchLocaleSlug)('fr-be', locales)).toBeUndefined(); expect((0, _matchLocaleSlug.matchLocaleSlug)('en-us', locales)).toBeUndefined(); expect((0, _matchLocaleSlug.matchLocaleSlug)('de-de', locales)).toBeUndefined(); }); it('should match locale by lang code slug', () => { var locales = ['nl_BE', 'en_US', 'fr_BE']; expect((0, _matchLocaleSlug.matchLocaleSlug)('nl', locales)).toBe('nl_BE'); expect((0, _matchLocaleSlug.matchLocaleSlug)('fr', locales)).toBe('fr_BE'); expect((0, _matchLocaleSlug.matchLocaleSlug)('en', locales)).toBe('en_US'); }); it('should match locale by region code slug', () => { var locales = ['nl_BE', 'en_GB', 'en_US']; expect((0, _matchLocaleSlug.matchLocaleSlug)('be', locales)).toBe('nl_BE'); expect((0, _matchLocaleSlug.matchLocaleSlug)('gb', locales)).toBe('en_GB'); expect((0, _matchLocaleSlug.matchLocaleSlug)('us', locales)).toBe('en_US'); }); it('should never match locale by number-only region code slug', () => { var locales = ['es_ES', 'es_419']; expect((0, _matchLocaleSlug.matchLocaleSlug)('419', locales)).toBeUndefined(); }); it('should pick locale in the given order of preference if multiple match against th shortened lang code', () => { expect((0, _matchLocaleSlug.matchLocaleSlug)('en', ['en_GB', 'en_US', 'nl_BE'])).toBe('en_GB'); expect((0, _matchLocaleSlug.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((0, _matchLocaleSlug.matchLocaleSlug)('be', ['nl_BE', 'fr_BE', 'en_GB'])).toBe('nl_BE'); expect((0, _matchLocaleSlug.matchLocaleSlug)('be', ['en_GB', 'fr_BE', 'nl_BE'])).toBe('fr_BE'); }); });