import { buildMaintenanceNotes, formatTrainRunLabel } from './train-builder.service'; describe('formatTrainRunLabel', () => { it('names the train by its export and import run numbers', () => { // What staff actually recognise — NOT the internal code (TRN-LEDGER-PW2). expect( formatTrainRunLabel({ exportTrainNumber: '9201', importTrainNumber: '9202', trainNumber: 'TRN-7', code: 'TRN-LEDGER-PW2', }), ).toBe('export 9201 / import 9202'); }); it('shows only the run number that is set', () => { expect( formatTrainRunLabel({ exportTrainNumber: '9201', code: 'TRN-LEDGER-PW2' }), ).toBe('export 9201'); expect( formatTrainRunLabel({ importTrainNumber: '9202', code: 'TRN-LEDGER-PW2' }), ).toBe('import 9202'); }); it('falls back to the train number, then the code, when no run is set', () => { expect(formatTrainRunLabel({ trainNumber: 'TRN-7', code: 'TRN-LEDGER-PW2' })).toBe( 'TRN-7', ); expect(formatTrainRunLabel({ code: 'TRN-LEDGER-PW2' })).toBe('TRN-LEDGER-PW2'); }); it('ignores blank run numbers rather than printing empty labels', () => { expect( formatTrainRunLabel({ exportTrainNumber: ' ', importTrainNumber: null, code: 'C-1' }), ).toBe('C-1'); }); it('never returns an empty label', () => { expect(formatTrainRunLabel({})).toBe('unknown'); }); }); describe('buildMaintenanceNotes', () => { it('records the operator reason together with the train it came off', () => { const notes = buildMaintenanceNotes('export 9201 / import 9202', 'Brake shoe worn through'); expect(notes.statusLogNote).toBe( 'Brake shoe worn through (detached from train export 9201 / import 9202)', ); expect(notes.movementNote).toBe( 'Sent to maintenance from train export 9201 / import 9202: Brake shoe worn through', ); }); it('still records the train number when no reason is given', () => { // The reason is optional, but which train a wagon left is never optional — // the history has to answer that on its own. const notes = buildMaintenanceNotes('export 9201 / import 9202'); expect(notes.statusLogNote).toBe('Detached from train export 9201 / import 9202'); expect(notes.movementNote).toBe('Sent to maintenance from train export 9201 / import 9202'); }); it('treats a whitespace-only reason as no reason', () => { const notes = buildMaintenanceNotes('export 9201 / import 9202', ' '); expect(notes.statusLogNote).toBe('Detached from train export 9201 / import 9202'); expect(notes.movementNote).toBe('Sent to maintenance from train export 9201 / import 9202'); }); it('trims padding around a real reason', () => { const notes = buildMaintenanceNotes('export 9201 / import 9202', ' Coupler damage '); expect(notes.statusLogNote).toBe('Coupler damage (detached from train export 9201 / import 9202)'); expect(notes.movementNote).toBe('Sent to maintenance from train export 9201 / import 9202: Coupler damage'); }); it('handles a null reason from an older client', () => { expect(buildMaintenanceNotes('export 9201 / import 9202', null).statusLogNote).toBe( 'Detached from train export 9201 / import 9202', ); }); });