Skip to content

Commit 2d092f6

Browse files
committed
✅ Update tests
1 parent 1af830b commit 2d092f6

File tree

8 files changed

+66
-65
lines changed

8 files changed

+66
-65
lines changed

frontend/src/routes/login.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function Login() {
8080
<FormLabel>Email</FormLabel>
8181
<FormControl>
8282
<Input
83+
data-testid="email-input"
8384
placeholder="[email protected]"
8485
type="email"
8586
{...field}
@@ -105,7 +106,11 @@ function Login() {
105106
</RouterLink>
106107
</div>
107108
<FormControl>
108-
<PasswordInput placeholder="Password" {...field} />
109+
<PasswordInput
110+
data-testid="password-input"
111+
placeholder="Password"
112+
{...field}
113+
/>
109114
</FormControl>
110115
<FormMessage className="text-xs" />
111116
</FormItem>

frontend/src/routes/signup.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ function SignUp() {
9191
<FormItem>
9292
<FormLabel>Full Name</FormLabel>
9393
<FormControl>
94-
<Input placeholder="User" type="text" {...field} />
94+
<Input
95+
data-testid="full-name-input"
96+
placeholder="User"
97+
type="text"
98+
{...field}
99+
/>
95100
</FormControl>
96101
<FormMessage />
97102
</FormItem>
@@ -106,6 +111,7 @@ function SignUp() {
106111
<FormLabel>Email</FormLabel>
107112
<FormControl>
108113
<Input
114+
data-testid="email-input"
109115
placeholder="[email protected]"
110116
type="email"
111117
{...field}
@@ -123,7 +129,11 @@ function SignUp() {
123129
<FormItem>
124130
<FormLabel>Password</FormLabel>
125131
<FormControl>
126-
<PasswordInput placeholder="Password" {...field} />
132+
<PasswordInput
133+
data-testid="password-input"
134+
placeholder="Password"
135+
{...field}
136+
/>
127137
</FormControl>
128138
<FormMessage />
129139
</FormItem>
@@ -137,7 +147,11 @@ function SignUp() {
137147
<FormItem>
138148
<FormLabel>Confirm Password</FormLabel>
139149
<FormControl>
140-
<PasswordInput placeholder="Confirm Password" {...field} />
150+
<PasswordInput
151+
data-testid="confirm-password-input"
152+
placeholder="Confirm Password"
153+
{...field}
154+
/>
141155
</FormControl>
142156
<FormMessage />
143157
</FormItem>

frontend/tests/auth.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const authFile = "playwright/.auth/user.json"
55

66
setup("authenticate", async ({ page }) => {
77
await page.goto("/login")
8-
await page.getByPlaceholder("Email").fill(firstSuperuser)
9-
await page.getByPlaceholder("Password").fill(firstSuperuserPassword)
8+
await page.getByTestId("email-input").fill(firstSuperuser)
9+
await page.getByTestId("password-input").fill(firstSuperuserPassword)
1010
await page.getByRole("button", { name: "Log In" }).click()
1111
await page.waitForURL("/")
1212
await page.context().storageState({ path: authFile })

frontend/tests/config.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ const __dirname = path.dirname(__filename)
77

88
dotenv.config({ path: path.join(__dirname, "../../.env") })
99

10-
const { FIRST_SUPERUSER, FIRST_SUPERUSER_PASSWORD } = process.env
11-
12-
if (typeof FIRST_SUPERUSER !== "string") {
13-
throw new Error("Environment variable FIRST_SUPERUSER is undefined")
14-
}
15-
16-
if (typeof FIRST_SUPERUSER_PASSWORD !== "string") {
17-
throw new Error("Environment variable FIRST_SUPERUSER_PASSWORD is undefined")
10+
function getEnvVar(name: string): string {
11+
const value = process.env[name]
12+
if (!value) {
13+
throw new Error(`Environment variable ${name} is undefined`)
14+
}
15+
return value
1816
}
1917

20-
export const firstSuperuser = FIRST_SUPERUSER as string
21-
export const firstSuperuserPassword = FIRST_SUPERUSER_PASSWORD as string
18+
export const firstSuperuser = getEnvVar("FIRST_SUPERUSER")
19+
export const firstSuperuserPassword = getEnvVar("FIRST_SUPERUSER_PASSWORD")

frontend/tests/login.spec.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@ import { randomPassword } from "./utils/random.ts"
44

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

7-
type OptionsType = {
8-
exact?: boolean
9-
}
10-
117
const fillForm = async (page: Page, email: string, password: string) => {
12-
await page.getByPlaceholder("Email").fill(email)
13-
await page.getByPlaceholder("Password", { exact: true }).fill(password)
8+
await page.getByTestId("email-input").fill(email)
9+
await page.getByTestId("password-input").fill(password)
1410
}
1511

16-
const verifyInput = async (
17-
page: Page,
18-
placeholder: string,
19-
options?: OptionsType,
20-
) => {
21-
const input = page.getByPlaceholder(placeholder, options)
12+
const verifyInput = async (page: Page, testId: string) => {
13+
const input = page.getByTestId(testId)
2214
await expect(input).toBeVisible()
2315
await expect(input).toHaveText("")
2416
await expect(input).toBeEditable()
@@ -27,8 +19,8 @@ const verifyInput = async (
2719
test("Inputs are visible, empty and editable", async ({ page }) => {
2820
await page.goto("/login")
2921

30-
await verifyInput(page, "Email")
31-
await verifyInput(page, "Password", { exact: true })
22+
await verifyInput(page, "email-input")
23+
await verifyInput(page, "password-input")
3224
})
3325

3426
test("Log In button is visible", async ({ page }) => {

frontend/tests/reset-password.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ test("Password Recovery title is visible", async ({ page }) => {
1616
test("Input is visible, empty and editable", async ({ page }) => {
1717
await page.goto("/recover-password")
1818

19-
await expect(page.getByPlaceholder("Email")).toBeVisible()
20-
await expect(page.getByPlaceholder("Email")).toHaveText("")
21-
await expect(page.getByPlaceholder("Email")).toBeEditable()
19+
await expect(page.getByTestId("email-input")).toBeVisible()
20+
await expect(page.getByTestId("email-input")).toHaveText("")
21+
await expect(page.getByTestId("email-input")).toBeEditable()
2222
})
2323

2424
test("Continue button is visible", async ({ page }) => {
@@ -40,7 +40,7 @@ test("User can reset password successfully using the link", async ({
4040
await signUpNewUser(page, fullName, email, password)
4141

4242
await page.goto("/recover-password")
43-
await page.getByPlaceholder("Email").fill(email)
43+
await page.getByTestId("email-input").fill(email)
4444

4545
await page.getByRole("button", { name: "Continue" }).click()
4646

@@ -64,8 +64,8 @@ test("User can reset password successfully using the link", async ({
6464
// Set the new password and confirm it
6565
await page.goto(url)
6666

67-
await page.getByPlaceholder("New Password").fill(newPassword)
68-
await page.getByPlaceholder("Confirm Password").fill(newPassword)
67+
await page.getByTestId("new-password-input").fill(newPassword)
68+
await page.getByTestId("confirm-password-input").fill(newPassword)
6969
await page.getByRole("button", { name: "Reset Password" }).click()
7070
await expect(page.getByText("Password updated successfully")).toBeVisible()
7171

@@ -79,8 +79,8 @@ test("Expired or invalid reset link", async ({ page }) => {
7979

8080
await page.goto(invalidUrl)
8181

82-
await page.getByPlaceholder("New Password").fill(password)
83-
await page.getByPlaceholder("Confirm Password").fill(password)
82+
await page.getByTestId("new-password-input").fill(password)
83+
await page.getByTestId("confirm-password-input").fill(password)
8484
await page.getByRole("button", { name: "Reset Password" }).click()
8585

8686
await expect(page.getByText("Invalid token")).toBeVisible()
@@ -96,7 +96,7 @@ test("Weak new password validation", async ({ page, request }) => {
9696
await signUpNewUser(page, fullName, email, password)
9797

9898
await page.goto("/recover-password")
99-
await page.getByPlaceholder("Email").fill(email)
99+
await page.getByTestId("email-input").fill(email)
100100
await page.getByRole("button", { name: "Continue" }).click()
101101

102102
const emailData = await findLastEmail({
@@ -115,8 +115,8 @@ test("Weak new password validation", async ({ page, request }) => {
115115

116116
// Set a weak new password
117117
await page.goto(url)
118-
await page.getByPlaceholder("New Password").fill(weakPassword)
119-
await page.getByPlaceholder("Confirm Password").fill(weakPassword)
118+
await page.getByTestId("new-password-input").fill(weakPassword)
119+
await page.getByTestId("confirm-password-input").fill(weakPassword)
120120
await page.getByRole("button", { name: "Reset Password" }).click()
121121

122122
await expect(

frontend/tests/sign-up.spec.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,21 @@ import { randomEmail, randomPassword } from "./utils/random"
44

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

7-
type OptionsType = {
8-
exact?: boolean
9-
}
10-
117
const fillForm = async (
128
page: Page,
139
full_name: string,
1410
email: string,
1511
password: string,
1612
confirm_password: string,
1713
) => {
18-
await page.getByPlaceholder("Full Name").fill(full_name)
19-
await page.getByPlaceholder("Email").fill(email)
20-
await page.getByPlaceholder("Password", { exact: true }).fill(password)
21-
await page.getByPlaceholder("Confirm Password").fill(confirm_password)
14+
await page.getByTestId("full-name-input").fill(full_name)
15+
await page.getByTestId("email-input").fill(email)
16+
await page.getByTestId("password-input").fill(password)
17+
await page.getByTestId("confirm-password-input").fill(confirm_password)
2218
}
2319

24-
const verifyInput = async (
25-
page: Page,
26-
placeholder: string,
27-
options?: OptionsType,
28-
) => {
29-
const input = page.getByPlaceholder(placeholder, options)
20+
const verifyInput = async (page: Page, testId: string) => {
21+
const input = page.getByTestId(testId)
3022
await expect(input).toBeVisible()
3123
await expect(input).toHaveText("")
3224
await expect(input).toBeEditable()
@@ -35,10 +27,10 @@ const verifyInput = async (
3527
test("Inputs are visible, empty and editable", async ({ page }) => {
3628
await page.goto("/signup")
3729

38-
await verifyInput(page, "Full Name")
39-
await verifyInput(page, "Email")
40-
await verifyInput(page, "Password", { exact: true })
41-
await verifyInput(page, "Confirm Password")
30+
await verifyInput(page, "full-name-input")
31+
await verifyInput(page, "email-input")
32+
await verifyInput(page, "password-input")
33+
await verifyInput(page, "confirm-password-input")
4234
})
4335

4436
test("Sign Up button is visible", async ({ page }) => {

frontend/tests/utils/user.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ export async function signUpNewUser(
88
) {
99
await page.goto("/signup")
1010

11-
await page.getByPlaceholder("Full Name").fill(name)
12-
await page.getByPlaceholder("Email").fill(email)
13-
await page.getByPlaceholder("Password", { exact: true }).fill(password)
14-
await page.getByPlaceholder("Confirm Password").fill(password)
11+
await page.getByTestId("full-name-input").fill(name)
12+
await page.getByTestId("email-input").fill(email)
13+
await page.getByTestId("password-input").fill(password)
14+
await page.getByTestId("confirm-password-input").fill(password)
1515
await page.getByRole("button", { name: "Sign Up" }).click()
1616
await page.goto("/login")
1717
}
1818

1919
export async function logInUser(page: Page, email: string, password: string) {
2020
await page.goto("/login")
2121

22-
await page.getByPlaceholder("Email").fill(email)
23-
await page.getByPlaceholder("Password", { exact: true }).fill(password)
22+
await page.getByTestId("email-input").fill(email)
23+
await page.getByTestId("password-input").fill(password)
2424
await page.getByRole("button", { name: "Log In" }).click()
2525
await page.waitForURL("/")
2626
await expect(

0 commit comments

Comments
 (0)