diff --git a/apps/web/components/admin/product/form.tsx b/apps/web/components/admin/product/form.tsx index c87ae674..f81ad75f 100644 --- a/apps/web/components/admin/product/form.tsx +++ b/apps/web/components/admin/product/form.tsx @@ -243,7 +243,7 @@ export function ProductCreateEditForm({ {Object.entries(ProductTypeLabels).map(([value, label]) => ( - + {label} ))} diff --git a/apps/web/tests/lib/nutriscore.test.ts b/apps/web/tests/lib/nutriscore.test.ts new file mode 100644 index 00000000..6ea6001f --- /dev/null +++ b/apps/web/tests/lib/nutriscore.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, test } from "vitest"; +import { getNutriscoreImageUrl } from "@/lib/product/nutriscore"; +import { Product } from "@/types/product"; +import { productList } from "@/constants/data"; + +describe("test getNutriscoreImageUrl function", () => { + test("should return -a", () => { + const result = getNutriscoreImageUrl({ ...productList[0], nutriscore: "A" } as Product); + const regex = /-([a-z])/gim; + const match = result.match(regex); + if (!match) throw new Error("No match found"); + expect(match[0]).toBe("-a"); + }); + + test("should return -b", () => { + const result = getNutriscoreImageUrl({ ...productList[0], nutriscore: "B" } as Product); + const regex = /-([a-z])/gim; + const match = result.match(regex); + if (!match) throw new Error("No match found"); + expect(match[0]).toBe("-b"); + }); + + test("should return -c", () => { + const result = getNutriscoreImageUrl(productList[0] as Product); + const regex = /-([a-z])/gim; + const match = result.match(regex); + if (!match) throw new Error("No match found"); + expect(match[0]).toBe("-c"); + }); + + test("should return -d", () => { + const result = getNutriscoreImageUrl({ ...productList[0], nutriscore: "D" } as Product); + const regex = /-([a-z])/gim; + const match = result.match(regex); + if (!match) throw new Error("No match found"); + expect(match[0]).toBe("-d"); + }); + + test("should return -e", () => { + const result = getNutriscoreImageUrl({ ...productList[0], nutriscore: "E" } as Product); + const regex = /-([a-z])/gim; + const match = result.match(regex); + if (!match) throw new Error("No match found"); + expect(match[0]).toBe("-e"); + }); +}); diff --git a/apps/web/tests/lib/user.test.ts b/apps/web/tests/lib/user.test.ts new file mode 100644 index 00000000..54e75f3e --- /dev/null +++ b/apps/web/tests/lib/user.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, test } from "vitest"; +import { user } from "@/constants/data"; +import { toName } from "@/lib/user"; + +describe("test toName function", () => { + test("should return concat first name and name", () => { + const result = toName(user); + expect(result).toBe("John Doe"); + }); + + test("should return unknown user", () => { + const result = toName(null); + expect(result).toBe("Utilisateur inconnu"); + }); +});