Skip to content

test: enhance BigNumberInput and HashInput coverage (Tier 2)#416

Merged
gabitoesmiapodo merged 3 commits intotest/utilsfrom
test/enhance-existing
Mar 25, 2026
Merged

test: enhance BigNumberInput and HashInput coverage (Tier 2)#416
gabitoesmiapodo merged 3 commits intotest/utilsfrom
test/enhance-existing

Conversation

@gabitoesmiapodo
Copy link
Collaborator

Summary

  • Enhances BigNumberInput tests with value formatting, min/max validation, decimal precision, and disabled state
  • Enhances HashInput tests with debounce behavior, loading callbacks, and custom renderInput prop

Test plan

  • pnpm test passes on this branch
  • Tests cover viem formatUnits/parseUnits integration points in BigNumberInput

Copilot AI review requested due to automatic review settings March 23, 2026 21:17
@vercel
Copy link

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
components.dappbooster Ready Ready Preview, Comment Mar 23, 2026 11:57pm
demo.dappbooster Ready Ready Preview, Comment Mar 23, 2026 11:57pm
docs.dappbooster Ready Ready Preview, Comment Mar 23, 2026 11:57pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the unit test coverage for shared input components, focusing on BigNumberInput parsing/validation behavior and HashInput search/loading/render customization behavior.

Changes:

  • Added helper render functions and additional interaction tests for HashInput (typing, clearing, loading callbacks, custom renderInput).
  • Added additional interaction and validation tests for BigNumberInput (placeholder/disabled, parsing, min/max, decimal precision).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/components/sharedComponents/HashInput.test.tsx Adds interaction tests around search callbacks, loading state, and custom renderInput.
src/components/sharedComponents/BigNumberInput.test.tsx Adds tests for parsing, validation bounds, placeholder/disabled behavior, and decimal precision handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +71
const onSearch = vi.fn()
detectHashMock.mockResolvedValueOnce({ type: 'ENS', data: '0x123' })
renderHashInput({ onSearch, debounceTime: 0 })
const input = screen.getByTestId('hash-input')
await userEvent.type(input, 'vitalik.eth')
await waitFor(() => {
expect(onSearch).toHaveBeenCalledWith({ type: 'ENS', data: '0x123' })
})
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite the name, this doesn’t currently verify debouncing behavior: debounceTime: 0 effectively disables the debounce window, and userEvent.type will trigger multiple searches (one per keystroke), so the expectation can pass even if the debounce logic is broken. Consider using fake timers with a non-zero debounce, asserting detectHashMock is called once with the final input value, then advancing timers and asserting the final onSearch call.

Suggested change
const onSearch = vi.fn()
detectHashMock.mockResolvedValueOnce({ type: 'ENS', data: '0x123' })
renderHashInput({ onSearch, debounceTime: 0 })
const input = screen.getByTestId('hash-input')
await userEvent.type(input, 'vitalik.eth')
await waitFor(() => {
expect(onSearch).toHaveBeenCalledWith({ type: 'ENS', data: '0x123' })
})
vi.useFakeTimers()
try {
const onSearch = vi.fn()
detectHashMock.mockResolvedValueOnce({ type: 'ENS', data: '0x123' })
const debounceTime = 300
renderHashInput({ onSearch, debounceTime })
const input = screen.getByTestId('hash-input')
await userEvent.type(input, 'vitalik.eth')
// Before the debounce window has elapsed, the detection function should not be called.
expect(detectHashMock).not.toHaveBeenCalled()
await vi.advanceTimersByTimeAsync(debounceTime)
// After the debounce window, detection should be called once with the final input value.
expect(detectHashMock).toHaveBeenCalledTimes(1)
const [[detectedValue]] = detectHashMock.mock.calls
expect(detectedValue).toBe('vitalik.eth')
await waitFor(() => {
expect(onSearch).toHaveBeenCalledWith({ type: 'ENS', data: '0x123' })
})
} finally {
vi.useRealTimers()
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fake-timer approach was attempted but conflicts with both userEvent.type (which uses its own timers for key delays) and waitFor (which uses setInterval for polling) in jsdom. All three interfere and the test timed out. The test was renamed to 'calls onSearch with the detected result' and a comment added explaining the constraint. Debounce isolation testing would require a dedicated adapter or direct component instrumentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok, by testing the debounce functionality we'll be testing a third party library, which I assume has tests and does what it's expected from it

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

BigNumberInput: add 9 tests covering placeholder, disabled state,
onChange with parsed bigint, onError for min/max violations,
decimal precision enforcement, and input clearing.

HashInput: add 7 tests covering placeholder, typed value reflection,
initial value, clear to null, debounced search callback,
onLoading lifecycle, and custom renderInput.
- Rename misleading test names in BigNumberInput (onError absence test,
  maxUint256 constraint test)
- Add beforeEach mock clear in HashInput to prevent cross-test contamination
  from unconsumed mockResolvedValueOnce calls
- Add debounceTime: 0 to clear test to avoid real-timer dependency
- Rename debounce test to accurately describe what it covers; fake-timer
  debounce testing conflicts with waitFor + userEvent in jsdom
React global namespace is not available without explicit import; use
named import from 'react' to avoid 'Cannot find namespace React' errors.

const system = createSystem(defaultConfig)

function renderInput(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines +64 to +71
const onSearch = vi.fn()
detectHashMock.mockResolvedValueOnce({ type: 'ENS', data: '0x123' })
renderHashInput({ onSearch, debounceTime: 0 })
const input = screen.getByTestId('hash-input')
await userEvent.type(input, 'vitalik.eth')
await waitFor(() => {
expect(onSearch).toHaveBeenCalledWith({ type: 'ENS', data: '0x123' })
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok, by testing the debounce functionality we'll be testing a third party library, which I assume has tests and does what it's expected from it

@gabitoesmiapodo gabitoesmiapodo merged commit ff358c9 into test/utils Mar 25, 2026
5 checks passed
@gabitoesmiapodo gabitoesmiapodo deleted the test/enhance-existing branch March 25, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants