Skip to content

Commit

Permalink
#99 add unit test for gear telemetry
Browse files Browse the repository at this point in the history
Signed-off-by: JAGFx <[email protected]>
  • Loading branch information
JAGFx committed Feb 25, 2022
1 parent 7f53568 commit 6568b77
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/dashboards/scania/display/ScaniaDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="flex-area justify-content-start w-100 gearbox-wrapper">
<div class="truck-shifterType flex-area">
<span>{{
$trukShifterTypeLetter(
$truckShifterTypeLetter(
telemetry.truck.transmission,
telemetry.truck.brand
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/telemetry/_grear.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const $trukGear = (transmission, brand, withShifterType = true) => {
return strGear;
};

export const $trukShifterTypeLetter = (transmission, brand) => {
export const $truckShifterTypeLetter = (transmission, brand) => {
const gear = $gearInfo(transmission, brand).gear;
const crawlingGear = $gearInfo(transmission, brand).crawlingGear;
let shifterType = 'D';
Expand Down
34 changes: 34 additions & 0 deletions test/unit/src/utils/telemetry/gear.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { $gearInfo } from '@/utils/telemetry/_grear.utils';

describe('Telemetry gear utils', () => {
const generateTransmissionData = (gear) => {
return { gear: { displayed: gear } };
};

describe('$gearInfo', () => {
test.each(['Toto', 'Mercedes'])(
'The crawling gear should not exist for unsupported brand truck',
(brandName) => {
const gearDisplayed = 5;
const transmission = generateTransmissionData(gearDisplayed);
const result = $gearInfo(transmission, { name: brandName });

expect(result).toEqual({
gear: gearDisplayed,
crawlingGear: 0
});
}
);

test.each(['Volvo', 'Scania', 'Kenworth'])('tes', (brandName) => {
const gearDisplayed = 5;
const transmission = generateTransmissionData(gearDisplayed);
const result = $gearInfo(transmission, { name: brandName });

expect(result).toEqual({
gear: gearDisplayed,
crawlingGear: 2
});
});
});
});
12 changes: 9 additions & 3 deletions test/unit/test.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ export const changeTelemetryData = (obj, path, value) =>

export const deepChangeObjectValue = (obj, path, value) => {
let i;
const splitPath = path.split('.');

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

obj[path[i]] = value;
obj[splitPath[i]] = value;

return obj;
};
Expand Down

0 comments on commit 6568b77

Please sign in to comment.