Stian Aune
5 years ago
14 changed files with 303 additions and 67 deletions
-
29my-bois/package-lock.json
-
1my-bois/package.json
-
37my-bois/src/components/Bois.jsx
-
45my-bois/src/components/Contexts.jsx
-
2my-bois/src/components/Misc.css
-
9my-bois/src/components/Misc.jsx
-
8my-bois/src/components/Score.css
-
19my-bois/src/components/Score.jsx
-
27my-bois/src/helpers/color.test.js
-
49my-bois/src/helpers/diff.js
-
89my-bois/src/helpers/diff.test.js
-
8my-bois/src/hooks/milestones.js
-
14my-bois/src/hooks/net.js
-
23my-bois/src/hooks/options.js
@ -0,0 +1,27 @@ |
|||||
|
import {COLOR_BAD, COLOR_GOOD, COLOR_VERY_BAD, COLOR_VERY_GOOD, colorByDiff} from "./color"; |
||||
|
|
||||
|
describe("colorByDiff", function () { |
||||
|
it("should show dark red for worse bad", () => { |
||||
|
expect(colorByDiff(-5, -2)).toBe(COLOR_VERY_BAD); |
||||
|
}); |
||||
|
|
||||
|
it("should show bright red for equal bad", () => { |
||||
|
expect(colorByDiff(-11, -11)).toBe(COLOR_BAD); |
||||
|
}); |
||||
|
|
||||
|
it("should show bright red for better bad", () => { |
||||
|
expect(colorByDiff(-1, -7)).toBe(COLOR_BAD); |
||||
|
}); |
||||
|
|
||||
|
it("should show dark green for better good", () => { |
||||
|
expect(colorByDiff(33, 25)).toBe(COLOR_VERY_GOOD); |
||||
|
}); |
||||
|
|
||||
|
it("should show bright green for equal good", () => { |
||||
|
expect(colorByDiff(10, 10)).toBe(COLOR_GOOD); |
||||
|
}); |
||||
|
|
||||
|
it("should show bright green for worse good", () => { |
||||
|
expect(colorByDiff(5, 7)).toBe(COLOR_GOOD); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,89 @@ |
|||||
|
import calculateDiff, {diffString} from "./diff"; |
||||
|
|
||||
|
const programWithoutWarmup = { |
||||
|
warmupMin: 0, |
||||
|
warmupCpm: 0, |
||||
|
cpm: 30, |
||||
|
cooldownCpm: 20, |
||||
|
}; |
||||
|
|
||||
|
const programWithWarmup = { |
||||
|
warmupMin: 10, |
||||
|
warmupCpm: 25, |
||||
|
cpm: 30, |
||||
|
cooldownCpm: 20, |
||||
|
}; |
||||
|
|
||||
|
describe('diffString', () => { |
||||
|
it("should show a plus before zero", () => { |
||||
|
expect(diffString(0)).toBe("+0"); |
||||
|
}); |
||||
|
|
||||
|
it("should show a plus before a positive number", () => { |
||||
|
expect(diffString(44)).toBe("+44"); |
||||
|
}); |
||||
|
|
||||
|
it("should show a minus when negatives", () => { |
||||
|
expect(diffString(-12)).toBe("-12"); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe("calculateDiff", () => { |
||||
|
it("should return zero at start", () => { |
||||
|
const diff = calculateDiff({ |
||||
|
program: programWithoutWarmup, |
||||
|
minutes: 0, |
||||
|
seconds: 0, |
||||
|
calories: 0, |
||||
|
}); |
||||
|
|
||||
|
expect(diff).toBe(0); |
||||
|
}); |
||||
|
|
||||
|
it("should expect 300 calories after 0' / 10'", () => { |
||||
|
const diff = calculateDiff({ |
||||
|
program: programWithoutWarmup, |
||||
|
minutes: 10, |
||||
|
seconds: 0, |
||||
|
calories: 305, |
||||
|
}); |
||||
|
|
||||
|
expect(diff).toBe(5); |
||||
|
}); |
||||
|
|
||||
|
it("should expect 865 calories after 10' / 20'50", () => { |
||||
|
const diff = calculateDiff({ |
||||
|
program: programWithWarmup, |
||||
|
minutes: 30, |
||||
|
seconds: 50, |
||||
|
calories: 250 + 600 + 25 - 17, |
||||
|
}); |
||||
|
|
||||
|
// Aim: 875
|
||||
|
expect(diff).toBe(-17); |
||||
|
}); |
||||
|
|
||||
|
it("should expect 755 calories after 10' / 15' / 7'45", () => { |
||||
|
const diff = calculateDiff({ |
||||
|
program: programWithWarmup, |
||||
|
cooldownMin: 25, |
||||
|
minutes: 32, |
||||
|
seconds: 45, |
||||
|
calories: 250 + 450 + 140 + 15, |
||||
|
}); |
||||
|
|
||||
|
expect(diff).toBe(0); |
||||
|
}); |
||||
|
|
||||
|
it("should expect 325 calories after 5' (half) / 0' / 10'", () => { |
||||
|
const diff = calculateDiff({ |
||||
|
program: programWithWarmup, |
||||
|
cooldownMin: 5, |
||||
|
minutes: 15, |
||||
|
seconds: 0, |
||||
|
calories: 325 |
||||
|
}); |
||||
|
|
||||
|
expect(diff).toBe(0); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,23 @@ |
|||||
|
import {useEffect, useState} from "react"; |
||||
|
import {fetchBikes, fetchPrograms} from "./net"; |
||||
|
|
||||
|
export default function useOptions() { |
||||
|
const [bikes, setBikes] = useState(null); |
||||
|
const [programs, setPrograms] = useState(null); |
||||
|
|
||||
|
useEffect(() => { |
||||
|
if (programs === null) { |
||||
|
fetchPrograms().then(newPrograms => setPrograms(newPrograms)); |
||||
|
} |
||||
|
}, [programs]); |
||||
|
|
||||
|
useEffect(() => { |
||||
|
if (bikes === null) { |
||||
|
fetchBikes().then(newBikes => { |
||||
|
setBikes(newBikes); |
||||
|
}); |
||||
|
} |
||||
|
}, [bikes]); |
||||
|
|
||||
|
return {bikes, programs}; |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue