-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(students): finish the Razor to Vue migration for class years #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
VueApp/src/Students/__tests__/student-class-year-permissions.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { nextTick } from "vue" | ||
| import { setActivePinia, createPinia } from "pinia" | ||
| import { mount } from "@vue/test-utils" | ||
| import { Quasar } from "quasar" | ||
| import { useUserStore } from "@/store/UserStore" | ||
| import StudentClassYear from "@/Students/pages/StudentClassYear.vue" | ||
| import { routes } from "../router/routes" | ||
|
|
||
| // Every class-year mutation requires SVMSecure.SIS.AllStudents on the server, so a user with | ||
| // only SVMSecure.Students must not be offered controls that would come back 403. | ||
| const SIS = "SVMSecure.SIS.AllStudents" | ||
| const STUDENTS_ONLY = ["SVMSecure.Students"] | ||
|
|
||
| vi.mock("@/composables/ViperFetch", () => ({ | ||
| useFetch: () => ({ | ||
| get: vi.fn<(...args: unknown[]) => unknown>().mockResolvedValue({ success: true, result: [] }), | ||
| put: vi.fn<(...args: unknown[]) => unknown>(), | ||
| del: vi.fn<(...args: unknown[]) => unknown>(), | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock("vue-router", () => ({ | ||
| useRoute: () => ({ query: {} }), | ||
| })) | ||
|
|
||
| function signInWith(permissions: string[]) { | ||
| setActivePinia(createPinia()) | ||
| useUserStore().setPermissions(permissions) | ||
| } | ||
|
|
||
| function mountPage() { | ||
| return mount(StudentClassYear, { | ||
| global: { | ||
| plugins: [[Quasar, {}]], | ||
| provide: { apiURL: import.meta.env.VITE_API_URL, viperOneUrl: "http://localhost/" }, | ||
| // QDialog teleports to body; render it inline so its contents are assertable. | ||
| stubs: { StatusBadge: true, teleport: true }, | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
| } | ||
|
|
||
| function enterClassYearRoute(query: Record<string, string>) { | ||
| const classYearRoute = routes.find((r) => r.path === "/Students/StudentClassYear") | ||
| const guard = classYearRoute?.beforeEnter as (to: { query: Record<string, string> }) => unknown | ||
|
|
||
| return guard({ query }) | ||
| } | ||
|
|
||
| // The update dialog only exists once a class year is selected. | ||
| async function mountPageWithDialogOpen() { | ||
| const wrapper = mountPage() | ||
| ;(wrapper.vm as unknown as { showForm: boolean }).showForm = true | ||
| await nextTick() | ||
| return wrapper | ||
| } | ||
|
|
||
| // The import control needs a selected class year as well as the permission, and the class | ||
| // year defaults to 0, so assert on it only once a year is chosen. | ||
| async function mountPageWithClassYear() { | ||
| const wrapper = mountPage() | ||
| ;(wrapper.vm as unknown as { classYear: { label: string; value: number } }).classYear = { | ||
| label: "Class of 2028", | ||
| value: 2028, | ||
| } | ||
| await nextTick() | ||
| return wrapper | ||
| } | ||
|
|
||
| describe("student class year permissions", () => { | ||
| it("offers delete and save to a user with SIS.AllStudents", async () => { | ||
| expect.hasAssertions() | ||
| signInWith([...STUDENTS_ONLY, SIS]) | ||
|
|
||
| const wrapper = await mountPageWithDialogOpen() | ||
| const text = wrapper.text() | ||
|
|
||
| expect(text).toContain("Delete") | ||
| expect(text).toContain("Save") | ||
| }) | ||
|
|
||
| it("hides delete and save from a user with only SVMSecure.Students", async () => { | ||
| expect.hasAssertions() | ||
| signInWith(STUDENTS_ONLY) | ||
|
|
||
| const wrapper = await mountPageWithDialogOpen() | ||
| const text = wrapper.text() | ||
|
|
||
| // Guard against the assertions passing just because the dialog never opened. | ||
| expect(text).toContain("Current class year") | ||
| expect(text).not.toContain("Delete") | ||
| expect(text).not.toContain("Save") | ||
| }) | ||
|
|
||
| // Pairs with the test below: without this one, dropping the permission check from the | ||
| // import button would still leave the negative assertion passing on the class year alone. | ||
| it("offers the class year import link to a user with SIS.AllStudents", async () => { | ||
| expect.hasAssertions() | ||
| signInWith([...STUDENTS_ONLY, SIS]) | ||
|
|
||
| const wrapper = await mountPageWithClassYear() | ||
|
|
||
| expect(wrapper.text()).toContain("Import students into") | ||
| }) | ||
|
|
||
| it("hides the class year import link from a user without SIS.AllStudents", async () => { | ||
| expect.hasAssertions() | ||
| signInWith(STUDENTS_ONLY) | ||
|
|
||
| const wrapper = await mountPageWithClassYear() | ||
|
|
||
| expect(wrapper.text()).not.toContain("Import students into") | ||
| }) | ||
|
|
||
| it("gates the class year import route on SIS.AllStudents", () => { | ||
| expect.hasAssertions() | ||
|
|
||
| const importRoute = routes.find((r) => r.path === "/Students/StudentClassYearImport") | ||
|
|
||
| expect(importRoute?.meta?.permissions).toStrictEqual([SIS]) | ||
| }) | ||
|
|
||
| it("sends the Razor ?import bookmark to the import route, keeping the class year", () => { | ||
| expect.hasAssertions() | ||
|
|
||
| expect(enterClassYearRoute({ import: "1", classYear: "2028" })).toStrictEqual({ | ||
| path: "/Students/StudentClassYearImport", | ||
| query: { classYear: "2028" }, | ||
| }) | ||
| }) | ||
|
|
||
| it("leaves the class year page alone when there is no import query", () => { | ||
| expect.hasAssertions() | ||
|
|
||
| expect(enterClassYearRoute({ classYear: "2028" })).toBeTruthy() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.