Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

1.8 KB
Raw Blame
import { describe, expect, it } from "vite-plus/test";
import {
	getLocaleAlternates,
	getPreferredLocale,
	isLocale,
	localeSchema,
	localizedUrl,
	supportedLocales,
} from "./locale";

it.each([
	[["de-DE"], "de-DE"],
	[["unsupported", "fr-CA", "de-DE"], "fr-FR"],
	[["de-AT", "fr-FR"], "de-DE"],
	[["de-de"], "de-DE"],
	[["de"], "de-DE"],
	[["en-GB", "en-US"], "en-GB"],
	[["pt-PT", "pt-BR"], "pt-PT"],
	[["zh-TW", "zh-CN"], "zh-TW"],
	[["zu-ZA", "de-DE"], "de-DE"],
	[["zu-ZA"], "en-US"],
	[["unsupported"], "en-US"],
	[[], "en-US"],
])("matches ordered language preferences %j to %s", (languages, expected) => {
	expect(getPreferredLocale(languages)).toBe(expected);
});

it("keeps the testing catalog valid without counting it as a supported translation", () => {
	expect(isLocale("zu-ZA")).toBe(true);
	expect(localeSchema.options).toContain("zu-ZA");
	expect(supportedLocales).not.toContain("zu-ZA");
	expect(supportedLocales).toContain("de-DE");
	expect(getLocaleAlternates("https://rxresu.me/")).toHaveLength(supportedLocales.length + 1);
});

describe("locale URLs", () => {
	it("keeps the default locale on the plain address and puts others in the locale parameter", () => {
		expect(localizedUrl("https://rxresu.me/?locale=de-DE", "en-US")).toBe("https://rxresu.me/");
		expect(localizedUrl("https://rxresu.me/", "de-DE")).toBe("https://rxresu.me/?locale=de-DE");
	});

	it("lists valid hreflang alternates without the pseudo-locale", () => {
		const alternates = getLocaleAlternates("https://rxresu.me/");

		expect(alternates).toContainEqual({ hreflang: "x-default", href: "https://rxresu.me/" });
		expect(alternates).toContainEqual({ hreflang: "sr", href: "https://rxresu.me/?locale=sr-SP" });
		expect(alternates.map((alternate) => alternate.hreflang)).not.toContain("zu-ZA");
	});
});