Files
edr-platform/apps/edr-freight-api/src/modules/trains/train-builder.reorder.spec.ts
2026-07-31 17:54:10 +00:00

45 lines
1.3 KiB
TypeScript
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 { orderSlotsByWagonSequence } from './train-builder.service';
describe('orderSlotsByWagonSequence', () => {
const slot = (sequenceNo: number, physicalWagonId: string | null) => ({
sequenceNo,
physicalWagonId,
});
it('reorders pinned slots to the wagons new positions, unpinned trail in old order', () => {
// Built train reordered to w3, w1, w2. Slots 1..5: three pinned + two empty.
const newSeq = new Map([
['w3', 1],
['w1', 2],
['w2', 3],
]);
const slots = [
slot(1, 'w1'),
slot(2, 'w2'),
slot(3, 'w3'),
slot(4, null),
slot(5, null),
];
expect(orderSlotsByWagonSequence(slots, newSeq).map((s) => s.physicalWagonId)).toEqual([
'w3',
'w1',
'w2',
null,
null,
]);
// Unpinned keep their old relative order (4 before 5).
expect(orderSlotsByWagonSequence(slots, newSeq).map((s) => s.sequenceNo)).toEqual([
3, 1, 2, 4, 5,
]);
});
it('slots pinned to wagons outside the reorder trail like unpinned ones', () => {
const newSeq = new Map([['w2', 1]]);
const slots = [slot(1, 'w-foreign'), slot(2, 'w2')];
expect(orderSlotsByWagonSequence(slots, newSeq).map((s) => s.physicalWagonId)).toEqual([
'w2',
'w-foreign',
]);
});
});