Files
traefik-llmgateway/webui/src/composables/useTargetPicker.spec.ts
T
lukaszraczylo 05a7c114f5 fix(admin-ui): page-level loading, stale and form fixes
Fetch the consumers list on the user detail page so admin and grant data show on a deep link.
Gate Recent errors, the Spend total and the forecast card on load state instead of showing zeros.
Show a stale notice on top lists when a refresh fails.
Clear the target name when the target kind changes.
Ignore out-of-order config responses.
Wrap long group names and event messages, and announce projected budget overruns to screen readers.
Regenerate admin_assets_gen.go.
2026-11-08 02:04:23 +00:00

58 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { useTargetPicker } from './useTargetPicker'
describe('useTargetPicker', () => {
it('defaults to targetKind "group" with an empty targetName', () => {
const picker = useTargetPicker(() => ['eng'], () => ['alice'])
expect(picker.targetKind.value).toBe('group')
expect(picker.targetName.value).toBe('')
})
it('targetNames reads groupNames() while targetKind is "group", userNames() while "user"', () => {
const picker = useTargetPicker(() => ['eng', 'ops'], () => ['alice', 'bob'])
expect(picker.targetNames.value).toEqual(['eng', 'ops'])
picker.targetKind.value = 'user'
expect(picker.targetNames.value).toEqual(['alice', 'bob'])
})
it('nameValid applies isValidName for a group target', () => {
const picker = useTargetPicker(() => [], () => [])
picker.targetName.value = 'valid-name.1'
expect(picker.nameValid.value).toBe(true)
picker.targetName.value = 'has spaces'
expect(picker.nameValid.value).toBe(false)
})
it('nameValid applies isValidUserName (non-empty only) for a user target', () => {
const picker = useTargetPicker(() => [], () => [])
picker.targetKind.value = 'user'
picker.targetName.value = 'has spaces are fine for a user'
expect(picker.nameValid.value).toBe(true)
picker.targetName.value = ' '
expect(picker.nameValid.value).toBe(false)
})
it('snippetLabel names middleware.yaml for a group target', () => {
const picker = useTargetPicker(() => [], () => [])
expect(picker.snippetLabel.value).toBe('Paste into middleware.yaml')
})
it('snippetLabel names the user\'s users.json line, with the current target name, for a user target', () => {
const picker = useTargetPicker(() => [], () => [])
picker.targetKind.value = 'user'
picker.targetName.value = 'alice'
expect(picker.snippetLabel.value).toBe('Merge into alice’s users.json line')
})
})
describe('useTargetPicker kind switch', () => {
it('clears targetName when targetKind changes so a stale name cannot leak across kinds', () => {
const picker = useTargetPicker(() => ['admins'], () => ['alice'])
picker.targetName.value = 'admins'
picker.targetKind.value = 'user'
expect(picker.targetName.value).toBe('')
expect(picker.nameValid.value).toBe(false)
})
})