From ba393dc4cb5116cd6c4b106adc63037a2a6a6ae3 Mon Sep 17 00:00:00 2001 From: Nazanin-sh Date: Sun, 31 May 2026 14:13:29 +0330 Subject: [PATCH] Refactor: simplify login test by removing helpers and describe block --- tests/auth/login.spec.ts | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/auth/login.spec.ts b/tests/auth/login.spec.ts index cc105ff..ab8f1e2 100644 --- a/tests/auth/login.spec.ts +++ b/tests/auth/login.spec.ts @@ -1,30 +1,17 @@ -import { test, expect, type Page } from "@playwright/test"; +import { test, expect } from "@playwright/test"; const LOGIN_URL = "/auth/login?returnUrl=/admin"; -const getPhoneInput = (page: Page) => - page.getByRole("spinbutton", { name: "شماره موبایل" }); -const getContinueButton = (page: Page) => - page.getByRole("button", { name: "ادامه" }); -const getPasswordInput = (page: Page) => - page.getByRole("textbox", { name: "کلمه عبور" }); -const getLoginButton = (page: Page) => - page.getByRole("button", { name: "ورود" }); - -test.describe("login tests - 09111111111", () => { - test.beforeEach(async ({ page }) => { - await page.goto(LOGIN_URL); - await getPhoneInput(page).fill("09111111111"); - await getContinueButton(page).click(); - }); - - test("should have password", async ({ page }) => { - await expect(getPasswordInput(page)).toBeVisible(); - }); - - test("should redirect to /admin on successful login", async ({ page }) => { - await getPasswordInput(page).fill("123456"); - await getLoginButton(page).click(); - await expect(page).toHaveURL("https://dev-gate.raysa.app/admin"); - }); +test("09111111111 should redirect to /admin on successful login", async ({ + page, + baseURL, +}) => { + await page.goto(LOGIN_URL); + await page + .getByRole("spinbutton", { name: "شماره موبایل" }) + .fill("09111111111"); + await page.getByRole("button", { name: "ادامه" }).click(); + await page.getByRole("textbox", { name: "کلمه عبور" }).fill("123456"); + await page.getByRole("button", { name: "ورود" }).click(); + await expect(page).toHaveURL(`${baseURL}/admin`); });