mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
refactor(webui): extract repeated dashboard elements into shared components
Markup and helpers that were copied between pages now live in one place: - ChartCard, StatDisabledAlert, StatItem, DetailField, BudgetRatioBars, LabeledSelect, TargetPicker and LoadStateView components - lib/scope.ts, lib/columns.ts and lib/chart-palette.ts - messageOf, isAuthRejection, and the USD to micro-USD conversion helpers - one monthly cost projection, one date formatter, and the useCopyFeedback composable Behaviour is unchanged. Before and after screenshots of every page match at 390 and 1440 px. Empty-state text now comes from the shared EmptyState component, and the user run-out date uses the short date format. admin_assets_gen.go is regenerated. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { AdminApiError, adminFetch } from './api'
|
||||
import { AdminApiError, adminFetch, isAuthRejection, messageOf } from './api'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
function jsonResponse(status: number, body: unknown): Response {
|
||||
@@ -76,3 +76,28 @@ describe('adminFetch', () => {
|
||||
expect(auth.error).toBe('invalid key, or not an admin')
|
||||
})
|
||||
})
|
||||
|
||||
describe('messageOf', () => {
|
||||
it('returns an Error instance\'s own message', () => {
|
||||
expect(messageOf(new Error('boom'))).toBe('boom')
|
||||
})
|
||||
|
||||
it('stringifies a non-Error thrown value', () => {
|
||||
expect(messageOf('plain string')).toBe('plain string')
|
||||
expect(messageOf(404)).toBe('404')
|
||||
expect(messageOf(null)).toBe('null')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAuthRejection', () => {
|
||||
it('is true for an AdminApiError with status 401 or 403', () => {
|
||||
expect(isAuthRejection(new AdminApiError('nope', 401))).toBe(true)
|
||||
expect(isAuthRejection(new AdminApiError('nope', 403))).toBe(true)
|
||||
})
|
||||
|
||||
it('is false for any other AdminApiError status or a non-AdminApiError value', () => {
|
||||
expect(isAuthRejection(new AdminApiError('server error', 500))).toBe(false)
|
||||
expect(isAuthRejection(new Error('plain'))).toBe(false)
|
||||
expect(isAuthRejection('nope')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user