From 270f7bf4a6b77798df4ab1e1086047523609b018 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Tue, 10 Sep 2019 18:02:35 +0200 Subject: [PATCH] Add tests --- src/components/Locale/Locale.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/components/Locale/Locale.test.ts diff --git a/src/components/Locale/Locale.test.ts b/src/components/Locale/Locale.test.ts new file mode 100644 index 000000000..082a9a1e3 --- /dev/null +++ b/src/components/Locale/Locale.test.ts @@ -0,0 +1,25 @@ +import { getMatchingLocale, Locale } from "./Locale"; + +describe("Matches locale to browser settings", () => { + it("if first language is an exact match", () => { + const locales = ["fr", "es", "en"]; + + expect(getMatchingLocale(locales)).toBe(Locale.FR); + }); + + it("if there is an exact match, but it's not first preference", () => { + const locales = ["does-not-exist", "tr", "de", "fr"]; + + expect(getMatchingLocale(locales)).toBe(Locale.TR); + }); + + it("or returns undefined if there is no match", () => { + const locales = [ + "does-not-exist-1", + "does-not-exist-2", + "does-not-exist-3" + ]; + + expect(getMatchingLocale(locales)).toBe(undefined); + }); +});