Skip to content

Commit a7db3c2

Browse files
feat(Tests): Added more front-end tests
1 parent 1cd18fe commit a7db3c2

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/tests/usability.spec.ts

+71-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ test("User should be able to input a barcode and get a result", async ({
1515
page,
1616
}) => {
1717
await page.goto("http://localhost:3000/en");
18+
1819
const inputField = await page.$('input[name="barcode"]');
1920
await inputField.type("4066600204404");
2021
const submitButton = await page.$('button[name="submit"]');
2122
await submitButton.click();
23+
2224
await page.waitForSelector(".loading_skeleton", { state: "hidden" });
25+
2326
const resultText = await page.textContent("#result");
2427
expect(resultText).toContain("Paulaner Spezi Zero");
2528
});
@@ -28,13 +31,35 @@ test("User should be able to input ingredients and get a result", async ({
2831
page,
2932
}) => {
3033
await page.goto("http://localhost:3000/en/ingredients");
34+
3135
const inputField = await page.$('textarea[id="ingredients"]');
3236
await inputField.type("Duck");
3337
const submitButton = await page.$('button[name="checkingredients"]');
3438
await submitButton.click();
39+
3540
await page.waitForSelector(".loading_skeleton", { state: "hidden" });
3641
const resultText = await page.textContent(".resultborder");
3742
expect(resultText).toContain("Duck");
43+
44+
await page.route("**/v0/ingredients/*", (route) => {
45+
expect(route.request().url()).toBe(
46+
"https://api.vegancheck.me/v0/ingredients/Duck"
47+
);
48+
expect(route.request().method()).toBe("GET");
49+
route.fulfill({
50+
status: 200,
51+
contentType: "application/json",
52+
body: JSON.stringify({
53+
code: "OK",
54+
status: "200",
55+
message: "Success",
56+
data: {
57+
vegan: "false",
58+
flagged: ["duck"],
59+
},
60+
}),
61+
});
62+
});
3863
});
3964

4065
test("User should be able to switch on OLED mode in darkmode, in lightmode, user should get an error", async ({
@@ -46,7 +71,7 @@ test("User should be able to switch on OLED mode in darkmode, in lightmode, user
4671
const switchInput = await page.$("#oled-switch");
4772
await switchInput.click();
4873

49-
// Wait for either the "animated shake" class or the background color to change
74+
// Wait for either the "animated shake" class (error) or the background color to change
5075
await Promise.any([
5176
page.waitForSelector(".switch.animated.shake", { timeout: 5000 }),
5277
page.waitForFunction(
@@ -74,3 +99,48 @@ test("User should be able to switch on OLED mode in darkmode, in lightmode, user
7499
);
75100
}
76101
});
102+
103+
test("User should be able to input a barcode via the URL parameter `ean` ", async ({
104+
page,
105+
}) => {
106+
await page.route("**/v0/product/*", (route) => {
107+
expect(route.request().url()).toBe(
108+
"https://api.vegancheck.me/v0/product/4066600204404"
109+
);
110+
expect(route.request().method()).toBe("POST");
111+
route.fulfill({
112+
status: 200,
113+
contentType: "application/json",
114+
body: JSON.stringify({
115+
status: 200,
116+
product: {
117+
productname: "Paulaner Spezi Zero",
118+
vegan: "true",
119+
vegetarian: "true",
120+
animaltestfree: "n/a",
121+
palmoil: "false",
122+
nutriscore: "c",
123+
grade: "B",
124+
},
125+
sources: {
126+
processed: "false",
127+
api: "OpenFoodFacts",
128+
baseuri: "https://world.openfoodfacts.org",
129+
},
130+
}),
131+
});
132+
});
133+
134+
await page.goto("http://localhost:3000/en?ean=4066600204404");
135+
136+
const inputField = await page.waitForSelector('input[name="barcode"]', {
137+
visible: true,
138+
});
139+
const inputValue = await inputField.evaluate((el) => el.value);
140+
expect(inputValue).toBe("4066600204404");
141+
142+
await page.waitForSelector(".loading_skeleton", { state: "hidden" });
143+
144+
const resultText = await page.textContent("#result");
145+
expect(resultText).toContain("Paulaner Spezi Zero");
146+
});

0 commit comments

Comments
 (0)