Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier setup #1084

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .editorconfig

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore www/dist, manual_lib, json
www/dist
www/manual_lib
www/json

# This is the pattern to check only www directory
# Ignore all
/*
# but don't ignore all the files in www directory
!/www
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": true,
"endOfLine": "lf",
"semi": true
}
3 changes: 2 additions & 1 deletion package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"typescript": "^5.0.3",
"url-loader": "^4.1.1",
"webpack": "^5.0.1",
"webpack-cli": "^5.0.1"
"webpack-cli": "^5.0.1",
"prettier": "3.0.3"
},
"dependencies": {
"@react-navigation/native": "^6.1.7",
Expand Down
101 changes: 62 additions & 39 deletions www/__tests__/diaryHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,86 @@
import { getFormattedDate, isMultiDay, getFormattedDateAbbr, getFormattedTimeRange, getDetectedModes, getBaseModeByKey, modeColors } from "../js/diary/diaryHelper";
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");
expect(getFormattedDate("")).toBeUndefined();
expect(getFormattedDate("2023-09-18T00:00:00-07:00", "2023-09-21T00:00:00-07:00")).toBe("Mon September 18, 2023 - Thu September 21, 2023");
expect(getFormattedDate('2023-09-18T00:00:00-07:00')).toBe('Mon September 18, 2023');
expect(getFormattedDate('')).toBeUndefined();
expect(getFormattedDate('2023-09-18T00:00:00-07:00', '2023-09-21T00:00:00-07:00')).toBe(
'Mon September 18, 2023 - Thu September 21, 2023',
);
});

it('returns an abbreviated formatted date', () => {
expect(getFormattedDateAbbr("2023-09-18T00:00:00-07:00")).toBe("Mon, Sep 18");
expect(getFormattedDateAbbr("")).toBeUndefined();
expect(getFormattedDateAbbr("2023-09-18T00:00:00-07:00", "2023-09-21T00:00:00-07:00")).toBe("Mon, Sep 18 - Thu, Sep 21");
expect(getFormattedDateAbbr('2023-09-18T00:00:00-07:00')).toBe('Mon, Sep 18');
expect(getFormattedDateAbbr('')).toBeUndefined();
expect(getFormattedDateAbbr('2023-09-18T00:00:00-07:00', '2023-09-21T00:00:00-07:00')).toBe(
'Mon, Sep 18 - Thu, Sep 21',
);
});

it('returns a human readable time range', () => {
expect(getFormattedTimeRange("2023-09-18T00:00:00-07:00", "2023-09-18T00:00:00-09:20")).toBe("2 hours");
expect(getFormattedTimeRange("2023-09-18T00:00:00-07:00", "2023-09-18T00:00:00-09:30")).toBe("3 hours");
expect(getFormattedTimeRange("", "2023-09-18T00:00:00-09:30")).toBeFalsy();
expect(getFormattedTimeRange('2023-09-18T00:00:00-07:00', '2023-09-18T00:00:00-09:20')).toBe(
'2 hours',
);
expect(getFormattedTimeRange('2023-09-18T00:00:00-07:00', '2023-09-18T00:00:00-09:30')).toBe(
'3 hours',
);
expect(getFormattedTimeRange('', '2023-09-18T00:00:00-09:30')).toBeFalsy();
});

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 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', () => {
expect(isMultiDay("2023-09-18T00:00:00-07:00", "2023-09-19T00:00:00-07:00")).toBeTruthy();
expect(isMultiDay("2023-09-18T00:00:00-07:00", "2023-09-18T00:00:00-09:00")).toBeFalsy();
expect(isMultiDay("", "2023-09-18T00:00:00-09:00")).toBeFalsy();
expect(isMultiDay('2023-09-18T00:00:00-07:00', '2023-09-19T00:00:00-07:00')).toBeTruthy();
expect(isMultiDay('2023-09-18T00:00:00-07:00', '2023-09-18T00:00:00-09:00')).toBeFalsy();
expect(isMultiDay('', '2023-09-18T00:00:00-09:00')).toBeFalsy();
});

//created a fake trip with relevant sections by examining log statements
let myFakeTrip = {sections: [
{ "sensed_mode_str": "BICYCLING", "distance": 6013.73657416706 },
{ "sensed_mode_str": "WALKING", "distance": 715.3078629361006 }
]};
let myFakeTrip2 = {sections: [
{ "sensed_mode_str": "BICYCLING", "distance": 6013.73657416706 },
{ "sensed_mode_str": "BICYCLING", "distance": 715.3078629361006 }
]};
let myFakeTrip = {
sections: [
{ sensed_mode_str: 'BICYCLING', distance: 6013.73657416706 },
{ sensed_mode_str: 'WALKING', distance: 715.3078629361006 },
],
};
let myFakeTrip2 = {
sections: [
{ sensed_mode_str: 'BICYCLING', distance: 6013.73657416706 },
{ sensed_mode_str: 'BICYCLING', distance: 715.3078629361006 },
],
};

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

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

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
})
});
Loading
Loading