new demo mode & tenure
Some checks failed
Build and publish Docker image / build-and-push (push) Successful in 8m43s
CI / Check (push) Failing after 8m49s

This commit is contained in:
Andras Schmelczer 2026-06-17 07:54:30 +01:00
parent 7656f24544
commit 4a0f00f2a4
64 changed files with 2875 additions and 338 deletions

View file

@ -0,0 +1,58 @@
import { describe, expect, it } from 'vitest';
import { buildTimelineEvents } from './PropertiesPane';
import type { Property } from '../../types';
function makeProperty(overrides: Partial<Property>): Property {
return { lat: 51, lon: -0.1, ...overrides } as Property;
}
// Compact, discriminated summary of each event so assertions stay type-safe.
function summarize(property: Property): string[] {
return buildTimelineEvents(property).map((event) => {
switch (event.kind) {
case 'tenure':
return `tenure:${event.status}:${event.year}`;
case 'sale':
return `sale:${event.year}`;
case 'reno':
return `reno:${event.event}:${event.year}`;
case 'built':
return `built:${event.year}`;
}
});
}
describe('buildTimelineEvents', () => {
it('renders tenure changes newest-first with their status', () => {
expect(
summarize(
makeProperty({
tenure_history: [
{ year: 2019, status: 'Rented (private)' },
{ year: 2023, status: 'Owner-occupied' },
],
}),
),
).toEqual(['tenure:Owner-occupied:2023', 'tenure:Rented (private):2019']);
});
it('interleaves tenure changes with sales by year', () => {
expect(
summarize(
makeProperty({
historical_prices: [
{ year: 2015, month: 6, price: 200_000 },
// Most recent sale is the card headline, so it is dropped here.
{ year: 2024, month: 1, price: 300_000 },
],
tenure_history: [{ year: 2020, status: 'Rented (private)' }],
}),
),
).toEqual(['tenure:Rented (private):2020', 'sale:2015']);
});
it('emits nothing when there is no tenure history', () => {
expect(summarize(makeProperty({}))).toEqual([]);
});
});