-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve merge conflicts by merging upstream
- Loading branch information
Showing
10 changed files
with
163 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { convertDistance, convertSpeed, formatForDisplay } from '../js/config/useImperialConfig'; | ||
|
||
|
||
// This mock is required, or else the test will dive into the import chain of useAppConfig.ts and fail when it gets to the root | ||
jest.mock('../js/useAppConfig', () => { | ||
return jest.fn(() => ({ | ||
appConfig: { | ||
use_imperial: false | ||
}, | ||
loading: false | ||
})); | ||
}); | ||
|
||
describe('formatForDisplay', () => { | ||
it('should round to the nearest integer when value is >= 100', () => { | ||
expect(formatForDisplay(105)).toBe('105'); | ||
expect(formatForDisplay(119.01)).toBe('119'); | ||
expect(formatForDisplay(119.91)).toBe('120'); | ||
}); | ||
|
||
it('should round to 3 significant digits when 1 <= value < 100', () => { | ||
expect(formatForDisplay(7.02)).toBe('7.02'); | ||
expect(formatForDisplay(9.6262)).toBe('9.63'); | ||
expect(formatForDisplay(11.333)).toBe('11.3'); | ||
expect(formatForDisplay(99.99)).toBe('100'); | ||
}); | ||
|
||
it('should round to 2 decimal places when value < 1', () => { | ||
expect(formatForDisplay(0.07178)).toBe('0.07'); | ||
expect(formatForDisplay(0.08978)).toBe('0.09'); | ||
expect(formatForDisplay(0.75)).toBe('0.75'); | ||
expect(formatForDisplay(0.001)).toBe('0'); | ||
expect(formatForDisplay(0.006)).toBe('0.01'); | ||
expect(formatForDisplay(0.00001)).toBe('0'); | ||
}); | ||
}); | ||
|
||
describe('convertDistance', () => { | ||
it('should convert meters to kilometers by default', () => { | ||
expect(convertDistance(1000, false)).toBe(1); | ||
}); | ||
|
||
it('should convert meters to miles when imperial flag is true', () => { | ||
expect(convertDistance(1609.34, true)).toBeCloseTo(1); // Approximately 1 mile | ||
}); | ||
}); | ||
|
||
describe('convertSpeed', () => { | ||
it('should convert meters per second to kilometers per hour by default', () => { | ||
expect(convertSpeed(10, false)).toBe(36); | ||
}); | ||
|
||
it('should convert meters per second to miles per hour when imperial flag is true', () => { | ||
expect(convertSpeed(6.7056, true)).toBeCloseTo(15); // Approximately 15 mph | ||
}); | ||
}); |
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* The general structure of this code is that all the timeline information for | ||
* a particular day is retrieved from the Timeline factory and put into the scope. | ||
* For best performance, all data should be loaded into the in-memory timeline, | ||
* and in addition to writing to storage, the data should be written to memory. | ||
* All UI elements should only use $scope variables. | ||
*/ | ||
|
||
import i18next from "i18next"; | ||
import { getAngularService } from "../../angular-react-helper"; | ||
|
||
const unlabeledCheck = (t) => { | ||
try { | ||
const EnketoTripButtonService = getAngularService("EnketoTripButtonService"); | ||
const etbsSingleKey = EnketoTripButtonService.SINGLE_KEY; | ||
return typeof t.userInput[etbsSingleKey] === 'undefined'; | ||
} | ||
catch (e) { | ||
console.log("Error in retrieving EnketoTripButtonService: ", e); | ||
} | ||
} | ||
|
||
const UNLABELED = { | ||
key: "unlabeled", | ||
text: i18next.t("diary.unlabeled"), | ||
filter: unlabeledCheck | ||
} | ||
|
||
const TO_LABEL = { | ||
key: "to_label", | ||
text: i18next.t("diary.to-label"), | ||
filter: unlabeledCheck | ||
} | ||
|
||
export const configuredFilters = [ | ||
TO_LABEL, | ||
UNLABELED | ||
]; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* The general structure of this code is that all the timeline information for | ||
* a particular day is retrieved from the Timeline factory and put into the scope. | ||
* For best performance, all data should be loaded into the in-memory timeline, | ||
* and in addition to writing to storage, the data should be written to memory. | ||
* All UI elements should only use $scope variables. | ||
*/ | ||
|
||
import i18next from "i18next"; | ||
|
||
const unlabeledCheck = (t) => { | ||
return t.INPUTS | ||
.map((inputType, index) => !t.userInput[inputType]) | ||
.reduce((acc, val) => acc || val, false); | ||
} | ||
|
||
const invalidCheck = (t) => { | ||
const retVal = | ||
(t.userInput['MODE'] && t.userInput['MODE'].value === 'pilot_ebike') && | ||
(!t.userInput['REPLACED_MODE'] || | ||
t.userInput['REPLACED_MODE'].value === 'pilot_ebike' || | ||
t.userInput['REPLACED_MODE'].value === 'same_mode'); | ||
return retVal; | ||
} | ||
|
||
const toLabelCheck = (trip) => { | ||
if (trip.expectation) { | ||
console.log(trip.expectation.to_label) | ||
return trip.expectation.to_label && unlabeledCheck(trip); | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
const UNLABELED = { | ||
key: "unlabeled", | ||
text: i18next.t("diary.unlabeled"), | ||
filter: unlabeledCheck, | ||
width: "col-50" | ||
} | ||
|
||
const INVALID_EBIKE = { | ||
key: "invalid_ebike", | ||
text: i18next.t("diary.invalid-ebike"), | ||
filter: invalidCheck | ||
} | ||
|
||
const TO_LABEL = { | ||
key: "to_label", | ||
text: i18next.t("diary.to-label"), | ||
filter: toLabelCheck, | ||
width: "col-50" | ||
} | ||
|
||
export const configuredFilters = [ | ||
TO_LABEL, | ||
UNLABELED | ||
]; |
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