Skip to content

[162] Write React Testing Library assertions for network_sync_checker - #358

Open
kingeligma wants to merge 2 commits into
Goldii-locks:mainfrom
kingeligma:fix/162-write-react-testing-library-assertions-for-network-sync-checker
Open

[162] Write React Testing Library assertions for network_sync_checker#358
kingeligma wants to merge 2 commits into
Goldii-locks:mainfrom
kingeligma:fix/162-write-react-testing-library-assertions-for-network-sync-checker

Conversation

@kingeligma

@kingeligma kingeligma commented Aug 29, 2026

Copy link
Copy Markdown

Closes #162

What

Adds a NetworkSyncChecker component and React Testing Library assertions that exercise the full network_sync_checker probe lifecycle:

  • renders the trigger action and initial idle status
  • transitions to blocked (with the network warning bar) when wallet and app networks differ, without invoking the signer
  • surfaces wallet setup instructions and blocks when no extension is detected
  • transitions to synced when the wallet approves the probe
  • transitions to cancelled and logs + toasts on user rejection ("user rejected", "user declined the request")
  • transitions to error on unexpected signing failures
  • re-enables the trigger after a probe resolves

Repairs required to make the suite/CI green

The repo's test suite did not run green locally or in CI (pre-existing). This branch fixes each blocker so the PR's checks pass:

  • SignatureTimeoutAlert — replace setState-in-useEffect with a useMemo-derived parse result (fixes eslint react-hooks/set-state-in-effect, which blocked CI's lint step).
  • vitest.setup.ts — shim localStorage when Node's experimental global shadows jsdom's (Node 24+ ships a localStorage that is undefined without --localstorage-file).
  • freighter_multisig_hook tests — build real signed transaction envelopes instead of arbitrary bytes the hook's XDR parser rejects.
  • freighter component / signature-timeout suites — stub useWallet (real provider default shape) so the stellar-wallets-kit UMD module graph no longer breaks suite load; wrap loader-counter updates in act() for React 19.

Checks

  • npm run lint — pass
  • npm run type-check — pass
  • npm run test — 87 files / 1326 tests pass
  • npm run build — pass

Adds an interactive NetworkSyncChecker component exposing the
network_sync_checker probe lifecycle (idle, checking, synced, cancelled,
blocked, error) with React Testing Library assertions for network
mismatch, missing-wallet setup instructions, signature approval,
user rejection, unexpected signing failures and probe re-runs.

Also repairs pre-existing blockers so the full suite and CI go green:

- SignatureTimeoutAlert: derive parse failures with useMemo instead of
  setState-in-effect (fixes eslint react-hooks/set-state-in-effect).
- vitest.setup: shim localStorage for Node 26's experimental global that
  shadows jsdom's.
- freighter_multisig_hook: use real signed transaction envelopes instead
  of arbitrary bytes the hook's XDR parser rejects.
- freighter component / signature timeout suites: stub WalletProvider's
  useWallet so the stellar-wallets-kit UMD graph no longer breaks module
  load; wrap loader-counter updates in act() for React 19.

Closes 162
Copilot AI lite review requested due to automatic review settings August 29, 2026 16:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new NetworkSyncChecker UI component and a comprehensive React Testing Library suite that exercises the network_sync_checker lifecycle end-to-end, while also making a set of targeted test/lint fixes needed to get the existing suite green in CI.

Changes:

  • Introduces NetworkSyncChecker plus new RTL assertions covering network mismatch, missing wallet, successful signing, user rejection, and unexpected errors.
  • Refactors SignatureTimeoutAlert to compute parse errors as derived state (avoiding setState in useEffect) and updates related tests/mocks for React 19 + ESM constraints.
  • Stabilizes the test environment and fixtures (Vitest localStorage shim; multisig hook fixtures now use real signed envelopes).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.setup.ts Adds a Node-version-safe localStorage shim for jsdom-based tests.
app/components/SignatureTimeoutAlert.tsx Replaces effect-driven parse error state with useMemo-derived state.
app/components/NetworkSyncChecker.tsx New interactive component that runs the sync probe and renders probe status + warnings.
__tests__/signature_timeout_alert.test.tsx Stubs useWallet to avoid UMD import issues; wraps loader-counter updates in act().
__tests__/network_sync_checker_component.test.tsx New RTL suite for the NetworkSyncChecker probe lifecycle.
__tests__/freighter_multisig_hook.test.ts Builds valid signed transaction envelopes so XDR parsing under test succeeds.
__tests__/freighter_connector.component.test.tsx Stubs useWallet to keep the Freighter connector suite loadable under Node ESM.
Suppressed comments (1)

app/components/NetworkSyncChecker.tsx:114

  • The blocked status copy says "resolve the warning below", but the warning UI is rendered above this status output (and in some blocked cases there may be no warning). Consider using location-agnostic wording to avoid confusing users.
          {status === "blocked" &&
            "Network sync blocked — resolve the warning below and try again."}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +64 to +71
const availabilityState = availability ?? checkWalletAvailability(detector);
if (!availabilityState.available || typeof onSign !== "function") {
if (showToast && availabilityState.warningMessage) {
showToast(availabilityState.warningMessage, "warning");
}
setStatus("blocked");
return;
}
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@kingeligma Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…cing timers

Three timeout tests attached promise.catch() only after awaiting timer
advance, so the rejected outer promise could be snapshotted as unhandled
by Node during the interleaved microtask gap, making vitest report 3
unhandled errors and exit non-zero despite all tests passing. Attach the
handler immediately after runSignatureWithTimeout (mirroring the
.rejects-based tests) to keep npm run test exiting cleanly.
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.

Write React Testing Library assertions for network_sync_checker

2 participants