fix issue

This commit is contained in:
Marshal
2026-07-31 17:54:10 +00:00
parent b74b51dcc1
commit 6a4067ec42
6 changed files with 160 additions and 34 deletions

View File

@@ -0,0 +1,44 @@
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',
]);
});
});