Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions VueApp/src/Personnel/__tests__/eis-academics-category.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import { flushPromises, mount } from "@vue/test-utils"
import { Quasar } from "quasar"
import EisAcademics from "../pages/EisAcademics.vue"
import EisAppointmentCategory from "../pages/EisAppointmentCategory.vue"
import { eisService } from "../services/eis-service"
import type { EisAcademics as EisAcademicsData, EisAppointmentCategories } from "../types/eis-types"

/**
* The Awards & degrees tab shows MyInfoVault entries as text, and the Appointment category tab
* lets EIS administrators set and clear the manual categories.
*/

const EMPLOYEE_ID = "10123456"
const mocked = vi.hoisted(() => ({ route: { params: { employeeId: "" } } }))
vi.mock("vue-router", async () => {
// Reactive, so a test can move to another employee the way the person picker does.
const { reactive } = await import("vue")
mocked.route = reactive({ params: { employeeId: "" } })
return { useRoute: () => mocked.route }
})
vi.mock("../services/eis-service", () => ({
eisService: {
getAcademics: vi.fn<(...args: unknown[]) => unknown>(),
getCategories: vi.fn<(...args: unknown[]) => unknown>(),
setFlag: vi.fn<(...args: unknown[]) => unknown>(),
},
}))

const academics: EisAcademicsData = {
hasMivAccount: true,
degrees: [{ year: "1994", degree: "DVM", institution: "UC Davis", location: "Davis, CA", field: "Medicine" }],
boards: [{ year: "2001-present", text: "ACVIM" }],
memberships: ["AVMA"],
researchFocus: ["Virology"],
specialtyFocus: ["Equine"],
honors: [{ year: "2010", text: "Teaching award" }],
}

function categories(canEditFlags: boolean, directorApplies = false): EisAppointmentCategories {
return {
academicYear: "2026-2027",
canEditFlags,
categories: [
{ label: "Dean", applies: true, flagCode: null },
{ label: "Resident", applies: false, flagCode: null },
{ label: "Director", applies: directorApplies, flagCode: 4 },
],
}
}

beforeEach(() => {
mocked.route.params.employeeId = EMPLOYEE_ID
})

async function mountTab(component: object) {
const wrapper = mount(component, { global: { plugins: [Quasar] } })
await flushPromises()
return wrapper
}

function missing(text: string, expected: string[]): string[] {
return expected.filter((item) => !text.includes(item))
}

describe("eisAcademics.vue", () => {
it("shows each kind of MyInfoVault entry", async () => {
expect.hasAssertions()
vi.mocked(eisService.getAcademics).mockResolvedValue(academics)

const wrapper = await mountTab(EisAcademics)

expect(
missing(wrapper.text(), [
"UC Davis",
"2001-present",
"ACVIM",
"AVMA",
"Virology",
"Equine",
"Teaching award",
]),
).toStrictEqual([])
})

it("says when each list is empty", async () => {
expect.hasAssertions()
vi.mocked(eisService.getAcademics).mockResolvedValue({
...academics,
degrees: [],
boards: [],
memberships: [],
researchFocus: [],
specialtyFocus: [],
honors: [],
})

const wrapper = await mountTab(EisAcademics)

expect(
missing(wrapper.text(), [
"No degree information.",
"No board or license information.",
"No membership information.",
"No research focus information.",
"No specialty focus information.",
"No award or honor information.",
]),
).toStrictEqual([])
})

it("explains a missing MyInfoVault account or a failed load", async () => {
expect.hasAssertions()
vi.mocked(eisService.getAcademics).mockResolvedValue({ ...academics, hasMivAccount: false })
const noAccount = await mountTab(EisAcademics)

vi.mocked(eisService.getAcademics).mockResolvedValue(null)
const failed = await mountTab(EisAcademics)

expect(noAccount.text()).toContain("no MyInfoVault account")
expect(failed.text()).toContain("could not be loaded")
})
})

