From c71d74dd18fe7ef8f4dcd9442cf596ee67f24ee0 Mon Sep 17 00:00:00 2001 From: aronmal Date: Mon, 10 Jul 2023 19:36:12 +0200 Subject: [PATCH] Add jest E2E testing --- leaky-ships/.gitignore | 2 + leaky-ships/__tests__/auth.js | 70 + leaky-ships/components/BurgerMenu.tsx | 1 + leaky-ships/components/OptionButton.tsx | 9 +- leaky-ships/jest-puppeteer.config.js | 6 + leaky-ships/jest.config.js | 9 + leaky-ships/package.json | 6 +- leaky-ships/pages/index.tsx | 1 + leaky-ships/pages/signin.tsx | 3 + leaky-ships/pages/signout.tsx | 1 + leaky-ships/pages/start.tsx | 79 +- leaky-ships/pnpm-lock.yaml | 2524 ++++++++++++++++++++++- 12 files changed, 2624 insertions(+), 87 deletions(-) create mode 100644 leaky-ships/__tests__/auth.js create mode 100644 leaky-ships/jest-puppeteer.config.js create mode 100644 leaky-ships/jest.config.js diff --git a/leaky-ships/.gitignore b/leaky-ships/.gitignore index 85b0254..1c20691 100644 --- a/leaky-ships/.gitignore +++ b/leaky-ships/.gitignore @@ -1,5 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +__tests__/screenshots/* + # logs /log diff --git a/leaky-ships/__tests__/auth.js b/leaky-ships/__tests__/auth.js new file mode 100644 index 0000000..d629a6b --- /dev/null +++ b/leaky-ships/__tests__/auth.js @@ -0,0 +1,70 @@ +describe("Azure AD", () => { + it("Go to MS sign in", async () => { + await page.goto("https://leaky-ships.mal-noh.de/") + await page.screenshot({ path: "__tests__/screenshots/a.png" }) + await page.click("#start") + await page.screenshot({ path: "__tests__/screenshots/b.png" }) + await page.waitForSelector("#login") + await page.screenshot({ path: "__tests__/screenshots/c.png" }) + await page.click("#login") + await page.screenshot({ path: "__tests__/screenshots/d.png" }) + await page.waitForSelector("#microsoft") + await page.screenshot({ path: "__tests__/screenshots/e.png" }) + await page.click("#microsoft") + await page.screenshot({ path: "__tests__/screenshots/f.png" }) + }, 10000) + + it("MS sign in", async () => { + // Listen for frame navigations and log the URL changes + // page.on("framenavigated", (frame) => { + // const frameUrl = frame.url() + // console.log("Window Location Changed:", frameUrl) + // }) + + await page.screenshot({ path: "__tests__/screenshots/1.png" }) + await page.waitForNavigation() + await page.screenshot({ path: "__tests__/screenshots/2.png" }) + // await page.screenshot({ path: "__tests__/screenshots/4.png" }) + const email = process.env.AUTH_EMAIL + const password = process.env.AUTH_PW + + console.log(email) + + await page.waitForSelector('input[type="email"]') + await page.waitForSelector('input[type="password"]') + await page.screenshot({ path: "__tests__/screenshots/3.png" }) + + // Find the email input field and type the email + const emailInput = await page.$('input[type="email"]') + await emailInput.type(email) + await page.screenshot({ path: "__tests__/screenshots/4.png" }) + + await page.waitForSelector('input[value="Next"]') + // Submit the form (if necessary) + const submitInput1 = await page.$('input[type="submit"]') + await submitInput1.click() + await page.screenshot({ path: "__tests__/screenshots/5.png" }) + + // Find the password input field and type the password + const passwordInput = await page.$('input[type="password"]') + await passwordInput.type(password) + await page.screenshot({ path: "__tests__/screenshots/6.png" }) + + await page.waitForSelector('input[value="Sign in"]') + // Submit the form (if necessary) + const submitInput = await page.$('input[value="Sign in"]') + await submitInput.click() + await page.screenshot({ path: "__tests__/screenshots/7.png" }) + + await page.waitForSelector('input[value="No"]') + // Submit the form (if necessary) + const noInput = await page.$('input[value="No"]') + await noInput.click() + await page.screenshot({ path: "__tests__/screenshots/8.png" }) + + const callbackUrl = "https://leaky-ships.mal-noh.de/" + await page.waitForFunction(`window.location.href === '${callbackUrl}'`) + // await page.waitForNavigation({ waitUntil: "networkidle0" }) + await page.screenshot({ path: "__tests__/screenshots/9.png" }) + }, 15000) +}) diff --git a/leaky-ships/components/BurgerMenu.tsx b/leaky-ships/components/BurgerMenu.tsx index 521c13f..12be92a 100644 --- a/leaky-ships/components/BurgerMenu.tsx +++ b/leaky-ships/components/BurgerMenu.tsx @@ -10,6 +10,7 @@ function BurgerMenu({ }) { return ( {!session?.user.id && (