Files
pleno-vue/tests/e2e/subuserProfileSecurity.spec.ts
T

68 lines
2.8 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { loginAsSubuserByPhone } from "./fixtures";
async function openSubuserSecurity(page) {
await loginAsSubuserByPhone(page);
await page.goto("/user/profile");
const securityCard = page.getByTestId("subuser-profile-security-card");
await expect(securityCard).toBeVisible();
await securityCard.locator(".card-header").click();
await expect(page.getByTestId("subuser-profile-security-logout")).toBeVisible();
}
async function expectLogoutButtonStyling(page, button) {
await expect(button).toHaveClass(/is-danger/);
await expect(button).toHaveClass(/is-outlined/);
const viewportWidth = page.viewportSize()?.width ?? Number.MAX_SAFE_INTEGER;
if (viewportWidth <= 768) {
const dimensions = await button.evaluate((element) => {
const rect = element.getBoundingClientRect();
const parentRect = element.parentElement?.getBoundingClientRect();
return {
width: rect.width,
parentWidth: parentRect?.width ?? rect.width,
};
});
expect(Math.abs(dimensions.parentWidth - dimensions.width)).toBeLessThanOrEqual(2);
}
}
test("[PROFILE][Subuser][Security] renders the current security surface", async ({ page }) => {
await openSubuserSecurity(page);
const logoutButton = page.getByTestId("subuser-profile-security-logout");
await expect(logoutButton).toBeVisible();
await expectLogoutButtonStyling(page, logoutButton);
await expect(page.getByTestId("subuser-profile-passkeys").getByTestId("passkey-add")).toBeVisible();
await expect(page.getByTestId("subuser-profile-two-factor").getByTestId("two-factor-status")).toBeVisible();
const enableButton = page.getByTestId("subuser-profile-two-factor").getByTestId("two-factor-enable");
const disableButton = page.getByTestId("subuser-profile-two-factor").getByTestId("two-factor-disable");
expect((await enableButton.count()) + (await disableButton.count())).toBeGreaterThan(0);
});
test("[PROFILE][Subuser][Security] opens the logout confirmation dialog", async ({ page }) => {
await openSubuserSecurity(page);
await page.getByTestId("subuser-profile-security-logout").click();
await expect(page.locator(".swal2-popup")).toBeVisible();
});
test("[PROFILE][Subuser][Security] logs out and requires re-authentication", async ({ page }) => {
await openSubuserSecurity(page);
await page.getByTestId("subuser-profile-security-logout").click();
const logoutDialog = page.locator(".swal2-popup");
await expect(logoutDialog).toBeVisible();
await logoutDialog.locator(".swal2-confirm").click();
await expect(page).toHaveURL(/\/login\/driver(?:\?.*)?$/);
await expect(page.locator('input[name="phone_country_code"]')).toBeVisible();
await page.goto("/user/profile");
await expect(page).toHaveURL(/\/login(?:\?.*)?$/);
await expect(page.locator('input[name="customer_number"]')).toBeVisible();
});