Files
traefik-llmgateway/webui/src/lib/load-state.spec.ts
T
lukaszraczylo 758d7c7020 feat(admin-ui): alias labels, active-provider legends, denser tables and readable money
Label configured model aliases with an alias badge wherever a model id shows.
List only providers with traffic in the window in provider chart legends.
Page long tables, show a scroll shadow on wide ones and drop the duplicate model link.
Show costs with thousands separators and magnitude-scaled decimals on cards and chart axes.
Use whole-number ticks for count charts and replace all-zero charts with a message.
Back off polling after failures.
Keep the CSV status region from widening the page on phones.
Regenerate admin_assets_gen.go.
2026-11-08 02:22:22 +00:00

50 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { emptyWhenAllZero, loadState } from './load-state'
describe('loadState', () => {
it('is "ready" when there is data, no error, not loading', () => {
expect(loadState({ loading: false, hasData: true, error: '' })).toBe('ready')
})
it('is "ready" when there is data even if loading is true (a background refresh in flight)', () => {
expect(loadState({ loading: true, hasData: true, error: '' })).toBe('ready')
})
// states-plan.md item 1: a background refresh failure must never blank
// already-rendered data into an error state — that surfaces via a
// toast instead (stores/toasts.ts), not by switching away from 'ready'.
it('is "ready" when there is data even if a background refresh just failed (error set)', () => {
expect(loadState({ loading: false, hasData: true, error: 'usage: fetch failed' })).toBe('ready')
})
it('is "error" when there is no data and an error is set', () => {
expect(loadState({ loading: false, hasData: false, error: 'overview: fetch failed' })).toBe('error')
})
it('is "error" even while loading, when there is no data and an error is set (a retry already in flight)', () => {
expect(loadState({ loading: true, hasData: false, error: 'overview: fetch failed' })).toBe('error')
})
it('is "skeleton" when there is no data, no error, and loading is true', () => {
expect(loadState({ loading: true, hasData: false, error: '' })).toBe('skeleton')
})
it('is "empty" when there is no data, no error, and not loading', () => {
expect(loadState({ loading: false, hasData: false, error: '' })).toBe('empty')
})
})
describe('emptyWhenAllZero', () => {
const zero = [{ data: [0, 0, null] }]
it.each([
{ name: 'ready + all zero', state: 'ready', series: zero, want: 'empty' },
{ name: 'ready + no series', state: 'ready', series: [], want: 'empty' },
{ name: 'ready + traffic', state: 'ready', series: [{ data: [0, 2] }], want: 'ready' },
{ name: 'skeleton passes through', state: 'skeleton', series: zero, want: 'skeleton' },
{ name: 'error passes through', state: 'error', series: zero, want: 'error' },
] as const)('$name', ({ state, series, want }) => {
expect(emptyWhenAllZero(state, series)).toBe(want)
})
})