-
Notifications
You must be signed in to change notification settings - Fork 24
End time default value #58
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
base: develop
Are you sure you want to change the base?
Changes from all commits
f8289da
d7eef3c
a1d61ba
711bb1e
b498948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,35 @@ describe('Stop', () => { | |
| // Then | ||
| expect(getByTestId('time').textContent).toBe('10'); | ||
| }); | ||
|
|
||
| it('should stop decremental timer when time is 0', () => { | ||
| // Given | ||
| const Component = () => { | ||
| const { time, start } = useTimer({ | ||
| initialTime: 30, | ||
| timerType: 'DECREMENTAL', | ||
| }); | ||
|
|
||
| return ( | ||
| <div> | ||
| <button onClick={start}>Start</button> | ||
| <p data-testid="time">{time}</p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const { getByRole, getByTestId } = render(<Component />); | ||
|
|
||
| // When | ||
| fireEvent.click(getByRole('button')); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(30000); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to advance time by more than 30000 to really test that the timer will stop at 0. I would replace |
||
| }); | ||
|
|
||
| // Then | ||
| expect(getByTestId('time').textContent).toBe('0'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Pause', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,13 @@ import reducer from './state/reducer'; | |
|
|
||
| export const useTimer = ({ | ||
| autostart = false, | ||
| endTime, | ||
| timerType = 'INCREMENTAL', | ||
| endTime = timerType === 'INCREMENTAL' ? null : 0, | ||
| initialTime = 0, | ||
| interval = 1000, | ||
| onTimeOver, | ||
| onTimeUpdate, | ||
| step = 1, | ||
| timerType = 'INCREMENTAL', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep the alphabetical order of properties, to keep the author's logic. |
||
| }: Partial<Config> = {}): ReturnValue => { | ||
| const [state, dispatch] = useReducer(reducer, { | ||
| status: 'STOPPED', | ||
|
|
||
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.
This example is not related to the rest of the PR. I would advise against it.