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
2 changes: 2 additions & 0 deletions VueApp/.fallowrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"src/ClinicalScheduler/clinicalscheduler.ts",
"src/Computing/computing.ts",
"src/Effort/effort.ts",
"src/Reports/reports.ts",
"src/Students/students.ts",
"src/CAHFS/index.html",
"src/CMS/index.html",
Expand All @@ -15,6 +16,7 @@
"src/Computing/index.html",
"src/Effort/index.html",
"src/Personnel/index.html",
"src/Reports/index.html",
"src/Students/index.html"
],
"ignorePatterns": [
Expand Down
14 changes: 14 additions & 0 deletions VueApp/src/Personnel/__tests__/personnel-home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mount } from "@vue/test-utils"
import Home from "../pages/Home.vue"

/** The Personnel home page shows its CMS content; Personnel reports are in the Report Builder. */

describe("personnel home page", () => {
it("shows the CMS content", () => {
expect.hasAssertions()

const wrapper = mount(Home, { global: { stubs: { CmsContent: true } } })

expect(wrapper.findComponent({ name: "CmsContent" }).props("contentName")).toBe("personnel-home")
})
})
4 changes: 4 additions & 0 deletions VueApp/src/Personnel/__tests__/router-permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const { mockRequireLogin } = vi.hoisted(() => ({
vi.mock("@/composables/RequireLogin", () => ({
useRequireLogin: () => ({ requireLogin: (...args: unknown[]) => mockRequireLogin(...args) }),
getLoginUrl: () => ({ value: "" }),
createAuthenticator: (permission: string) => async () => {
const loginResult = await mockRequireLogin(true, permission)
return loginResult === null || loginResult
},
}))

/**
Expand Down
16 changes: 4 additions & 12 deletions VueApp/src/Personnel/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { createSpaRouter } from "@/shared/create-spa-router"
import type { NavigationGuard, RouteLocationNormalized } from "vue-router"
import { routes } from "./routes"
import { useRequireLogin } from "@/composables/RequireLogin"
import { createAuthenticator } from "@/composables/RequireLogin"
import { useUserStore } from "@/store/UserStore"
import { checkHasOnePermission } from "@/composables/CheckPagePermission"

const router = createSpaRouter(routes)

/**
* Signs the visitor in and loads the SVMSecure.PhoneLists permissions in the same request.
* Those roles are the only permissions anything in this SPA reads, so asking requireLogin for
* them directly leaves no second permission set to fetch or keep in sync.
* A null result means requireLogin reached no verdict, which is not a refusal.
*/
async function authenticate(to: RouteLocationNormalized): Promise<boolean> {
const { requireLogin } = useRequireLogin(to)
const loginResult = await requireLogin(true, "SVMSecure.PhoneLists")
return loginResult === null || loginResult
}
// Those are the only permissions anything in this SPA reads, so asking requireLogin for them
// directly leaves no second permission set to fetch or keep in sync.
const authenticate = createAuthenticator("SVMSecure.PhoneLists")

/**
* An in-app navigation (tab switch, list to list) is already signed in and already holds its
Expand Down
13 changes: 13 additions & 0 deletions VueApp/src/Reports/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<!-- Reports come from every area, so this SPA has no section menu of its own. -->
<component
:is="$route.meta.layout || 'div'"
:navarea="false"
>
</component>
<GenericError />
</template>

<script setup lang="ts">
import GenericError from "@/components/GenericError.vue"
</script>
11 changes: 11 additions & 0 deletions VueApp/src/Reports/__tests__/deferred.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** A promise the test settles by hand, to hold a request in flight. */
function deferred<T>() {
let settle: ((value: T) => void) | null = null
// eslint-disable-next-line avoid-new -- a promise the test settles by hand
const promise = new Promise<T>((resolve) => {
settle = resolve
})
return { promise, resolve: (value: T) => settle?.(value) }
}

export { deferred }
171 changes: 171 additions & 0 deletions VueApp/src/Reports/__tests__/report-admin-edit-form.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { mount } from "@vue/test-utils"
import { Quasar } from "quasar"
import ReportAdminEditForm from "../components/ReportAdminEditForm.vue"
import { toForm } from "../admin/report-admin-form"
import { rosterReport, saved } from "./report-admin-fixtures"

/**
* ReportAdminEditForm only wires its children's v-models and events to its own props, so each
* child is stubbed and its events are emitted directly: the children's own behavior is covered by
* their own tests.
*/
const global = {
plugins: [[Quasar, {}]] as [typeof Quasar, object][],
stubs: {
ReportAdminStatus: true,
ReportAdminBasics: true,
ReportAdminColumns: true,
ReportAdminParameters: true,
ReportAdminDisplay: true,
ReportAdminPermissions: true,
ReportAdminPreview: true,
ReportAdminHistory: true,
},
}

function mountForm(overrides: Record<string, unknown> = {}) {
return mount(ReportAdminEditForm, {
props: {
modelValue: toForm(rosterReport),
definition: saved,
sources: [],
sourcesFailed: false,
columnsError: null,
sourceColumns: [],
canAddMissing: false,
targets: [],
isView: true,
views: [],
errors: [],
conflict: false,
saving: false,
isDirty: false,
request: rosterReport,
changeSource: vi.fn<() => Promise<void>>(),
addMissingColumns: vi.fn<() => void>(),
save: vi.fn<() => Promise<void>>(),
setDeleted: vi.fn<() => Promise<void>>(),
reload: vi.fn<() => Promise<void>>(),
applyVersion: vi.fn<() => Promise<void>>(),
...overrides,
},
global,
})
}

function saveButton(wrapper: ReturnType<typeof mountForm>) {
return wrapper.findAllComponents({ name: "QBtn" }).find((button) => button.props("type") === "submit")
}

describe("report admin edit form", () => {
it("deletes and restores through the status bar", () => {
expect.hasAssertions()
const setDeleted = vi.fn<() => Promise<void>>()
const wrapper = mountForm({ setDeleted })

wrapper.findComponent({ name: "ReportAdminStatus" }).vm.$emit("delete")
wrapper.findComponent({ name: "ReportAdminStatus" }).vm.$emit("restore")

expect(setDeleted.mock.calls).toStrictEqual([[true], [false]])
})

it("replaces the whole form from basics and display", () => {
expect.hasAssertions()
const wrapper = mountForm()
const form = toForm(rosterReport)

wrapper.findComponent({ name: "ReportAdminBasics" }).vm.$emit("update:modelValue", { ...form, title: "New" })
wrapper.findComponent({ name: "ReportAdminDisplay" }).vm.$emit("update:modelValue", { ...form, area: "Effort" })

const updates = wrapper.emitted("update:modelValue")!
expect(updates.map((update) => update[0])).toStrictEqual([
{ ...form, title: "New" },
{ ...form, area: "Effort" },
])
})

// Columns/parameters/permissions each v-model one field of the form rather than the whole
// thing, so a child's update mutates that field on the shared form object in place - it
// doesn't itself emit update:modelValue (ReportAdminEditForm only forwards whole-form
// replacements upward). The mutation still reaches whoever holds the same form reference,
// including the test's own modelValue prop.
it("updates the form's columns, parameters and permissions in place", () => {
expect.hasAssertions()
const wrapper = mountForm()

wrapper.findComponent({ name: "ReportAdminColumns" }).vm.$emit("update:modelValue", [])
wrapper.findComponent({ name: "ReportAdminParameters" }).vm.$emit("update:modelValue", [])
wrapper.findComponent({ name: "ReportAdminPermissions" }).vm.$emit("update:modelValue", ["SVMSecure.Effort"])

const form = wrapper.props("modelValue") as ReturnType<typeof toForm>
expect([form.columns, form.parameters, form.permissions]).toStrictEqual([[], [], ["SVMSecure.Effort"]])
expect(wrapper.emitted("update:modelValue")).toBeUndefined()
})

it("asks for a new source", () => {
expect.hasAssertions()
const changeSource = vi.fn<() => Promise<void>>()
const wrapper = mountForm({ changeSource })

wrapper.findComponent({ name: "ReportAdminBasics" }).vm.$emit("source", "usp_Leave")

expect(changeSource).toHaveBeenCalledWith("usp_Leave")
})

it("adds the source's missing columns", () => {
expect.hasAssertions()
const addMissingColumns = vi.fn<() => void>()
const wrapper = mountForm({ addMissingColumns })

wrapper.findComponent({ name: "ReportAdminColumns" }).vm.$emit("add-missing")

expect(addMissingColumns).toHaveBeenCalledOnce()
})

it("applies an earlier version from history", () => {
expect.hasAssertions()
const applyVersion = vi.fn<() => Promise<void>>()
const wrapper = mountForm({ applyVersion })

wrapper.findComponent({ name: "ReportAdminHistory" }).vm.$emit("load", rosterReport)

expect(applyVersion).toHaveBeenCalledWith(rosterReport)
})

it("submits the form to save", async () => {
expect.hasAssertions()
const save = vi.fn<() => Promise<void>>()
const wrapper = mountForm({ save })

await wrapper.get("form").trigger("submit")

expect(save).toHaveBeenCalledOnce()
})

it("shows the errors, a reload action when they conflict, and unsaved-changes note", async () => {
expect.hasAssertions()
const reload = vi.fn<() => Promise<void>>()
const wrapper = mountForm({ errors: ["Someone else saved it."], conflict: true, isDirty: true, reload })

expect(wrapper.text()).toContain("Someone else saved it.")
expect(wrapper.text()).toContain("Unsaved changes")

await wrapper
.findAll("button")
.find((button) => button.text() === "Reload the saved report")
?.trigger("click")

expect(reload).toHaveBeenCalledOnce()
})

it("labels and disables the save button for a new, saved or deleted report", () => {
expect.hasAssertions()
const creating = mountForm({ definition: null })
const deleted = mountForm({ definition: { ...saved, deletedOn: "2026-11-16T10:00:00" } })

expect(saveButton(creating)?.props("label")).toBe("Create report")
expect(saveButton(mountForm())?.props("label")).toBe("Save")
expect(saveButton(deleted)?.props("disable")).toBeTruthy()
expect(mountForm({ saving: true }).text()).toContain("Saving")
})
})
Loading
Loading