Skip to content

Commit

Permalink
Merge pull request #1036 from JGreenlee/fix-diaryhelper-tests
Browse files Browse the repository at this point in the history
fix diaryHelper tests: update to refactored fns
  • Loading branch information
shankari authored Sep 23, 2023
2 parents 53911a2 + 8c24387 commit c341e35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions www/__tests__/diaryHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getFormattedSectionProperties, getFormattedDate, motionTypeOf, isMultiDay, getFormattedDateAbbr, getFormattedTimeRange, getPercentages } from "../js/diary/diaryHelper";
import { useImperialConfig } from "../js/config/useImperialConfig";
import { getFormattedDate, isMultiDay, getFormattedDateAbbr, getFormattedTimeRange, getDetectedModes, getBaseModeByKey, modeColors } from "../js/diary/diaryHelper";

it('returns a formatted date', () => {
expect(getFormattedDate("2023-09-18T00:00:00-07:00")).toBe("Mon September 18, 2023");
Expand All @@ -19,10 +18,10 @@ it('returns a human readable time range', () => {
expect(getFormattedTimeRange("", "2023-09-18T00:00:00-09:30")).toBeFalsy();
});

it("returns a MotionType object", () => {
expect(motionTypeOf("WALKING")).toEqual({ name: "WALKING", icon: "walk", color: '#0068a5' });
expect(motionTypeOf("MotionTypes.WALKING")).toEqual({ name: "WALKING", icon: "walk", color: '#0068a5' });
expect(motionTypeOf("I made this type up")).toEqual({ name: "UNKNOWN", icon: "help", color: '#484848'});
it("returns a Base Mode for a given key", () => {
expect(getBaseModeByKey("WALKING")).toEqual({ name: "WALKING", icon: "walk", color: modeColors.blue });
expect(getBaseModeByKey("MotionTypes.WALKING")).toEqual({ name: "WALKING", icon: "walk", color: modeColors.blue });
expect(getBaseModeByKey("I made this type up")).toEqual({ name: "UNKNOWN", icon: "help", color: modeColors.grey });
});

it('returns true/false is multi day', () => {
Expand All @@ -41,25 +40,24 @@ let myFakeTrip2 = {sections: [
{ "sensed_mode_str": "BICYCLING", "distance": 715.3078629361006 }
]};

let myFakePcts = [
let myFakeDetectedModes = [
{ mode: "BICYCLING",
icon: "bike",
color: '#007e46',
color: modeColors.green,
pct: 89 },
{ mode: "WALKING",
icon: "walk",
color: '#0068a5',
color: modeColors.blue,
pct: 11 }];

let myFakePcts2 = [
let myFakeDetectedModes2 = [
{ mode: "BICYCLING",
icon: "bike",
color: '#007e46',
color: modeColors.green,
pct: 100 }];

it('returns the percetnages by mode for a trip', () => {
expect(getPercentages(myFakeTrip)).toEqual(myFakePcts);
expect(getPercentages(myFakeTrip2)).toEqual(myFakePcts2);
expect(getPercentages({})).toEqual({});
it('returns the detected modes, with percentages, for a trip', () => {
expect(getDetectedModes(myFakeTrip)).toEqual(myFakeDetectedModes);
expect(getDetectedModes(myFakeTrip2)).toEqual(myFakeDetectedModes2);
expect(getDetectedModes({})).toEqual([]); // empty trip, no sections, no modes
})

2 changes: 1 addition & 1 deletion www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import moment from "moment";
import { DateTime } from "luxon";

const modeColors = {
export const modeColors = {
pink: '#d43678', // oklch(59% 0.2 0) // e-car
red: '#b9003d', // oklch(50% 0.37 15) // car
orange: '#b25200', // oklch(55% 0.37 50) // air, hsr
Expand Down

0 comments on commit c341e35

Please sign in to comment.