Files
LiamPietralla 4fe6f9d7b5
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m17s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Skipped
Build and Publish / Build Yale Access Backend (pull_request) Successful in 2m12s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Skipped
Add backend and frontend tests and run them in CI
- Backend: xUnit integration tests (auth, rate limiting, people, lock codes,
  validation, error handling) using WebApplicationFactory with a fake lock
- Frontend: Vitest + Nuxt test utils for useApi, the auth middleware,
  LoginForm, UserCodeList and PeopleList
- Run both suites in CI before building
2026-11-16 12:23:32 +11:00

38 lines
1.3 KiB
TypeScript

import { expect } from 'vitest'
import { defineComponent, h, nextTick, type Component } from 'vue'
import { flushPromises } from '@vue/test-utils'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { UApp } from '#components'
/** Mounts a component inside <UApp>, which modals and toasts need. */
export const mountInApp = (component: Component) =>
mountSuspended(defineComponent({ render: () => h(UApp, null, { default: () => h(component) }) }))
/** Lets promises, reactivity and (async) form validation settle. */
export const settle = async () => {
for (let i = 0; i < 4; i++) {
await flushPromises()
await nextTick()
}
}
/** Modals render in a portal, so query the whole document. */
export const inBody = <T extends Element = HTMLElement>(selector: string) => document.body.querySelector<T>(selector)
export const setInput = async (input: HTMLInputElement, value: string) => {
input.value = value
input.dispatchEvent(new Event('input', { bubbles: true }))
await settle()
}
export const submitForm = async (form: HTMLFormElement) => {
form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
await settle()
}
export const click = async (el: Element | null) => {
expect(el, 'element to click').not.toBeNull()
;(el as HTMLElement).click()
await settle()
}