describe("eisAppointmentCategory.vue", () => {
it("ticks the categories that apply and locks the manual ones for non-admins", async () => {
expect.hasAssertions()
vi.mocked(eisService.getCategories).mockResolvedValue(categories(false))

const wrapper = await mountTab(EisAppointmentCategory)
const text = wrapper.text()

expect(
missing(text, ["Dean(applies)", "Resident(does not apply)", "2026-2027", "Only EIS administrators"]),
).toStrictEqual([])
expect(wrapper.find('[role="checkbox"]').attributes("aria-disabled")).toBe("true")
})

it("lets an admin set a manual category and shows the updated categories", async () => {
expect.hasAssertions()
vi.mocked(eisService.getCategories).mockResolvedValue(categories(true))
vi.mocked(eisService.setFlag).mockResolvedValue(categories(true, true))

const wrapper = await mountTab(EisAppointmentCategory)
await wrapper.find('[role="checkbox"]').trigger("click")
await flushPromises()

expect(eisService.setFlag).toHaveBeenCalledWith(EMPLOYEE_ID, 4, true)
expect(wrapper.find('[role="checkbox"]').attributes("aria-checked")).toBe("true")
expect(wrapper.text()).not.toContain("Only EIS administrators")
expect(document.body.textContent).toContain("Category updated.")
})

it("ignores a save that finishes after the user has moved to another employee", async () => {
expect.hasAssertions()
vi.mocked(eisService.getCategories).mockResolvedValue(categories(true))
const save: { finish?: (updated: EisAppointmentCategories | null) => void } = {}
vi.mocked(eisService.setFlag).mockReturnValue(
new Promise((resolve) => {
save.finish = resolve
}),
)
const wrapper = await mountTab(EisAppointmentCategory)
await wrapper.find('[role="checkbox"]').trigger("click")

mocked.route.params.employeeId = "10765432"
await flushPromises()
save.finish?.(categories(true, true))
await flushPromises()

expect(eisService.setFlag).toHaveBeenCalledWith(EMPLOYEE_ID, 4, true)
expect(eisService.getCategories).toHaveBeenLastCalledWith("10765432")
expect(wrapper.find('[role="checkbox"]').attributes("aria-checked")).toBe("false")
expect(wrapper.find('[role="checkbox"]').attributes("aria-disabled")).not.toBe("true")
})

it("keeps a save's result when a reload of the same employee resolves after it", async () => {
expect.hasAssertions()
const reload: { finish?: (value: EisAppointmentCategories | null) => void } = {}
vi.mocked(eisService.getCategories)
.mockResolvedValueOnce(categories(true)) // The initial load for this employee
.mockResolvedValueOnce(categories(true)) // The load after navigating away
.mockReturnValueOnce(
// The load after navigating back, held open - this is the stale response.
new Promise((resolve) => {
reload.finish = resolve
}),
)
const save: { finish?: (updated: EisAppointmentCategories | null) => void } = {}
vi.mocked(eisService.setFlag).mockReturnValue(
new Promise((resolve) => {
save.finish = resolve
}),
)
const wrapper = await mountTab(EisAppointmentCategory)
await wrapper.find('[role="checkbox"]').trigger("click")

mocked.route.params.employeeId = "10765432"
await flushPromises()
mocked.route.params.employeeId = EMPLOYEE_ID
await flushPromises()

// The save completes first, with the category now applied...
save.finish?.(categories(true, true))
await flushPromises()
// ...and the reload that started before it resolves afterward, with the category as it
// was before the save - a response to a request the server saw before the save committed.
reload.finish?.(categories(true, false))
await flushPromises()

expect(wrapper.find('[role="checkbox"]').attributes("aria-checked")).toBe("true")
})

it("says when a change fails or the categories could not be loaded", async () => {
expect.hasAssertions()
vi.mocked(eisService.getCategories).mockResolvedValue(categories(true))
vi.mocked(eisService.setFlag).mockResolvedValue(null)
const wrapper = await mountTab(EisAppointmentCategory)
await wrapper.find('[role="checkbox"]').trigger("click")
await flushPromises()

vi.mocked(eisService.getCategories).mockResolvedValue(null)
const failed = await mountTab(EisAppointmentCategory)

expect(wrapper.text()).toContain("could not be changed")
expect(wrapper.find('[role="checkbox"]').attributes("aria-checked")).toBe("false")
expect(failed.text()).toContain("could not be loaded")
})
})
30 changes: 30 additions & 0 deletions VueApp/src/Personnel/__tests__/eis-fact-list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { mount } from "@vue/test-utils"
import EisFactList from "../components/EisFactList.vue"

/**
* The fact list starts each row of related facts on a new line, so a lone fact (such as Email)
* leaves the second column empty instead of pulling the next pair up beside it.
*/

