@@ -15,11 +15,14 @@ test("User should be able to input a barcode and get a result", async ({
15
15
page,
16
16
} ) => {
17
17
await page . goto ( "http://localhost:3000/en" ) ;
18
+
18
19
const inputField = await page . $ ( 'input[name="barcode"]' ) ;
19
20
await inputField . type ( "4066600204404" ) ;
20
21
const submitButton = await page . $ ( 'button[name="submit"]' ) ;
21
22
await submitButton . click ( ) ;
23
+
22
24
await page . waitForSelector ( ".loading_skeleton" , { state : "hidden" } ) ;
25
+
23
26
const resultText = await page . textContent ( "#result" ) ;
24
27
expect ( resultText ) . toContain ( "Paulaner Spezi Zero" ) ;
25
28
} ) ;
@@ -28,13 +31,35 @@ test("User should be able to input ingredients and get a result", async ({
28
31
page,
29
32
} ) => {
30
33
await page . goto ( "http://localhost:3000/en/ingredients" ) ;
34
+
31
35
const inputField = await page . $ ( 'textarea[id="ingredients"]' ) ;
32
36
await inputField . type ( "Duck" ) ;
33
37
const submitButton = await page . $ ( 'button[name="checkingredients"]' ) ;
34
38
await submitButton . click ( ) ;
39
+
35
40
await page . waitForSelector ( ".loading_skeleton" , { state : "hidden" } ) ;
36
41
const resultText = await page . textContent ( ".resultborder" ) ;
37
42
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
+ } ) ;
38
63
} ) ;
39
64
40
65
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
46
71
const switchInput = await page . $ ( "#oled-switch" ) ;
47
72
await switchInput . click ( ) ;
48
73
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
50
75
await Promise . any ( [
51
76
page . waitForSelector ( ".switch.animated.shake" , { timeout : 5000 } ) ,
52
77
page . waitForFunction (
@@ -74,3 +99,48 @@ test("User should be able to switch on OLED mode in darkmode, in lightmode, user
74
99
) ;
75
100
}
76
101
} ) ;
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