Skip to content

Commit 15e8cdd

Browse files
feat(Tests): Added playwright tests
1 parent cdaf3b6 commit 15e8cdd

File tree

5 files changed

+550
-38
lines changed

5 files changed

+550
-38
lines changed

package.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"build": "next build",
88
"start": "next start -p 1030",
99
"stage": "next start -p 1031",
10-
"lint": "next lint"
10+
"lint": "next lint",
11+
"test": "playwright test"
1112
},
1213
"dependencies": {
1314
"@next/font": "13.2.4",
@@ -21,7 +22,20 @@
2122
"quagga": "^0.12.1",
2223
"react": "18.2.0",
2324
"react-dom": "18.2.0",
25+
<<<<<<< Updated upstream
2426
"sass": "^1.60.0",
2527
"typescript": "5.0.2"
28+
=======
29+
<<<<<<< Updated upstream
30+
"sass": "^1.58.3",
31+
"typescript": "4.9.5"
32+
=======
33+
"sass": "^1.60.0",
34+
"typescript": "5.0.2"
35+
},
36+
"devDependencies": {
37+
"@playwright/test": "^1.32.1"
38+
>>>>>>> Stashed changes
39+
>>>>>>> Stashed changes
2640
}
2741
}

src/components/check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ const ProductSearch = () => {
396396
)}
397397
{loading && (
398398
<>
399-
<div id="result">
399+
<div id="result" class="loading_skeleton">
400400
<div className="animated fadeIn resultborder" id="RSFound">
401401
<span className="unknown">
402402
<span className="name skeleton">&nbsp;</span>

src/components/ingredientscheck.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ const IngredientsCheck = () => {
269269
</div>
270270
)}
271271
{loading && (
272-
<div id="result">
272+
<div id="result" class="loading_skeleton">
273273
<div className="animated fadeIn">
274274
<div className="resultborder">
275275
<div className="Grid">

src/tests/usability.spec.ts

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("User should be able to load page and change language", async ({
4+
page,
5+
}) => {
6+
await page.goto("http://localhost:3000/en");
7+
await page.click("text=More");
8+
await expect(page).toHaveURL("http://localhost:3000/more");
9+
await page.click("text=Language");
10+
await page.click("text=German");
11+
await expect(page).toHaveURL("http://localhost:3000/de/more");
12+
});
13+
14+
test("User should be able to input a barcode and get a result", async ({
15+
page,
16+
}) => {
17+
await page.goto("http://localhost:3000/en");
18+
const inputField = await page.$('input[name="barcode"]');
19+
await inputField.type("4066600204404");
20+
const submitButton = await page.$('button[name="submit"]');
21+
await submitButton.click();
22+
await page.waitForSelector(".loading_skeleton", { state: "hidden" });
23+
const resultText = await page.textContent("#result");
24+
expect(resultText).toContain("Paulaner Spezi Zero");
25+
});
26+
27+
test("User should be able to input ingredients and get a result", async ({
28+
page,
29+
}) => {
30+
await page.goto("http://localhost:3000/en/ingredients");
31+
const inputField = await page.$('textarea[id="ingredients"]');
32+
await inputField.type("Duck");
33+
const submitButton = await page.$('button[name="checkingredients"]');
34+
await submitButton.click();
35+
await page.waitForSelector(".loading_skeleton", { state: "hidden" });
36+
const resultText = await page.textContent(".resultborder");
37+
expect(resultText).toContain("Duck");
38+
});
39+
40+
test("User should be able to switch on OLED mode in darkmode, in lightmode, user should get an error", async ({
41+
page,
42+
}) => {
43+
await page.goto("http://localhost:3000/en/more");
44+
45+
// Locate the switch input and click on it
46+
const switchInput = await page.$("#oled-switch");
47+
await switchInput.click();
48+
49+
// Wait for either the "animated shake" class or the background color to change
50+
await Promise.any([
51+
page.waitForSelector(".switch.animated.shake", { timeout: 5000 }),
52+
page.waitForFunction(
53+
() => {
54+
const bodyStyles = window.getComputedStyle(document.body);
55+
return bodyStyles.backgroundColor === "#000";
56+
},
57+
{ timeout: 5000 }
58+
),
59+
]);
60+
// Check if the switch triggered the expected result
61+
const bodyStyles = await page.evaluate(() => {
62+
return window.getComputedStyle(document.body);
63+
});
64+
if (bodyStyles.backgroundColor === "#000") {
65+
// Dark mode was activated
66+
expect(bodyStyles.color).toBe("#141414");
67+
} else {
68+
// Light mode was activated
69+
const switchClasses = await switchInput.evaluate((input) =>
70+
Array.from(input.classList)
71+
);
72+
expect(switchClasses).toEqual(
73+
expect.arrayContaining(["animated", "shake"])
74+
);
75+
}
76+
});

0 commit comments

Comments
 (0)