-
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.
- Loading branch information
Abby Wheelis
committed
Nov 9, 2023
1 parent
7ebcc94
commit 3943053
Showing
2 changed files
with
47 additions
and
2 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,45 @@ | ||
import { getMet, setUseCustomMET } from '../js/metrics/metHelper'; | ||
import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import fakeLabels from '../__mocks__/fakeLabels.json'; | ||
import { getConfig } from '../js/config/dynamicConfig'; | ||
import { initCustomDatasetHelper } from '../js/metrics/CustomMetricsHelper'; | ||
|
||
mockBEMUserCache(); | ||
mockLogger(); | ||
|
||
global.fetch = (url: string) => | ||
new Promise((rs, rj) => { | ||
setTimeout(() => | ||
rs({ | ||
text: () => | ||
new Promise((rs, rj) => { | ||
let myJSON = JSON.stringify(fakeLabels); | ||
setTimeout(() => rs(myJSON), 100); | ||
}), | ||
}), | ||
); | ||
}) as any; | ||
|
||
beforeEach(() => { | ||
setUseCustomMET(false); | ||
}); | ||
|
||
it('gets met for mode and speed', () => { | ||
expect(getMet('WALKING', 1.47523, 0)).toBe(4.3); | ||
expect(getMet('BICYCLING', 4.5, 0)).toBe(6.8); | ||
expect(getMet('UNICYCLE', 100, 0)).toBe(0); | ||
expect(getMet('CAR', 25, 1)).toBe(0); | ||
}); | ||
|
||
it('gets custom met for mode and speed', async () => { | ||
initCustomDatasetHelper(getConfig()); | ||
setUseCustomMET(true); | ||
await new Promise((r) => setTimeout(r, 500)); | ||
expect(getMet('walk', 1.47523, 0)).toBe(4.3); | ||
expect(getMet('bike', 4.5, 0)).toBe(6.8); | ||
expect(getMet('unicycle', 100, 0)).toBe(0); | ||
expect(getMet('drove_alone', 25, 1)).toBe(0); | ||
expect(getMet('e-bike', 6, 1)).toBe(4.9); | ||
expect(getMet('e-bike', 12, 1)).toBe(4.9); | ||
}); |
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