49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
||
import { test } from 'node:test';
|
||
import {
|
||
groupStops,
|
||
formatRemainingMinutes,
|
||
} from '../modules/home/departuresCard/stopGroups.ts';
|
||
|
||
test('groups duplicate stop names without losing either direction or repeating IDs', () => {
|
||
const groups = groupStops([
|
||
{ id: 95, name: '11 Июля', direction: 'на Лозовку', routesCount: 4 },
|
||
{ id: 45, name: ' 11 июля ', direction: 'на Шмидта', routesCount: 3 },
|
||
{ id: 45, name: '11 Июля', direction: 'на Шмидта', routesCount: 3 },
|
||
{
|
||
id: 88,
|
||
name: '23-х Гвардейцев',
|
||
direction: 'на Селянскую',
|
||
routesCount: 6,
|
||
},
|
||
]);
|
||
assert.equal(groups.length, 2);
|
||
assert.equal(groups[0].name, '11 Июля');
|
||
assert.deepEqual(
|
||
groups[0].stops.map((stop) => [stop.id, stop.direction]),
|
||
[
|
||
[95, 'на Лозовку'],
|
||
[45, 'на Шмидта'],
|
||
]
|
||
);
|
||
assert.deepEqual(groupStops([]), []);
|
||
});
|
||
|
||
test('formats countdowns around the hour boundary in both locales', () => {
|
||
const ru = { now: 'Сейчас', hours: 'ч', minutes: 'мин' };
|
||
const en = { now: 'Now', hours: 'h', minutes: 'min' };
|
||
for (const [value, expected] of [
|
||
[-1, 'Сейчас'],
|
||
[0, 'Сейчас'],
|
||
[1, '1 мин'],
|
||
[59, '59 мин'],
|
||
[60, '1 ч'],
|
||
[83, '1 ч 23 мин'],
|
||
[120, '2 ч'],
|
||
[1439, '23 ч 59 мин'],
|
||
]) {
|
||
assert.equal(formatRemainingMinutes(value, ru), expected);
|
||
}
|
||
assert.equal(formatRemainingMinutes(83, en), '1 h 23 min');
|
||
});
|