refactor testing
Some checks failed
ci/woodpecker/pr/pr Pipeline failed

This commit is contained in:
Madison Grubb
2026-02-17 11:05:57 -05:00
parent b0e8dd7ad9
commit 1a566e2d80
57 changed files with 1127 additions and 1760 deletions

View File

@@ -2,31 +2,34 @@ import { describe, it, expect } from 'vitest'
import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
import Login from '../../app/pages/login.vue'
const wait = (ms = 50) => new Promise(r => setTimeout(r, ms))
describe('login page', () => {
it('renders sign in form (local auth always shown)', async () => {
registerEndpoint('/api/auth/config', () => ({ oidc: { enabled: false, label: '' } }), { method: 'GET' })
const wrapper = await mountSuspended(Login)
await new Promise(r => setTimeout(r, 50))
await wait()
expect(wrapper.text()).toContain('Sign in')
expect(wrapper.find('input[type="text"]').exists()).toBe(true)
expect(wrapper.find('input[type="password"]').exists()).toBe(true)
})
it('shows OIDC button when OIDC is enabled', async () => {
registerEndpoint('/api/auth/config', () => ({ oidc: { enabled: true, label: 'Sign in with Authentik' } }), { method: 'GET' })
it.each([
[{ enabled: true, label: 'Sign in with Authentik' }, true, false],
[{ enabled: true, label: 'Sign in with OIDC' }, true, true],
])('shows OIDC when enabled: %j', async (oidcConfig, shouldShowButton, shouldShowPassword) => {
registerEndpoint('/api/auth/config', () => ({ oidc: oidcConfig }), { method: 'GET' })
await clearNuxtData('auth-config')
const wrapper = await mountSuspended(Login)
await new Promise(r => setTimeout(r, 150))
expect(wrapper.text()).toContain('Sign in with Authentik')
expect(wrapper.find('a[href*="/api/auth/oidc/authorize"]').exists()).toBe(true)
})
it('shows both OIDC button and password form when OIDC is enabled', async () => {
registerEndpoint('/api/auth/config', () => ({ oidc: { enabled: true, label: 'Sign in with OIDC' } }), { method: 'GET' })
await clearNuxtData('auth-config')
const wrapper = await mountSuspended(Login)
await new Promise(r => setTimeout(r, 150))
expect(wrapper.find('a[href*="/api/auth/oidc/authorize"]').exists()).toBe(true)
expect(wrapper.find('input[type="password"]').exists()).toBe(true)
await wait(150)
if (shouldShowButton) {
expect(wrapper.find('a[href*="/api/auth/oidc/authorize"]').exists()).toBe(true)
if (oidcConfig.label) {
expect(wrapper.text()).toContain(oidcConfig.label)
}
}
if (shouldShowPassword) {
expect(wrapper.find('input[type="password"]').exists()).toBe(true)
}
})
})