Improve metrics clarity, exploration, and refresh reliability
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { compareMetricValues, metricDuration, metricNumber, metricPercent } from '../../src/lib/ui/metrics.js';
|
||||
|
||||
describe('metric presentation', () => {
|
||||
it('distinguishes unavailable evidence, zero, and tiny nonzero values', () => {
|
||||
expect(metricPercent(0, 0)).toBe('—');
|
||||
expect(metricPercent(0, 1)).toBe('0.0%');
|
||||
expect(metricPercent(0.0001, 1)).toBe('<0.1%');
|
||||
expect(metricDuration(0)).toBe('0 h');
|
||||
expect(metricDuration(0.1 / 3600)).toBe('<1 s');
|
||||
expect(metricDuration(45 / 3600)).toBe('45 s');
|
||||
expect(metricDuration(90 / 3600)).toBe('1.5 min');
|
||||
expect(metricNumber(0.0125)).toBe('<0.1');
|
||||
});
|
||||
|
||||
it('sorts numerically while putting unavailable observations last in both directions', () => {
|
||||
const values = [2, null, 100, 0, 10];
|
||||
expect([...values].sort((a, b) => compareMetricValues(a, b, 'desc'))).toEqual([100, 10, 2, 0, null]);
|
||||
expect([...values].sort((a, b) => compareMetricValues(a, b, 'asc'))).toEqual([0, 2, 10, 100, null]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user