mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 03:38:17 +00:00
fix issue
This commit is contained in:
@@ -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',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user