Follow-up to review on #3. The card and the detail page each built their own Measured/Derived split, kind label and provenance sentence — the drift buildBodyViewModel exists to prevent, re-forked one layer up, and the drift would have been in which side of the measured/derived line a quantity falls on, which is the distinction those panels exist to draw. One bodyReadouts(body) now returns both blocks and the sentence, and both templates iterate it. The two surfaces render identical rows as a result, and the card gains the inclination the detail page already showed. Also from that review: - KIND_LABELS was duplicated between the two panels; it now lives beside bodyReadouts. The third copy the review pointed at is a different union (search results are star/body/exoplanet, and label a body "Body"), so it stays where it is. - CardRow was HudReadout renamed. Both are now Readout, which HudReadout extends with its derived flag. - The enterable-systems count was a 21-line lazy memo over arrays that are already in hand; it is one expression where those arrays are assigned. - buildBodyViewModel now carries hostStarId, so the detail scene stops rescanning both catalogues for something the builder had already resolved. - heliocentricPeriodDays was called twice for the same body. - The superscript helper was a split/map/join; it is a replace. - info-panel had five computed() each wrapping one pure call with a non-null assertion, beside a template that inlined the same kind of call directly. They are gone with the shared readouts. - Dropped a tautological test that compared a pure function to itself. Replaced with one that asserts the host star id the builder now carries. - Removed the orphaned doc comment left behind when formatParsecs/formatAu moved out. And one the review raised as out of scope but is worth taking: formatRadiusKm grouped thousands above its decimal threshold and not below it, so 69,911 km sat beside a bare 6371 km. Both are grouped now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WaySiNst4HhDXBHnMy8p5G
87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
|
||
import { formatAu, formatDensity, formatLuminosity, formatMassEarth, formatParsecs, formatPeriod, formatRadiusKm, formatTemperature } from './quantity';
|
||
|
||
describe('formatParsecs', () => {
|
||
it('switches to kiloparsecs past a thousand parsecs', () => {
|
||
expect(formatParsecs(8180)).toBe('8.2 kpc');
|
||
});
|
||
|
||
it('keeps two decimals only while they carry information', () => {
|
||
expect(formatParsecs(1.3)).toBe('1.30 pc');
|
||
expect(formatParsecs(250)).toBe('250 pc');
|
||
});
|
||
});
|
||
|
||
describe('formatAu', () => {
|
||
it('holds four decimals for close-in orbits', () => {
|
||
// 0.0026 AU is a real published semi-major axis; two decimals would render it — and every
|
||
// other hot Jupiter — as a flat 0.00.
|
||
expect(formatAu(0.0026)).toBe('0.0026 AU');
|
||
});
|
||
|
||
it('drops to whole units past 100 AU', () => {
|
||
expect(formatAu(120)).toBe('120 AU');
|
||
expect(formatAu(5.53)).toBe('5.53 AU');
|
||
});
|
||
});
|
||
|
||
describe('formatPeriod', () => {
|
||
it('uses hours below a day', () => {
|
||
expect(formatPeriod(0.5)).toBe('12.0 h');
|
||
});
|
||
|
||
it('uses days through the short end and years beyond', () => {
|
||
expect(formatPeriod(88)).toBe('88.0 d');
|
||
expect(formatPeriod(365.25)).toBe('365.3 d');
|
||
expect(formatPeriod(4332.6)).toBe('11.9 yr');
|
||
});
|
||
|
||
it('drops the decimal for periods of centuries', () => {
|
||
expect(formatPeriod(90_560)).toBe('248 yr');
|
||
});
|
||
});
|
||
|
||
describe('formatRadiusKm', () => {
|
||
it('groups thousands on both sides of the decimal threshold', () => {
|
||
// Not just above it: 69,911 km beside a bare 6371 km reads as two different conventions.
|
||
expect(formatRadiusKm(69_911)).toBe('69,911 km');
|
||
expect(formatRadiusKm(6371)).toBe('6,371 km');
|
||
});
|
||
|
||
it('keeps a decimal only for small bodies', () => {
|
||
expect(formatRadiusKm(11.3)).toBe('11.3 km');
|
||
expect(formatRadiusKm(1737)).toBe('1,737 km');
|
||
});
|
||
});
|
||
|
||
describe('formatMassEarth', () => {
|
||
it('scales precision to magnitude', () => {
|
||
expect(formatMassEarth(0.815)).toBe('0.815 M⊕');
|
||
expect(formatMassEarth(17.15)).toBe('17.15 M⊕');
|
||
expect(formatMassEarth(317.8)).toBe('318 M⊕');
|
||
});
|
||
});
|
||
|
||
describe('formatTemperature and formatDensity', () => {
|
||
it('rounds temperature to a whole kelvin', () => {
|
||
expect(formatTemperature(254.6)).toBe('255 K');
|
||
});
|
||
|
||
it('holds two decimals of density', () => {
|
||
expect(formatDensity(5.514)).toBe('5.51 g/cm³');
|
||
});
|
||
});
|
||
|
||
describe('formatLuminosity', () => {
|
||
it('stays decimal across the ordinary range', () => {
|
||
expect(formatLuminosity(1)).toBe('1.00 L☉');
|
||
expect(formatLuminosity(0.0017)).toBe('0.002 L☉');
|
||
});
|
||
|
||
it('goes to powers of ten at the extremes', () => {
|
||
expect(formatLuminosity(126_000)).toBe('1.3×10⁵ L☉');
|
||
expect(formatLuminosity(0.00004)).toBe('4.0×10⁻⁵ L☉');
|
||
});
|
||
});
|