- Introduced ServiceWindow component to display the last departure today and the first tomorrow. - Implemented cancellation notice parsing to handle route cancellations effectively. - Enhanced departure display logic to include cancellation alerts and status updates. - Created information blocks for displaying service information, weather, and QR codes. - Added tests for departure features, information handling, and service window functionality. - Updated fixtures for testing various scenarios including cancellations and long wait times.
43 lines
2.9 KiB
JavaScript
43 lines
2.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { boardScenes, informationBlocks, serviceWindow } from '../src/lib/information.ts';
|
|
import { defaultSettings } from '../src/lib/storage.ts';
|
|
|
|
const off = { ...defaultSettings, infoServiceEnabled: false, infoWeatherEnabled: false, infoQrEnabled: false };
|
|
const trip = (routeId, at) => ({ routeId, routeNumber: String(routeId), scheduledAt: at });
|
|
|
|
test('disabled information blocks are omitted without leaving gaps in the cycle', () => {
|
|
assert.deepEqual(informationBlocks(defaultSettings).map(block => block.id), ['service', 'weather', 'qr']);
|
|
assert.deepEqual(informationBlocks({ ...off, infoQrEnabled: true }).map(block => block.id), ['qr']);
|
|
assert.deepEqual(informationBlocks({ ...defaultSettings, infoWeatherEnabled: false }).map(block => block.id), ['service', 'qr']);
|
|
assert.deepEqual(informationBlocks(off), []);
|
|
});
|
|
test('all blocks off keeps departures, retains optional advertising, and still surfaces alerts', () => {
|
|
assert.deepEqual(boardScenes(off, false, false), ['departures']);
|
|
assert.deepEqual(boardScenes({ ...off, adsEnabled: true }, false, false), ['departures', 'ad']);
|
|
assert.deepEqual(boardScenes({ ...off, adsEnabled: true }, true, true), ['departures', 'info']);
|
|
assert.deepEqual(boardScenes(off, true, false), ['departures', 'info']);
|
|
});
|
|
test('service boundaries use local arrival dates, including after-midnight trips', () => {
|
|
const now = Date.parse('2026-10-09T23:00:00+03:00');
|
|
const last = trip(2, '2026-10-09T23:50:00+03:00');
|
|
const first = trip(1, '2026-10-09T21:15:00Z'); // 00:15 tomorrow in Minsk
|
|
const departures = [trip(1, '2026-10-10T06:00:00+03:00'), last, first,
|
|
trip(1, '2026-10-09T00:10:00+03:00'), trip(1, '2026-10-08T23:59:00+03:00')];
|
|
assert.deepEqual(serviceWindow(departures, now, ''), { lastToday: last, firstTomorrow: first });
|
|
});
|
|
test('route selection scopes both boundaries; empty days do not invent a trip', () => {
|
|
const now = Date.parse('2026-10-09T12:00:00+03:00');
|
|
const filtered = trip(1, '2026-10-09T20:00:00+03:00');
|
|
const departures = [filtered, trip(2, '2026-10-09T23:00:00+03:00'), trip(2, '2026-10-10T05:00:00+03:00')];
|
|
assert.deepEqual(serviceWindow(departures, now, '1'), { lastToday: filtered, firstTomorrow: null });
|
|
assert.deepEqual(serviceWindow([], now, ''), { lastToday: null, firstTomorrow: null });
|
|
});
|
|
test('service boundaries roll to the new day and across the year at local midnight', () => {
|
|
const last = trip(1, '2026-12-31T23:59:00+03:00');
|
|
const first = trip(1, '2027-01-01T05:00:00+03:00');
|
|
const next = trip(1, '2027-01-02T06:00:00+03:00');
|
|
assert.deepEqual(serviceWindow([last, first, next], Date.parse('2026-12-31T23:59:00+03:00'), ''), { lastToday: last, firstTomorrow: first });
|
|
assert.deepEqual(serviceWindow([last, first, next], Date.parse('2027-01-01T00:00:00+03:00'), ''), { lastToday: first, firstTomorrow: next });
|
|
});
|