Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
[FEATURE] Add tests for the web app
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatole-Godard committed Jul 2, 2024
1 parent 38bebc4 commit 055191d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/web/components/admin/product/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export function ProductCreateEditForm({
</FormControl>
<SelectContent>
{Object.entries(ProductTypeLabels).map(([value, label]) => (
<SelectItem key={value} value={ProductType[parseInt(value)]}>
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
Expand Down
46 changes: 46 additions & 0 deletions apps/web/tests/lib/nutriscore.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
15 changes: 15 additions & 0 deletions apps/web/tests/lib/user.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit 055191d

Please sign in to comment.