mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 08:20:58 +00:00
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
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',
|
||
]);
|
||
});
|
||
});
|