Skip to content

Commit 6568b77

Browse files
committed
#99 add unit test for gear telemetry
Signed-off-by: JAGFx <contact@jagfx.fr>
1 parent 7f53568 commit 6568b77

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

src/components/dashboards/scania/display/ScaniaDisplay.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="flex-area justify-content-start w-100 gearbox-wrapper">
66
<div class="truck-shifterType flex-area">
77
<span>{{
8-
$trukShifterTypeLetter(
8+
$truckShifterTypeLetter(
99
telemetry.truck.transmission,
1010
telemetry.truck.brand
1111
)

src/utils/telemetry/_grear.utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const $trukGear = (transmission, brand, withShifterType = true) => {
4848
return strGear;
4949
};
5050

51-
export const $trukShifterTypeLetter = (transmission, brand) => {
51+
export const $truckShifterTypeLetter = (transmission, brand) => {
5252
const gear = $gearInfo(transmission, brand).gear;
5353
const crawlingGear = $gearInfo(transmission, brand).crawlingGear;
5454
let shifterType = 'D';
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { $gearInfo } from '@/utils/telemetry/_grear.utils';
2+
3+
describe('Telemetry gear utils', () => {
4+
const generateTransmissionData = (gear) => {
5+
return { gear: { displayed: gear } };
6+
};
7+
8+
describe('$gearInfo', () => {
9+
test.each(['Toto', 'Mercedes'])(
10+
'The crawling gear should not exist for unsupported brand truck',
11+
(brandName) => {
12+
const gearDisplayed = 5;
13+
const transmission = generateTransmissionData(gearDisplayed);
14+
const result = $gearInfo(transmission, { name: brandName });
15+
16+
expect(result).toEqual({
17+
gear: gearDisplayed,
18+
crawlingGear: 0
19+
});
20+
}
21+
);
22+
23+
test.each(['Volvo', 'Scania', 'Kenworth'])('tes', (brandName) => {
24+
const gearDisplayed = 5;
25+
const transmission = generateTransmissionData(gearDisplayed);
26+
const result = $gearInfo(transmission, { name: brandName });
27+
28+
expect(result).toEqual({
29+
gear: gearDisplayed,
30+
crawlingGear: 2
31+
});
32+
});
33+
});
34+
});

test/unit/test.helper.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ export const changeTelemetryData = (obj, path, value) =>
33

44
export const deepChangeObjectValue = (obj, path, value) => {
55
let i;
6+
const splitPath = path.split('.');
67

7-
path = path.split('.');
8-
for (i = 0; i < path.length - 1; i++) obj = obj[path[i]];
8+
for (i = 0; i < splitPath.length - 1; i++) {
9+
if (!Object.hasOwnProperty.call(obj, splitPath[i]))
10+
throw new Error(
11+
`The path "${path}" was not found on the original object`
12+
);
13+
obj = obj[splitPath[i]];
14+
}
915

10-
obj[path[i]] = value;
16+
obj[splitPath[i]] = value;
1117

1218
return obj;
1319
};

0 commit comments

Comments
 (0)