Skip to content

Commit

Permalink
feat(test): Add test and hide implem details
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrault committed Aug 5, 2024
1 parent aa88fd3 commit e19b1ba
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions src/translation/generate-template-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe("generateType", () => {

expect(result).toHaveLength(1);

expect(result[0]).toEqual({
expect(result[0]).toMatchObject({
key: "day",
interpolations: [{ name: "count", type: [{ value: "number", last: true }], last: true }],
interpolations: [{ name: "count", type: [{ value: "number" }] }],
});
});

Expand All @@ -41,11 +41,11 @@ describe("generateType", () => {

expect(result).toHaveLength(3);

expect(result[0]).toEqual({
expect(result[0]).toMatchObject({
key: "day.one",
interpolations: [],
});
expect(result[1]).toEqual({
expect(result[1]).toMatchObject({
key: "day.other",
interpolations: [],
});
Expand All @@ -68,17 +68,16 @@ describe("generateType", () => {

expect(result).toHaveLength(1);

expect(result[0]).toEqual({
expect(result[0]).toMatchObject({
key: "greeting",
interpolations: [
{
name: "firstName",
type: [{ value: "string" }, { value: "number", last: true }],
type: [{ value: "string" }, { value: "number" }],
},
{
name: "familyName",
type: [{ value: "string" }, { value: "number", last: true }],
last: true,
type: [{ value: "string" }, { value: "number" }],
},
],
});
Expand Down Expand Up @@ -106,12 +105,43 @@ describe("generateType", () => {

expect(result).toHaveLength(1);

expect(result[0]).toEqual({
expect(result[0]).toMatchObject({
key: "day",
interpolations: [
{ name: "count", type: [{ value: "number" }, { value: "string", last: true }] },
{ name: "mood", type: [{ value: "string", last: true }] },
{ name: "moods", type: [{ value: "string", last: true }], last: true },
{ name: "count", type: [{ value: "number" }, { value: "string" }] },
{ name: "mood", type: [{ value: "string" }] },
{ name: "moods", type: [{ value: "string" }] },
],
});
});

it("should handle ", () => {
const translations = {
"greeting.man": "Hello Mr {{name}}!",
"greeting.woman": "Hello Ms {{name}}!",
"greeting.neutral": "Hello {{name}}!",
};

const rules = [
{
condition: { placeholderPattern: { prefix: "{{", suffix: "}}" } },
transformer: { addMatchedPlaceholder: { type: ["string"] } },
},
{
condition: { keyEndsWith: ["man", "woman", "neutral"] },
transformer: { addPlaceholder: { name: "gender", type: ["string"] }, removeLastPart: true },
},
];

const result = generateTemplateData(translations, { ...mockConfig, rules });

expect(result).toHaveLength(1);

expect(result[0]).toMatchObject({
key: "greeting",
interpolations: [
{ name: "gender", type: [{ value: "string" }] },
{ name: "name", type: [{ value: "string" }] },
],
});
});
Expand Down

0 comments on commit e19b1ba

Please sign in to comment.