-
Notifications
You must be signed in to change notification settings - Fork 1
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 bike goal list view and routes #207
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a3c344
feat: Update date-fns from 2.28.0 to 2.29.3
JF-Cozy 44cb584
test(Trips): Rename a test because of unfortunate copy/past
JF-Cozy 55149a3
refactor: Create SpinnerOrEmptyContent to mutualize behavior
JF-Cozy 3cf52ae
feat: Upgrade cozy-ui from 75.4.1 to 76.2.0
JF-Cozy fc5b0b0
feat(BikeGoal): Add some helpers to cook good meals 🍣
JF-Cozy 2321523
feat(BikeGoal): Add query to get bike goal timeseries
JF-Cozy 1c7b0c2
feat(BikeGoal): Add locales
JF-Cozy ac1f796
feat(Titlebar): Add subtitle prop and refactor a bit
JF-Cozy 0cffc42
feat(TripsList): Add noHeader prop
JF-Cozy 7683a2d
feat(BikeGoal): Add some components to create the list view
JF-Cozy 06a49ad
feat(BikeGoal): Add list view and routes
JF-Cozy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import flag from 'cozy-flags' | ||
import { countDays } from 'src/lib/timeseries' | ||
|
||
export const getDaysToReach = () => | ||
flag('coachco2.bikegoal.settings').daysToReach | ||
|
||
export const isGoalCompleted = timeseries => { | ||
return countDays(timeseries) >= getDaysToReach() | ||
} | ||
|
||
export const countDaysOrDaysToReach = timeseries => { | ||
const days = countDays(timeseries) | ||
const daysToReach = getDaysToReach() | ||
|
||
return days < daysToReach ? days : daysToReach | ||
} | ||
|
||
export const makeGoalAchievementPercentage = timeseries => { | ||
const daysOrDaysToReach = countDaysOrDaysToReach(timeseries) | ||
const daysToReach = getDaysToReach() | ||
|
||
return Math.round((daysOrDaysToReach / daysToReach) * 100) | ||
} |
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,83 @@ | ||
import { | ||
isGoalCompleted, | ||
countDaysOrDaysToReach, | ||
makeGoalAchievementPercentage | ||
} from './helpers' | ||
|
||
jest.mock('cozy-flags', () => name => { | ||
if (name === 'coachco2.bikegoal.settings') { | ||
return { daysToReach: 30 } | ||
} | ||
}) | ||
|
||
describe('isGoalCompleted', () => { | ||
it('should return true', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-02T00:00:00' }, | ||
{ startDate: '2021-03-01T00:00:00', endDate: '2021-03-02T00:00:00' } | ||
] | ||
|
||
const res = isGoalCompleted(timeseries) | ||
|
||
expect(res).toBe(true) | ||
}) | ||
|
||
it('should return false', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-02T00:00:00' }, | ||
{ startDate: '2021-01-04T00:00:00', endDate: '2021-01-05T00:00:00' } | ||
] | ||
|
||
const res = isGoalCompleted(timeseries) | ||
|
||
expect(res).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('countDaysOrDaysToReach', () => { | ||
it('should return the number of timeseries days', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-01T00:00:00' }, | ||
{ startDate: '2021-01-05T00:00:00', endDate: '2021-01-05T00:00:00' } | ||
] | ||
|
||
const res = countDaysOrDaysToReach(timeseries) | ||
|
||
expect(res).toBe(4) | ||
}) | ||
|
||
it('should return the days to reach', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-02T00:00:00' }, | ||
{ startDate: '2021-06-01T00:00:00', endDate: '2021-06-01T00:00:00' } | ||
] | ||
|
||
const res = countDaysOrDaysToReach(timeseries) | ||
|
||
expect(res).toBe(30) | ||
}) | ||
}) | ||
|
||
describe('makeGoalAchievementPercentage', () => { | ||
it('should return 30', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-01T00:00:00' }, | ||
{ startDate: '2021-01-05T00:00:00', endDate: '2021-01-05T00:00:00' } | ||
] | ||
|
||
const res = makeGoalAchievementPercentage(timeseries) | ||
|
||
expect(res).toBe(13) | ||
}) | ||
|
||
it('should return 100', () => { | ||
const timeseries = [ | ||
{ startDate: '2021-01-01T00:00:00', endDate: '2021-01-02T00:00:00' }, | ||
{ startDate: '2021-06-01T00:00:00', endDate: '2021-06-01T00:00:00' } | ||
] | ||
|
||
const res = makeGoalAchievementPercentage(timeseries) | ||
|
||
expect(res).toBe(100) | ||
}) | ||
}) |
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
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.
Dans l'état, on a une erreur si le flag n'est pas défini.
Peut-être qu'on aurait pu mettre une valeur par défaut ou émettre une erreur explicite dans ce cas ?
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.
exact, je me suis posé la question, et je suis parti du principe que de toute façon l'app ne marcherait pas sans et que le flag serait présent sur les instances... un throw explicite serait bien dans ce genre de conclusion 👍