Обновлены переводы на русский язык для компонентов, включая карточки мониторинга, сетевые панели и настройки. Исправлены описания и метки для улучшения пользовательского интерфейса, а также добавлены новые элементы для поддержки локализации в компонентах, таких как DataGrid и ResourcePage.
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
|
||
import {
|
||
isReadyCheckOk,
|
||
isSystemReady,
|
||
readinessBreakdown,
|
||
readyCheckStatusLabel,
|
||
} from '@/lib/metrics/readiness-breakdown'
|
||
|
||
describe('isSystemReady', () => {
|
||
it('accepts ready and ok', () => {
|
||
expect(isSystemReady('ready')).toBe(true)
|
||
expect(isSystemReady('ok')).toBe(true)
|
||
expect(isSystemReady('READY')).toBe(true)
|
||
})
|
||
|
||
it('rejects not_ready and empty', () => {
|
||
expect(isSystemReady('not_ready')).toBe(false)
|
||
expect(isSystemReady(undefined)).toBe(false)
|
||
expect(isSystemReady('')).toBe(false)
|
||
})
|
||
})
|
||
|
||
describe('isReadyCheckOk', () => {
|
||
it('parses backend string checks as ok', () => {
|
||
expect(isReadyCheckOk('ok')).toBe(true)
|
||
expect(isReadyCheckOk('memory')).toBe(true)
|
||
expect(isReadyCheckOk('unavailable')).toBe(false)
|
||
})
|
||
|
||
it('parses boolean and object forms', () => {
|
||
expect(isReadyCheckOk(true)).toBe(true)
|
||
expect(isReadyCheckOk(false)).toBe(false)
|
||
expect(isReadyCheckOk({ ok: true })).toBe(true)
|
||
expect(isReadyCheckOk({ ok: false, error: 'down' })).toBe(false)
|
||
})
|
||
})
|
||
|
||
describe('readyCheckStatusLabel', () => {
|
||
it('labels memory and failures', () => {
|
||
expect(readyCheckStatusLabel('memory', true)).toBe('В памяти')
|
||
expect(readyCheckStatusLabel('ok', true)).toBe('В норме')
|
||
expect(readyCheckStatusLabel('unavailable', false)).toBe('Недоступно')
|
||
})
|
||
})
|
||
|
||
describe('readinessBreakdown', () => {
|
||
it('counts healthy handleReady payload without false failures', () => {
|
||
const slices = readinessBreakdown(
|
||
{
|
||
status: 'ready',
|
||
checks: { store: 'ok', jobs: 'memory', postgres: 'ok' },
|
||
},
|
||
true,
|
||
)
|
||
expect(slices.find((s) => s.key === 'checks-fail')).toBeUndefined()
|
||
expect(slices.find((s) => s.key === 'checks-ok')?.count).toBe(3)
|
||
expect(slices.find((s) => s.key === 'health')?.count).toBe(1)
|
||
})
|
||
|
||
it('counts unavailable checks as failures', () => {
|
||
const slices = readinessBreakdown(
|
||
{
|
||
status: 'not_ready',
|
||
checks: { store: 'unavailable', jobs: 'memory' },
|
||
},
|
||
true,
|
||
)
|
||
expect(slices.find((s) => s.key === 'checks-fail')?.count).toBe(1)
|
||
expect(slices.find((s) => s.key === 'checks-ok')?.count).toBe(1)
|
||
})
|
||
|
||
it('returns API down slice when health fails', () => {
|
||
const slices = readinessBreakdown({ status: 'ready', checks: { store: 'ok' } }, false)
|
||
expect(slices).toHaveLength(1)
|
||
expect(slices[0]?.key).toBe('health-fail')
|
||
})
|
||
})
|