Skip to content

Commit c6e2fe5

Browse files
committed
front: fix stdcm consist length and mass minimum values
The sum of the rolling stock and towed rolling stock mass was previously rounded down (instead of up) resulting to some invalid values send to the form. If a total mass was 80.7t, the user was allowed to send 80t. Signed-off-by: SharglutDev <p.filimon75@gmail.com>
1 parent 833fe27 commit c6e2fe5

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

front/src/applications/stdcm/components/StdcmForm/StdcmConsist.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const StdcmConsist = ({ isDebugMode, consistErrors = {}, disabled = false }: Std
144144
status: 'error',
145145
tooltip: 'left',
146146
message: t(consistErrors.totalMass, {
147-
low: Math.floor(
147+
low: Math.ceil(
148148
kgToT((rollingStock?.mass ?? 0) + (towedRollingStock?.mass ?? 0))
149149
),
150150
high: CONSIST_TOTAL_MASS_MAX,
@@ -168,7 +168,7 @@ const StdcmConsist = ({ isDebugMode, consistErrors = {}, disabled = false }: Std
168168
status: 'error',
169169
tooltip: 'left',
170170
message: t(consistErrors.totalLength, {
171-
low: Math.floor((rollingStock?.length ?? 0) + (towedRollingStock?.length ?? 0)),
171+
low: Math.ceil((rollingStock?.length ?? 0) + (towedRollingStock?.length ?? 0)),
172172
high: CONSIST_TOTAL_LENGTH_MAX,
173173
}),
174174
}

front/src/applications/stdcm/hooks/useStdcmConsist.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const useStdcmConsist = () => {
5151
maxSpeedTag?: string | null
5252
) => {
5353
if (!totalMassChanged) {
54-
const consistMass = Math.floor(kgToT((rollingStock?.mass ?? 0) + (towed?.mass ?? 0)));
54+
const consistMass = Math.ceil(kgToT((rollingStock?.mass ?? 0) + (towed?.mass ?? 0)));
5555
dispatch(updateTotalMass(consistMass > 0 ? consistMass : undefined));
5656
}
5757

5858
if (!totalLengthChanged) {
59-
const consistLength = Math.floor((rollingStock?.length ?? 0) + (towed?.length ?? 0));
59+
const consistLength = Math.ceil((rollingStock?.length ?? 0) + (towed?.length ?? 0));
6060
dispatch(updateTotalLength(consistLength > 0 ? consistLength : undefined));
6161
}
6262

front/src/applications/stdcm/utils/consistValidation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const validateTotalMass = ({
2222
}
2323

2424
const tractionMassInTons = kgToT(tractionEngineMass);
25-
const consistMassInTons = Math.floor(kgToT(tractionEngineMass + towedMass));
25+
const consistMassInTons = Math.ceil(kgToT(tractionEngineMass + towedMass));
2626
const massLimit = towedMass ? consistMassInTons : tractionMassInTons;
2727

2828
if (totalMass < massLimit || totalMass > CONSIST_TOTAL_MASS_MAX) {
@@ -49,7 +49,7 @@ export const validateTotalLength = ({
4949
return 'consist.errors.totalLength.negative';
5050
}
5151

52-
const consistLength = Math.floor(tractionEngineLength + towedLength);
52+
const consistLength = Math.ceil(tractionEngineLength + towedLength);
5353

5454
if (totalLength < consistLength || totalLength > CONSIST_TOTAL_LENGTH_MAX) {
5555
return 'consist.errors.totalLength.range';

front/tests/006-stdcm.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test.describe('Verify train schedule elements and filters', () => {
3535
};
3636
const fastRollingStockPrefilledValues = {
3737
tonnage: '190',
38-
length: '45',
38+
length: '46',
3939
maxSpeed: '220',
4040
};
4141
const towedRollingStockPrefilledValues = {

0 commit comments

Comments
 (0)