Skip to content

Fix/unit tests hooks utils 248#272

Merged
Mosas2000 merged 33 commits intomainfrom
fix/unit-tests-hooks-utils-248
Mar 15, 2026
Merged

Fix/unit tests hooks utils 248#272
Mosas2000 merged 33 commits intomainfrom
fix/unit-tests-hooks-utils-248

Conversation

@Mosas2000
Copy link
Copy Markdown
Owner

Closes #248

Mosas2000 and others added 30 commits March 15, 2026 12:12
Cover initial loading state, successful fetch, error states (non-ok,
missing data, network error), toUsd conversion with various inputs
(null, undefined, string, number), refetch behavior, and error
recovery after successful refetch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover initial state, empty/null recipient, self-check short-circuit,
whitespace trimming, checking state transitions, blocked/not-blocked
contract results (including string true), error handling, reset
behavior, stale response discard, and argument verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover empty/invalid/null input, tip-sent and tip-categorized parsing,
default values for missing fields, message extraction, large amounts
and tip IDs, unicode event prefix, all seven categories, and null
category when not present.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover MIN_TIP_STX and MAX_TIP_STX constant exports, empty/null/
undefined/whitespace inputs, zero, negative, non-numeric, below-
minimum, exact-minimum, valid amounts, exact-maximum, above-maximum,
typical tip amounts, and decimal edge cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The hook retries up to MAX_RETRIES times with a 1500ms delay, which
caused error tests to timeout with real timers. Switch to fake timers
for error/retry tests, add retry count verification, and add a test
for successful recovery on retry after initial failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test the isValidStacksAddress regex pattern shared by SendTip,
BatchTip, and TokenTip: empty/null/undefined, SP/SM/ST prefixes,
length bounds, special characters, case insensitivity, whitespace.
Also test isValidContractId from TokenTip: empty, missing parts,
multiple dots, invalid address portion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test the Set-based duplicate address detection with unique addresses,
duplicates, trimmed whitespace, empty/null addresses, and multiple
duplicate pairs. Also test amount validation for empty, non-numeric,
zero, negative, below-minimum, exact-minimum, and valid amounts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test contract ID splitting into address and name parts, whitespace
trimming, hyphen and underscore handling. Also test the validation
flow: empty ID, missing separator, invalid address, empty name,
and well-formed IDs with SP/ST/SM prefixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify toUsd formats output to exactly two decimal places and
that a zero price from the API is handled correctly with toUsd
returning 0.00.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ed input

Verify case-insensitive sender parsing, extra whitespace tolerance,
fee field extraction, and graceful handling of non-string inputs
(numbers, objects, arrays) without throwing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover empty/null/zero/negative/non-numeric inputs, minimum and
maximum amounts, decimal edge cases, and self-tip detection with
whitespace trimming.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document all new test files and the useBalance test fix for the
unit test coverage expansion across hooks, utilities, and
component validation logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ckCheck

Verify that sequential checkBlocked calls with different recipients
update the blocked state correctly, and that checking is always set
to false after an error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that converting micro-STX to STX and back yields the
original value for whole numbers, fractional amounts, and small
values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that successful fetch sets a numeric lastFetched timestamp,
that the hook exposes a refetch function, and that lastFetched
starts as null when no address is provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Call refetch() with a fresh mock response and confirm the hook
exposes new balance and balanceStx values, proving the function
actually triggers a new network request.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…s on null

Add two tests: one that re-renders with a new address and confirms
a fresh fetch is triggered, and another that switches to null and
verifies balance resets properly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tests proving the hook re-fetches price after 60 seconds,
stops polling on unmount, preserves the last good price when a
subsequent poll fails, and returns '0.00' for zero STX input.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify the hook fetches from the expected CoinGecko API URL with
the stacks ID and USD currency parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…incipals

Cover explicit u0 amounts and tip-ids, empty message strings,
category values outside the standard 0-6 range, contract principal
suffixes being excluded from sender addresses, and custom event names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test mid-pagination short page detection, error thrown on second
page during multi-page fetch, and combined startOffset+maxPages
parameter behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that entries with an empty repr string are filtered out
and that a zero block_time value is treated as falsy (mapped to
null) by the existing || coercion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ant tests

Cover 280-character message limit, self-tip detection with whitespace
trimming, totalAmount reduce logic with NaN-safe accumulation, and
verify MAX_BATCH_SIZE/MIN_TIP_STX constant values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…age tests

Verify insufficient-balance guard with null/valid/exceeded balances,
assert MIN_TIP_STX and MAX_TIP_STX constants, confirm TIP_CATEGORIES
has 7 entries with consecutive IDs, and test default "Thanks!" message
fallback for empty/null/undefined inputs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… tests

Cover parseInt truncation for decimal token amounts, nested and flat
whitelist response shapes, null/undefined contract ID rejection, and
IDs with more than one dot separator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover NaN, Infinity, and negative Infinity string inputs along with
a small positive amount just above the minimum threshold.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…cial cases

Test length boundaries at 37 and 42 chars, lowercase prefix acceptance,
prefix-only rejection, numeric-only body, contract principal dot
rejection, embedded space rejection, and contract ID whitespace trimming.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… config

Test isWalletInstalled with StacksProvider, LeatherProvider, both,
and neither. Verify appDetails name and icon, and network resolution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify PWA cache rules correctly apply NetworkFirst to balance,
transactions, and nonce endpoints while leaving static assets
and CoinGecko requests with appropriate strategies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover skeleton loading, error state, tab switching, refresh button,
timestamp display, empty state, ranking order, medal classes, event
filtering, footer total, and Load More behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Mosas2000 and others added 3 commits March 15, 2026 13:48
Test empty input, single sender/recipient, amount aggregation across
multiple tips, self-tips, address counting, large amounts, and
ensure correct sorting by total sent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…bers

Reflect expanded test counts: useStxPrice 19, parseTipEvent 23,
address-validation 30, batch-tip 29, send-tip 26, token-tip 23,
tipBackValidation 21, useBalance 17, contractEvents 22, and new
files for stacks-utils, pwa-cache-rules, Leaderboard, and
buildLeaderboardStats.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponent

The current Leaderboard component does not disable the Refresh
button or swap text during refresh. Update tests to verify the
button remains present with standard styling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Mosas2000 Mosas2000 merged commit e83133e into main Mar 15, 2026
3 of 7 checks passed
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.

Add unit tests for hooks, utilities, and component validation logic

1 participant