Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react-swc": "^3.5.0",
"dotenv": "^16.4.5",
"typescript": "^5.2.2",
"vite": "^5.0.13"
}
Expand Down
1 change: 1 addition & 0 deletions frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig, devices } from '@playwright/test';


/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
Expand Down
6 changes: 4 additions & 2 deletions frontend/tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { test as setup } from "@playwright/test"
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"

const authFile = "playwright/.auth/user.json"


setup("authenticate", async ({ page }) => {
await page.goto("/login")
await page.getByPlaceholder("Email").fill("[email protected]")
await page.getByPlaceholder("Password").fill("changethis")
await page.getByPlaceholder("Email").fill(firstSuperuser)
await page.getByPlaceholder("Password").fill(firstSuperuserPassword)
await page.getByRole("button", { name: "Log In" }).click()
await page.waitForURL("/")
await page.context().storageState({ path: authFile })
Expand Down
21 changes: 21 additions & 0 deletions frontend/tests/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

dotenv.config({ path: path.join(__dirname, '../../.env') });

const { FIRST_SUPERUSER, FIRST_SUPERUSER_PASSWORD } = process.env;

if (typeof FIRST_SUPERUSER !== "string") {
throw new Error("Environment variable FIRST_SUPERUSER is undefined");
}

if (typeof FIRST_SUPERUSER_PASSWORD !== "string") {
throw new Error("Environment variable FIRST_SUPERUSER_PASSWORD is undefined");
}

export const firstSuperuser = FIRST_SUPERUSER as string;
export const firstSuperuserPassword = FIRST_SUPERUSER_PASSWORD as string;
13 changes: 7 additions & 6 deletions frontend/tests/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Page, expect, test } from "@playwright/test"
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"

test.use({ storageState: { cookies: [], origins: [] } })

Expand Down Expand Up @@ -46,7 +47,7 @@ test("Forgot Password link is visible", async ({ page }) => {
test("Log in with valid email and password ", async ({ page }) => {
await page.goto("/login")

await fillForm(page, "[email protected]", "changethis")
await fillForm(page, firstSuperuser, firstSuperuserPassword)
await page.getByRole("button", { name: "Log In" }).click()

await page.waitForURL("/")
Expand All @@ -59,16 +60,16 @@ test("Log in with valid email and password ", async ({ page }) => {
test("Log in with invalid email", async ({ page }) => {
await page.goto("/login")

await fillForm(page, "invalidemail", "changethis")
await fillForm(page, "invalidemail", firstSuperuserPassword)
await page.getByRole("button", { name: "Log In" }).click()

await expect(page.getByText("Invalid email address")).toBeVisible()
})

test("Log in with invalid password", async ({ page }) => {
await page.goto("/login")

await fillForm(page, "[email protected]", "changethat")
// TODO: Add a random password utility
await fillForm(page, firstSuperuser, "changethat")
await page.getByRole("button", { name: "Log In" }).click()

await expect(page.getByText("Incorrect email or password")).toBeVisible()
Expand All @@ -79,7 +80,7 @@ test("Log in with invalid password", async ({ page }) => {
test("Successful log out", async ({ page }) => {
await page.goto("/login")

await fillForm(page, "[email protected]", "changethis")
await fillForm(page, firstSuperuser, firstSuperuserPassword)
await page.getByRole("button", { name: "Log In" }).click()

await page.waitForURL("/")
Expand All @@ -96,7 +97,7 @@ test("Successful log out", async ({ page }) => {
test("Logged-out user cannot access protected routes", async ({ page }) => {
await page.goto("/login")

await fillForm(page, "[email protected]", "changethis")
await fillForm(page, firstSuperuser, firstSuperuserPassword)
await page.getByRole("button", { name: "Log In" }).click()

await page.waitForURL("/")
Expand Down
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src", "*.ts", "**/*.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}