-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add Jest for Basic Testing of Pure Functions #1033
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
856b2d6
add jest for basic testing of pure functions
JGreenlee 4604405
add some DiaryHelper tests
1b49b89
fix motionTypeOf function; re-enable test
JGreenlee df60ea4
more diaryHelper tests
f24ce9d
add step in serve-install for jest tests
JGreenlee 1d0ddca
jest: ignore these directories when discover tests
JGreenlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,15 @@ | ||
{ | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/platforms/", | ||
"/plugins/", | ||
"/lib/", | ||
"/manual_lib/" | ||
], | ||
"transform": { | ||
"^.+\\.(ts|tsx|js|jsx)$": "ts-jest" | ||
}, | ||
"moduleNameMapper": { | ||
"^react-native$": "react-native-web" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getFormattedSectionProperties, getFormattedDate, motionTypeOf, isMultiDay, getFormattedDateAbbr, getFormattedTimeRange, getPercentages } from "../js/diary/diaryHelper"; | ||
import { useImperialConfig } from "../js/config/useImperialConfig"; | ||
|
||
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"); | ||
}); | ||
|
||
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"); | ||
}); | ||
|
||
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(); | ||
}); | ||
|
||
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 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(); | ||
}); | ||
|
||
//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 myFakePcts = [ | ||
{ mode: "BICYCLING", | ||
icon: "bike", | ||
color: '#007e46', | ||
pct: 89 }, | ||
{ mode: "WALKING", | ||
icon: "walk", | ||
color: '#0068a5', | ||
pct: 11 }]; | ||
|
||
let myFakePcts2 = [ | ||
{ mode: "BICYCLING", | ||
icon: "bike", | ||
color: '#007e46', | ||
pct: 100 }]; | ||
|
||
it('returns the percetnages by mode for a trip', () => { | ||
expect(getPercentages(myFakeTrip)).toEqual(myFakePcts); | ||
expect(getPercentages(myFakeTrip2)).toEqual(myFakePcts2); | ||
expect(getPercentages({})).toEqual({}); | ||
}) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the server code, we have install and test in separate workflows.
(future fix): I am fine with having this in the same workflow (at least initially), but then we should rename the file to indicate that it is also testing.