test(people): update tests for teamId and add people e2e spec

This commit is contained in:
2026-06-26 01:29:04 +02:00
parent e3434d9c58
commit fadff5251f
22 changed files with 550 additions and 233 deletions
@@ -10,6 +10,7 @@ const mocks = vi.hoisted(() => ({
getI18n: vi.fn(),
findByIdWithUser: vi.fn(),
findById: vi.fn(),
listTeamsUseCase: vi.fn(),
personForm: vi.fn(),
push: vi.fn(),
toastError: vi.fn(),
@@ -27,6 +28,10 @@ vi.mock("@/services/person.service", () => ({
},
}))
vi.mock("@/use-cases/team.use-cases", () => ({
listTeamsUseCase: mocks.listTeamsUseCase,
}))
vi.mock("@/app/(dashboard)/people/_components/edit.person.form", () => ({
default: (props: unknown) => {
mocks.personForm(props)
@@ -54,8 +59,8 @@ const basePerson: PersonWithUser = {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: null,
team: null,
email: "ada@example.test",
phone: "1234",
userId: null,
@@ -80,10 +85,16 @@ const personWithUser: PersonWithUser = {
},
}
const teams = [
{ id: "team-1", name: "Engineering" },
{ id: "team-2", name: "Sales" },
]
describe("edit person page wiring", () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.getI18n.mockResolvedValue({ dictionary: en, locale: "en" })
mocks.listTeamsUseCase.mockResolvedValue(teams)
})
it("loads the person without user, passes PersonWithoutUser to the edit form", async () => {
@@ -112,6 +123,7 @@ describe("edit person page wiring", () => {
...en.inventory.people.schema,
},
roleLabels: en.admin.users.roles,
teams,
}),
)
})
@@ -142,10 +154,7 @@ describe("edit person page wiring", () => {
}),
formCopy: es.admin.users.form,
roleLabels: es.admin.users.roles,
departmentCopy: es.inventory.people.departments,
fallbackCopy: expect.objectContaining({
unknownDepartment: es.inventory.people.fallback.unknownDepartment,
}),
teams,
}),
)
})
@@ -7,6 +7,7 @@ const mocks = vi.hoisted(() => ({
getI18n: vi.fn(),
findByIdWithUser: vi.fn(),
findById: vi.fn(),
listTeamsUseCase: vi.fn(),
redirect: vi.fn(),
personForm: vi.fn(),
}))
@@ -22,6 +23,10 @@ vi.mock("@/services/person.service", () => ({
},
}))
vi.mock("@/use-cases/team.use-cases", () => ({
listTeamsUseCase: mocks.listTeamsUseCase,
}))
vi.mock("next/navigation", () => ({
redirect: mocks.redirect,
useRouter: () => ({
@@ -49,10 +54,16 @@ vi.mock("sonner", () => ({
},
}))
const teams = [
{ id: "team-1", name: "Engineering" },
{ id: "team-2", name: "Sales" },
]
describe("person pages", () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
mocks.listTeamsUseCase.mockResolvedValue(teams)
})
it("renders the edit person page with Person heading and passes person to unified form", async () => {
@@ -66,7 +77,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "ENGINEERING",
teamId: "team-1",
team: { id: "team-1", name: "Engineering" },
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -88,6 +100,7 @@ describe("person pages", () => {
firstName: "Ada",
lastName: "Lovelace",
}),
teams,
}),
)
})
+14 -8
View File
@@ -67,7 +67,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "ENGINEERING",
teamId: "team-1",
team: { id: "team-1", name: "Engineering" },
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -87,7 +88,7 @@ describe("person pages", () => {
expect(html).toContain("Add Person")
// No username column — username header must not appear
expect(html).not.toContain("Username")
// No standalone username cell — only name, email, phone, department columns
// No standalone username cell — only name, email, phone, team columns
expect(html).not.toContain(">ada<")
// Name and other fields rendered
expect(html).toContain("Ada Lovelace")
@@ -110,7 +111,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "ENGINEERING",
teamId: "team-1",
team: { id: "team-1", name: "Engineering" },
userId: "user-1",
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -137,7 +139,8 @@ describe("person pages", () => {
lastName: "Jones",
email: "bob@example.test",
phone: null,
department: "IT",
teamId: null,
team: null,
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -193,7 +196,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "DRIVER",
teamId: "team-2",
team: { id: "team-2", name: "Driver" },
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -221,7 +225,7 @@ describe("person pages", () => {
// Person detail fields
expect(html).toContain("Email")
expect(html).toContain("Phone")
expect(html).toContain("Department")
expect(html).toContain("Team")
expect(html).toContain("ada@example.test")
expect(html).toContain("Driver")
// Embedded assignments
@@ -239,7 +243,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "DRIVER",
teamId: null,
team: null,
userId: "user-1",
isActive: true,
createdAt: new Date("2024-01-01"),
@@ -287,7 +292,8 @@ describe("person pages", () => {
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "DRIVER",
teamId: null,
team: null,
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),