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) })