feat(teams): add Team entity and cutover Person.department to Person.teamId
Co-authored-by: Asis Ferrer <aferrer@aferrer.dev> Co-committed-by: Asis Ferrer <aferrer@aferrer.dev>
This commit was merged in pull request #5.
This commit is contained in:
@@ -27,7 +27,7 @@ async function createPerson(page: Page, name: string, email: string) {
|
||||
await page.goto("/people/new")
|
||||
await page.getByLabel("Nombre").fill(name)
|
||||
await page.getByLabel("Apellido").fill("E2E")
|
||||
await page.getByLabel("Departamento").selectOption("OTHER")
|
||||
await page.getByLabel("Equipo").selectOption({ label: "Other" })
|
||||
await page.getByLabel("Correo electrónico").fill(email)
|
||||
await page.getByLabel("Teléfono").fill("123456789")
|
||||
await page.getByLabel("Rol").selectOption("NO_USER")
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import { expect, type Page, test } from "@playwright/test"
|
||||
|
||||
async function setLocaleCookie(
|
||||
page: Page,
|
||||
locale: "en" | "es",
|
||||
baseURL?: string,
|
||||
) {
|
||||
await page.context().addCookies([
|
||||
{
|
||||
name: "stock-manager-locale",
|
||||
value: locale,
|
||||
url: baseURL ?? "http://127.0.0.1:3100",
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
async function signInAsAdmin(page: Page, baseURL?: string) {
|
||||
await setLocaleCookie(page, "en", baseURL)
|
||||
await page.goto("/login")
|
||||
await page.getByLabel("Email").fill("admin@example.test")
|
||||
await page.getByLabel("Password").fill("admin-password")
|
||||
await page.getByRole("button", { name: "Sign In" }).click()
|
||||
await expect(page).toHaveURL("/")
|
||||
}
|
||||
|
||||
async function createTeam(page: Page, name: string) {
|
||||
await page.goto("/people?tab=teams")
|
||||
await page.getByLabel("Team name").fill(name)
|
||||
await page.getByRole("button", { name: "Create Team" }).click()
|
||||
await expect(page.getByText("Team created successfully")).toBeVisible()
|
||||
}
|
||||
|
||||
test.describe("people and teams", () => {
|
||||
test("switches between people and teams tabs via URL", async ({
|
||||
baseURL,
|
||||
page,
|
||||
}) => {
|
||||
await signInAsAdmin(page, baseURL)
|
||||
await page.goto("/people")
|
||||
|
||||
const sections = page.getByRole("navigation", { name: "People sections" })
|
||||
await expect(sections).toBeVisible()
|
||||
|
||||
await page.goto("/people?tab=people")
|
||||
await expect(
|
||||
sections.getByRole("link", { name: "People" }),
|
||||
).toHaveAttribute("aria-current", "page")
|
||||
|
||||
await page.goto("/people?tab=teams")
|
||||
await expect(sections.getByRole("link", { name: "Teams" })).toHaveAttribute(
|
||||
"aria-current",
|
||||
"page",
|
||||
)
|
||||
await expect(page.getByLabel("Team name")).toBeVisible()
|
||||
|
||||
await page.goto("/people?tab=invalid")
|
||||
await expect(
|
||||
sections.getByRole("link", { name: "People" }),
|
||||
).toHaveAttribute("aria-current", "page")
|
||||
})
|
||||
|
||||
test("creates, renames, and deletes a team", async ({ baseURL, page }) => {
|
||||
const timestamp = Date.now()
|
||||
const originalName = `E2E Team ${timestamp}`
|
||||
const updatedName = `E2E Team Updated ${timestamp}`
|
||||
|
||||
await signInAsAdmin(page, baseURL)
|
||||
await createTeam(page, originalName)
|
||||
|
||||
const row = page.getByRole("row", { name: new RegExp(originalName) })
|
||||
await expect(row).toBeVisible()
|
||||
|
||||
await row.getByRole("button", { name: "Edit team" }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
await expect(dialog).toBeVisible()
|
||||
await dialog.getByLabel("Team name").fill(updatedName)
|
||||
await dialog.getByRole("button", { name: "Update Team" }).click()
|
||||
await expect(dialog).not.toBeVisible()
|
||||
await expect(page.getByText("Team updated successfully")).toBeVisible()
|
||||
await expect(page.getByRole("row", { name: updatedName })).toBeVisible()
|
||||
|
||||
await page
|
||||
.getByRole("row", { name: updatedName })
|
||||
.getByRole("button", { name: "Delete team" })
|
||||
.click()
|
||||
await expect(page.getByText("Team deleted successfully")).toBeVisible()
|
||||
await expect(page.getByRole("row", { name: updatedName })).not.toBeVisible()
|
||||
})
|
||||
|
||||
test("creates a person with a team and shows the team in the list", async ({
|
||||
baseURL,
|
||||
page,
|
||||
}) => {
|
||||
const timestamp = Date.now()
|
||||
const teamName = `E2E Person Team ${timestamp}`
|
||||
const personName = `E2E Person ${timestamp}`
|
||||
|
||||
await signInAsAdmin(page, baseURL)
|
||||
await createTeam(page, teamName)
|
||||
|
||||
await page.goto("/people/new")
|
||||
await page.getByLabel("First Name").fill(personName)
|
||||
await page.getByLabel("Last Name").fill("E2E")
|
||||
await page.getByLabel("Team").selectOption({ label: teamName })
|
||||
await page.getByLabel("Email").fill(`e2e-${timestamp}@example.test`)
|
||||
await page.getByLabel("Phone").fill("123456789")
|
||||
await page.getByLabel("Role").selectOption("NO_USER")
|
||||
await page.getByRole("button", { name: "Create User" }).click()
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
|
||||
await page.goto("/people?tab=people")
|
||||
const row = page.getByRole("row", { name: new RegExp(personName) })
|
||||
await expect(row).toContainText(teamName)
|
||||
|
||||
await row.getByRole("link", { name: "View person" }).click()
|
||||
await expect(page.getByText(teamName)).toBeVisible()
|
||||
})
|
||||
|
||||
test("shows no team fallback for a person without a team", async ({
|
||||
baseURL,
|
||||
page,
|
||||
}) => {
|
||||
const timestamp = Date.now()
|
||||
const personName = `E2E No Team ${timestamp}`
|
||||
|
||||
await signInAsAdmin(page, baseURL)
|
||||
|
||||
await page.goto("/people/new")
|
||||
await page.getByLabel("First Name").fill(personName)
|
||||
await page.getByLabel("Last Name").fill("E2E")
|
||||
await page.getByLabel("Team").selectOption({ value: "" })
|
||||
await page.getByLabel("Email").fill(`e2e-noteam-${timestamp}@example.test`)
|
||||
await page.getByLabel("Phone").fill("123456789")
|
||||
await page.getByLabel("Role").selectOption("NO_USER")
|
||||
await page.getByRole("button", { name: "Create User" }).click()
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
|
||||
await page.goto("/people?tab=people")
|
||||
const row = page.getByRole("row", { name: new RegExp(personName) })
|
||||
await expect(row).toContainText("—")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user