Files
ridebus-pwa/test/stopGroups.test.mjs
2026-10-07 01:48:32 +03:00

39 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { countLabel, directionLabel, groupStops } from '../src/lib/stopGroups.ts';
test('names are grouped like the landing while direction IDs remain independent', () => {
const groups = groupStops([
{ id: 1, name: ' Площадь Свободы ', direction: 'В центр', routesCount: 2 },
{ id: 2, name: 'площадь свободы', direction: 'Из центра', routesCount: 3 },
{ id: 1, name: 'Площадь Свободы', direction: 'Duplicate ID', routesCount: 2 },
{ id: 3, name: 'Автовокзал', direction: '', routesCount: 1 },
]);
assert.equal(groups.length, 2);
assert.equal(groups[0].name, 'Автовокзал');
assert.equal(groups[1].name, 'Площадь Свободы');
assert.deepEqual(groups[1].stops.map(stop => stop.id), [1, 2]);
});
test('direction labels distinguish unlabeled and repeated directions', () => {
const stops = [
{ id: 1, name: 'Вокзал', direction: 'В центр', routesCount: 2 },
{ id: 2, name: 'Вокзал', direction: 'В центр', routesCount: 2 },
{ id: 3, name: 'Вокзал', direction: '', routesCount: 2 },
];
const group = groupStops(stops)[0];
assert.equal(directionLabel(group, stops[0], 0), 'В центр · 1');
assert.equal(directionLabel(group, stops[1], 1), 'В центр · 2');
assert.equal(directionLabel(group, stops[2], 2), 'Направление 3');
});
test('the list retains more than eighty stops and uses correct count labels', () => {
const stops = Array.from({ length: 120 }, (_, index) => ({ id: index + 1, name: `Остановка ${index + 1}`, direction: '', routesCount: 1 }));
assert.equal(groupStops(stops).length, 120);
const forms = ['остановка', 'остановки', 'остановок'];
assert.equal(countLabel(1, forms), '1 остановка');
assert.equal(countLabel(2, forms), '2 остановки');
assert.equal(countLabel(11, forms), '11 остановок');
assert.equal(countLabel(21, forms), '21 остановка');
});