describe("eisFactList.vue", () => {
it("marks the first fact of each row and links facts with an href", () => {
expect.hasAssertions()
const wrapper = mount(EisFactList, {
props: {
rows: [
[{ label: "Email", value: "ada@ucdavis.edu", href: "mailto:ada@ucdavis.edu" }],
[
{ label: "Date of birth", value: "12/1815" },
{ label: "Age", value: null },
],
],
},
})

const facts = wrapper.findAll(".eis-fact")
expect(facts.map((fact) => fact.find("dt").text())).toStrictEqual(["Email", "Date of birth", "Age"])
expect(facts.map((fact) => fact.classes("eis-fact--row-start"))).toStrictEqual([true, true, false])
expect(wrapper.find("a[href='mailto:ada@ucdavis.edu']").text()).toBe("ada@ucdavis.edu")
expect(facts[2]?.find("dd").text()).toBe("")
})
})
125 changes: 125 additions & 0 deletions VueApp/src/Personnel/__tests__/eis-facts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { headerFacts, listingFacts, summaryFacts } from "../utils/eis-facts"
import type { EisFactRow, EisFactSection } from "../utils/eis-facts"
import type { EisPersonHeader } from "../types/eis-types"

/**
* The EIS fact lists pair related facts on one line as the legacy header did, keep missing
* values as null (shown blank) and leave out what a person doesn't have: staff and faculty
* programs, and a PTO balance of zero.
*/

const person: EisPersonHeader = {
employeeId: "10123456",
name: "Lovelace, Ada",
email: null,
dateOfBirth: null,
age: null,
gender: null,
ethnicity: null,
hireDate: null,
employmentStatus: null,
citizenship: null,
visa: null,
primaryAffiliation: null,
primaryTitle: null,
jobGroup: null,
homeDepartment: null,
alternateDepartment: null,
bargainingUnit: null,
laborRelationsUnit: null,
isStaff: false,
staffProgram: null,
staffStatus: null,
isFaculty: false,
facultyProgram: null,
ladderRank: null,
serviceCreditMonths: 0,
vacationHours: null,
sickHours: null,
ptoHours: 0,
}

function labels(rows: EisFactRow[]): string[] {
return rows.flat().map((fact) => fact.label)
}

/** Every row of every Summary section, in order. */
function summaryRows(sections: EisFactSection[]): EisFactRow[] {
return sections.flatMap((section) => section.rows)
}

/** Each row's labels joined, so the pairing is easy to read in the expectations. */
function lines(rows: EisFactRow[]): string[] {
return rows.map((row) => row.map((fact) => fact.label).join(" | "))
}

describe("eis-facts", () => {
it("links the email and shows PTO only when there is a balance", () => {
expect.hasAssertions()
const facts = summaryRows(summaryFacts({ ...person, email: "ada@ucdavis.edu", ptoHours: 8 }))

expect(facts[0]).toStrictEqual([{ label: "Email", value: "ada@ucdavis.edu", href: "mailto:ada@ucdavis.edu" }])
expect(labels(facts)).toContain("PTO balance")
expect(summaryRows(summaryFacts(person))[0]).toStrictEqual([{ label: "Email", value: null }])
expect(labels(summaryRows(summaryFacts(person)))).not.toContain("PTO balance")
})

it("pairs related facts the way the legacy header did", () => {
expect.hasAssertions()

expect(lines(headerFacts({ ...person, isStaff: true, isFaculty: true }))).toStrictEqual([
"Employee ID",
"Primary affiliation",
"Primary title | Job group ID",
"Home department | Alternate department",
"Staff program | Staff type",
"Faculty program | Ladder rank",
])
})

it("keeps the legacy order in the Summary, split into personal, position, and service and leave", () => {
expect.hasAssertions()
const sections = summaryFacts({ ...person, ptoHours: 8 })

expect(sections.map((section) => [section.title, lines(section.rows)])).toStrictEqual([
[
"Personal",
[
"Email",
"Date of birth | Age",
"Gender | Ethnicity",
"Hire date | Employment status",
"US citizen | Visa type",
],
],
["Position", ["Bargaining unit | Labor relations unit"]],
["Service and leave", ["Service credit | Vacation balance", "Sick leave balance | PTO balance"]],
])
})

it("adds the staff and faculty programs only for people who hold them", () => {
expect.hasAssertions()

expect(labels(headerFacts(person))).not.toContain("Staff program")
expect(labels(headerFacts({ ...person, isStaff: true, isFaculty: true }))).toStrictEqual(
expect.arrayContaining(["Staff program", "Staff type", "Faculty program", "Ladder rank"]),
)
})

it("lists a campus listing's details", () => {
expect.hasAssertions()
const facts = listingFacts({
isPrimary: true,
isPublic: true,
title: "Professor",
department: null,
address: null,
phone: null,
})

expect(facts.map((row) => row.map((fact) => fact.value))).toStrictEqual([
["Professor", null],
[null, null],
])
})
})
Loading
Loading