import { ACTOR_PERMISSIONS, useActor } from "../fixtures/user"; import { test, expect } from "../fixtures/user-lifecycle"; import { LoginPage } from "../pages/auth/login"; import { MyProfilePage } from "../pages/user/my-profile"; import { MyProfileEditFormPage } from "../pages/user/my-profile-edit-form"; import { UserCreateFormPage } from "../pages/user/user-create-form"; import { UserDetailPage } from "../pages/user/user-detail"; import { UserEditFormPage } from "../pages/user/user-edit-form"; import { UserListPage } from "../pages/user/user-list"; import { createUser } from "../utils/user-factory"; useActor(test, "user"); // The user-lifecycle flow's `## Flow Diagram` main path as one journey. test("create a user account, find it in the list, update its profile, view and update own profile, then deactivate and reactivate the account", async ({ page, browser, baseURL, }) => { const suffix = Date.now(); const userName = `Lifecycle User ${suffix}`; // Create User Account — the new account starts ACTIVE; dismiss the // initial-password dialog to continue. const listPage = new UserListPage(page); await listPage.goto(); await expect(listPage.heading).toBeVisible(); await listPage.createButton.click(); const createForm = new UserCreateFormPage(page); await expect(createForm.nameInput).toBeVisible(); await createForm.fill({ name: userName, email: `lifecycle-${suffix}@example.com` }); await createForm.submitButton.click(); await expect(createForm.successDialog).toBeVisible(); await createForm.doneButton.click(); // Browse User List await expect(listPage.heading).toBeVisible(); await expect(listPage.table).toBeVisible(); await expect(listPage.getRow(userName)).toBeVisible(); // View User Detail await listPage.getViewLink(userName).click(); const detailPage = new UserDetailPage(page); await expect(detailPage.heading).toBeVisible(); await expect(detailPage.statusBadge).toBeVisible(); // Update User Profile await detailPage.editButton.click(); const editForm = new UserEditFormPage(page); const updatedName = `Renamed User ${suffix}`; await editForm.nameInput.clear(); await editForm.nameInput.fill(updatedName); await editForm.submitButton.click(); await page.waitForURL(/\/user-management\/user\/[^/]+$/); await expect(page.getByRole("main").getByText(updatedName)).toBeVisible(); // View + Update Own Profile — a dedicated account acts on its own record so // the worker's shared account stays intact. const owner = await createUser({ name: `Owner ${suffix}`, email: `owner-${suffix}@example.com`, permissions: ACTOR_PERMISSIONS.user, }); const ownerContext = await browser.newContext({ baseURL, storageState: { cookies: [], origins: [] }, }); const ownerPage = await ownerContext.newPage(); await new LoginPage(ownerPage).login(owner.email, owner.password); const profilePage = new MyProfilePage(ownerPage); await profilePage.goto(); await expect(profilePage.heading).toBeVisible(); await expect(ownerPage.getByRole("main").getByText(owner.email)).toBeVisible(); await profilePage.editButton.click(); const profileEdit = new MyProfileEditFormPage(ownerPage); const ownName = `Own Renamed ${suffix}`; await profileEdit.nameInput.clear(); await profileEdit.nameInput.fill(ownName); await profileEdit.submitButton.click(); await ownerPage.waitForURL(/\/user-management\/profile\/?$/); await expect(ownerPage.getByRole("main").getByText(ownName)).toBeVisible(); await ownerContext.close(); // Deactivate User await detailPage.deactivateButton.click(); await expect(detailPage.statusBadge).toHaveText(/^inactive$/i); // Reactivate User await detailPage.reactivateButton.click(); await expect(detailPage.statusBadge).toHaveText(/^active$/i); });