-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: add unit tests for stdcm simulation report sheet
- Loading branch information
Showing
8 changed files
with
397 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
562 changes: 284 additions & 278 deletions
562
front/src/applications/stdcm/components/SimulationReportSheetV2.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
front/src/applications/stdcm/utils/__tests__/sampleData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const simulationReportTest = { | ||
pathProperties: { | ||
suggestedOperationalPoints: [ | ||
{ | ||
opId: 'op1', | ||
name: 'Point 1', | ||
ch: 'Ch1', | ||
stopFor: 'Stop1', | ||
metadata: { trackName: 'Track 1' }, | ||
positionOnPath: 100, | ||
offsetOnTrack: 0, | ||
track: 'Track 1', | ||
coordinates: { lat: 0, lon: 0 }, | ||
}, | ||
], | ||
}, | ||
stdcmData: { | ||
status: 'success', | ||
simulation: { | ||
status: 'success', | ||
base: { | ||
positions: [50, 100, 150], | ||
energy_consumption: 10200307394.39714, | ||
scheduled_points_honored: true, | ||
speeds: [10, 20, 30], | ||
times: [0, 60000, 120000], | ||
}, | ||
final_output: { | ||
positions: [50, 100, 150], | ||
energy_consumption: 10200307394.39714, | ||
scheduled_points_honored: true, | ||
speeds: [10, 20, 30], | ||
times: [0, 60000, 120000], | ||
routing_requirements: [], | ||
signal_sightings: [], | ||
spacing_requirements: [], | ||
zone_updates: [], | ||
}, | ||
}, | ||
departure_time: '2024-07-08T10:00:00Z', | ||
}, | ||
simulationReportSheetNumber: '0724-123-456', | ||
}; | ||
|
||
export default simulationReportTest; |
59 changes: 59 additions & 0 deletions
59
front/src/applications/stdcm/utils/__tests__/simulationSheet.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { SimulationReportSheetProps } from 'applications/stdcm/types'; | ||
import { | ||
generateCodeNumber, | ||
formatCreationDate, | ||
getStopDurationTime, | ||
extractSpeedLimit, | ||
getOperationalPointsWithTimes, | ||
} from 'applications/stdcm/utils/simulationReportSheet'; | ||
|
||
import simulationReportTest from './sampleData'; | ||
|
||
describe('Utils simulation report sheet functions', () => { | ||
test('should return a formatted string', () => { | ||
const codeNumber = generateCodeNumber(); | ||
expect(codeNumber).toMatch(/^\d{2}\d{2}-\d{3}-\d{3}$/); | ||
}); | ||
|
||
test('should format the date correctly', () => { | ||
const date = '2024-07-08T10:20:30Z'; | ||
const formattedDate = formatCreationDate(date); | ||
expect(formattedDate).toEqual({ | ||
day: '08', | ||
month: '07', | ||
year: 2024, | ||
hours: 12, | ||
minutes: 20, | ||
}); | ||
}); | ||
|
||
test('should return correct time format', () => { | ||
expect(getStopDurationTime(30)).toBe('30 sec'); | ||
expect(getStopDurationTime(90)).toBe('1 min'); | ||
}); | ||
|
||
test('should extract the speed limit correctly', () => { | ||
const speedLimitByTag = 'Some tag - 50'; | ||
expect(extractSpeedLimit(speedLimitByTag)).toBe('50'); | ||
}); | ||
|
||
test('should return formatted operational points with times', () => { | ||
const result = getOperationalPointsWithTimes( | ||
simulationReportTest as unknown as SimulationReportSheetProps | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
opId: 'op1', | ||
positionOnPath: 100, | ||
time: '12:01', | ||
name: 'Point 1', | ||
ch: 'Ch1', | ||
stop: 'Stop1', | ||
duration: 0, | ||
departureTime: '12:00', | ||
stopEndTime: '12:01', | ||
trackName: 'Track 1', | ||
}, | ||
]); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
front/src/applications/stdcm/utils.ts → ...ions/stdcm/utils/simulationReportSheet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters