-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/asset-receive-network
- Loading branch information
Showing
10 changed files
with
534 additions
and
9 deletions.
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
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
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,53 @@ | ||
import safePromiseHandler from './utils'; | ||
|
||
describe('safePromiseHandler', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.runOnlyPendingTimers(); | ||
jest.useRealTimers(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return a function', () => { | ||
const toggleFunction = jest.fn(); | ||
const handler = safePromiseHandler(toggleFunction); | ||
expect(typeof handler).toBe('function'); | ||
}); | ||
|
||
it('should call toggleFunction after the default delay (100ms)', () => { | ||
const toggleFunction = jest.fn(); | ||
const handler = safePromiseHandler(toggleFunction); | ||
handler(); | ||
// Initially, the toggleFunction should not have been called. | ||
expect(toggleFunction).not.toHaveBeenCalled(); | ||
// Advance time by 100ms | ||
jest.advanceTimersByTime(100); | ||
expect(toggleFunction).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call toggleFunction after a custom delay', () => { | ||
const customDelay = 250; | ||
const toggleFunction = jest.fn(); | ||
const handler = safePromiseHandler(toggleFunction, customDelay); | ||
handler(); | ||
// Advance time by less than customDelay; function should not have been called yet. | ||
jest.advanceTimersByTime(customDelay - 1); | ||
expect(toggleFunction).not.toHaveBeenCalled(); | ||
// Advance by the remaining time. | ||
jest.advanceTimersByTime(1); | ||
expect(toggleFunction).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call toggleFunction for each invocation of the handler', () => { | ||
const toggleFunction = jest.fn(); | ||
const handler = safePromiseHandler(toggleFunction); | ||
// Call the returned function twice. | ||
handler(); | ||
handler(); | ||
jest.advanceTimersByTime(100); | ||
expect(toggleFunction).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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,13 @@ | ||
/** | ||
* Delays the execution of a function by a specified amount of time. | ||
* | ||
* @param toggleFunction - The function to execute after the delay. | ||
* @param delay - The delay in milliseconds (default: 100ms). | ||
* @returns A function that, when called, will execute the provided function after the delay. | ||
*/ | ||
const safePromiseHandler = | ||
(toggleFunction: () => void, delay: number = 100): (() => void) => | ||
() => | ||
setTimeout(toggleFunction, delay); | ||
|
||
export default safePromiseHandler; |
37 changes: 34 additions & 3 deletions
37
...Confirm/AccountNetworkInfo/AccountNetworkInfoExpanded/AccountNetworkInfoExpanded.test.tsx
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
Oops, something went wrong.