Skip to content

Commit

Permalink
Speedup CountdownButton in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jul 8, 2024
1 parent 81b1dc8 commit 1c0ab37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions .changelog/1995.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speedup CountdownButton in tests
17 changes: 10 additions & 7 deletions src/app/components/CountdownButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export const CountdownButton = (props: Omit<ButtonExtendedProps, 'disabled'>) =>
const isDisabled = countdown > 0

useEffect(() => {
const timerId = setInterval(() => {
setCountdown(prevCountdown => {
const newCount = prevCountdown - 1
if (newCount <= 0) clearInterval(timerId)
return newCount
})
}, 1000)
const timerId = setInterval(
() => {
setCountdown(prevCountdown => {
const newCount = prevCountdown - 1
if (newCount <= 0) clearInterval(timerId)
return newCount
})
},
process.env.REACT_APP_E2E_TEST ? 200 : 1000,
)

return () => clearInterval(timerId)
}, [])
Expand Down

0 comments on commit 1c0ab37

Please sign in to comment.