Files
peardata/test/chart-types.test.js
T
Raven Scott 6d384534f2
CI / test (push) Successful in 58s
Release rolling / release (push) Successful in 7m11s
updates
2026-07-18 22:15:43 -04:00

55 lines
1.5 KiB
JavaScript

import test from 'brittle'
import {
allowedModesFor,
defaultModeFromMeta,
nextChartMode,
normalizeChartMode,
isCompositionChart,
} from '../shared/chart-types.js'
import { padLeftFor } from '../ui/charts.js'
test('normalizeChartMode aliases', (t) => {
t.is(normalizeChartMode('STACK'), 'stacked')
t.is(normalizeChartMode('multi-bar'), 'multibar')
t.is(normalizeChartMode('nope'), 'line')
})
test('defaultModeFromMeta respects catalog', (t) => {
t.is(defaultModeFromMeta({ chartType: 'area' }), 'area')
t.is(defaultModeFromMeta({ chart_type: 'stacked' }), 'stacked')
t.is(defaultModeFromMeta({}), 'line')
})
test('composition charts get pie in allowed modes', (t) => {
const meta = {
id: 'system.cpu',
chartType: 'stacked',
units: 'percentage',
dimensions: ['user', 'system', 'idle'],
}
t.ok(isCompositionChart(meta))
const allowed = allowedModesFor(meta)
t.ok(allowed.includes('pie'))
t.ok(allowed.includes('stacked'))
t.is(allowed[0], 'stacked')
})
test('line charts cycle through sensible modes', (t) => {
const meta = { chartType: 'line', dimensions: ['a', 'b'] }
let mode = 'line'
const seen = new Set()
for (let i = 0; i < 8; i++) {
mode = nextChartMode(mode, meta)
seen.add(mode)
}
t.ok(seen.has('area'))
t.ok(seen.has('bar'))
t.absent(seen.has('pie'))
})
test('padLeftFor matches Y-axis layout', (t) => {
t.is(padLeftFor('', true), 46)
t.is(padLeftFor('kilobytes', true), 52)
t.is(padLeftFor('percentage', false), 0)
})