Added localize implementation along with its tests

This commit is contained in:
Alexander Cerutti
2021-09-25 21:41:06 +02:00
parent 7a23cba582
commit 344c33c54c
2 changed files with 75 additions and 14 deletions

View File

@@ -1,4 +1,8 @@
import { default as PKPass } from "../lib/PKPass";
import {
default as PKPass,
localizationSymbol,
propsSymbol,
} from "../lib/PKPass";
describe("PKPass", () => {
describe("setBeacons", () => {
@@ -389,4 +393,48 @@ describe("PKPass", () => {
expect(passCP.transitType).toBeUndefined(); */
});
});
describe("localize", () => {
const pass = new PKPass({}, {}, {});
it("should create a new language record inside class props", () => {
pass.localize("en");
expect(pass[localizationSymbol]["en"]).toEqual({});
});
it("should save some translations to be exported later", () => {
pass.localize("it", {
say_hi: "ciao",
say_gb: "arrivederci",
});
expect(pass[localizationSymbol]["it"]).toEqual({
say_hi: "ciao",
say_gb: "arrivederci",
});
});
it("should accept later translations and merge them with existing ones", () => {
pass.localize("it", {
say_good_morning: "buongiorno",
say_good_evening: "buonasera",
});
expect(pass[localizationSymbol]["it"]).toEqual({
say_hi: "ciao",
say_gb: "arrivederci",
say_good_morning: "buongiorno",
say_good_evening: "buonasera",
});
});
it("should delete a language and its all translations when null is passed as parameter", () => {
pass.localize("it", null);
pass.localize("en", null);
expect(pass[localizationSymbol]["it"]).toBeUndefined();
expect(pass[localizationSymbol]["en"]).toBeUndefined();
});
});
});