2021-03-13 19:37:44 +01:00
|
|
|
import { replaceBoth, retrieveFiltered, CheckType, LangType } from "../../utils/language";
|
2021-03-12 19:41:20 +01:00
|
|
|
import { languages, exceptions, mappings } from "../../utils/languages.json";
|
|
|
|
|
|
|
|
|
|
describe("replaceBoth", () => {
|
2021-03-13 19:37:44 +01:00
|
|
|
const testReplacer = (
|
|
|
|
|
checkType: CheckType,
|
|
|
|
|
checkObj: {
|
|
|
|
|
[key in LangType]: {
|
|
|
|
|
[key: string]: string
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
langType: LangType
|
|
|
|
|
) => (
|
|
|
|
|
Object.entries(checkObj[langType]).forEach(([code, replacement]) => {
|
|
|
|
|
const res = replaceBoth(checkType, { source: "", target: "", [langType]: code })
|
|
|
|
|
expect(res[langType]).toBe(replacement);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2021-03-12 19:41:20 +01:00
|
|
|
it("replaces excepted sources correctly", () => {
|
2021-03-13 19:37:44 +01:00
|
|
|
testReplacer("exception", exceptions, "source");
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("replaces excepted targets correctly", () => {
|
2021-03-13 19:37:44 +01:00
|
|
|
testReplacer("exception", exceptions, "target");
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("replaces mapped sources correctly", () => {
|
2021-03-13 19:37:44 +01:00
|
|
|
testReplacer("mapping", mappings, "source");
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("replaces mapped targets correctly", () => {
|
2021-03-13 19:37:44 +01:00
|
|
|
testReplacer("mapping", mappings, "target");
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("retrieveFiltered", () => {
|
2021-04-30 23:11:26 +02:00
|
|
|
const filteredEntries = (langType: LangType) => (
|
|
|
|
|
Object.entries(languages).filter(([code]) => !Object.keys(exceptions[langType]).includes(code))
|
2021-03-13 19:37:44 +01:00
|
|
|
);
|
|
|
|
|
|
2021-04-30 23:11:26 +02:00
|
|
|
it("filters by exceptions", () => {
|
|
|
|
|
const { sourceLangs, targetLangs } = retrieveFiltered();
|
|
|
|
|
expect(sourceLangs).toStrictEqual(filteredEntries("source"));
|
|
|
|
|
expect(targetLangs).toStrictEqual(filteredEntries("target"));
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
});
|