Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Oct 8, 2024
1 parent 45bf9be commit 1b6542f
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/record/src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { expFormat } from "./utils";
import Yaml from "js-yaml";
import en_us from "../i18n/en-us.yaml";
import eu from "../i18n/eu.yaml";
import fr from "../i18n/fr.yaml";
import hu from "../i18n/hu.yaml";
import it from "../i18n/it.yaml";
import ja from "../i18n/ja.yaml";
import nl from "../i18n/nl.yaml";
import pt_br from "../i18n/pt-br.yaml";
import pt from "../i18n/pt.yaml";
import { TranslationNotFoundError } from "./errors";
import { expFormat, getTranslation } from "./utils";

test("expFormat convert written text to format well in HTML", () => {
expect(expFormat("abcdefg")).toStrictEqual("abcdefg");
Expand All @@ -18,3 +29,27 @@ test("expFormat convert written text to format well in HTML", () => {
"    Tabbed text",
);
});

test("Get translation file for specified locale", () => {
const translations = {
ja,
pt,
eu,
fr,
hu,
it,
nl,
"en-us": en_us,
"pt-br": pt_br,
};

for (const [k, v] of Object.entries<string>(translations)) {
expect(getTranslation(new Intl.Locale(k))).toStrictEqual(Yaml.load(v));
}

expect(pt_br).not.toStrictEqual(pt);

expect(() => getTranslation(new Intl.Locale("not-a2code"))).toThrow(
TranslationNotFoundError,
);
});

0 comments on commit 1b6542f

Please sign in to comment.