|
| 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