Skip to content

Conversation

@bordalix
Copy link
Collaborator

@bordalix bordalix commented Nov 11, 2025

Summary by CodeRabbit

  • Tests

    • Added unit tests for the Wallet Send screen covering loading and full-state scenarios.
    • Added expanded test infrastructure including a comprehensive mock wallet to improve test coverage.
    • Updated transaction screen tests to use more reliable assertions across states.
  • Chores

    • Added a new npm script to run unit tests easily.
  • Refactor

    • Consolidated helper logic in the Send form to streamline error handling and state updates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

This PR adds a unit test script, refactors helper functions in the Wallet Send form, introduces comprehensive test mocks including a mock service wallet, adds Vitest tests for the Send screen, and relaxes/assertion changes in transaction screen tests.

Changes

Cohort / File(s) Summary
NPM Script Addition
package.json
Added test:unit script: "vitest run --exclude '**/e2e/**'"
SendForm Refactoring
src/screens/Wallet/Send/Form.tsx
Moved and consolidated smartSetError and setState helpers to top-level scope of the component; removed duplicate declarations and centralized error/state updates
Test Mocks
src/test/screens/mocks.ts
Added imports from @arkade-os/sdk and exported mock context values (mockConfigContextValue, mockFiatContextValue, mockLightningContextValue, mockOptionsContextValue) plus mockSvcWallet with identity, wallet/repositories stubs, async methods, and serviceWorker state
Send Screen Tests
src/test/screens/wallet/send.test.tsx
Added Vitest test file rendering SendForm with mocked contexts; tests for loading and initialized svcWallet states and asserts presence of key UI elements (Max, Send, Amount, SATS balance, Recipient, Continue)
Transaction Screen Tests
src/test/screens/wallet/transaction.test.tsx
Relaxed/changed assertions: removed some title/subtext validations and replaced findByText(...).not.toBeInTheDocument() with queryByText(...).not.toBeInTheDocument() for certain button checks; retained structural UI assertions

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Test Runner
    participant SendForm as SendForm Component
    participant Helpers as Consolidated Helpers
    participant State as Component State
    participant Mocks as Mock Contexts / svcWallet

    Runner->>Mocks: Provide mocked contexts & mockSvcWallet
    Runner->>SendForm: Render component
    SendForm->>Helpers: invoke smartSetError / setState
    Helpers->>State: update sendInfo, setScan(false), set error
    SendForm-->>Runner: Render UI (Max, Amount, Recipient, Continue)
    Runner->>Runner: Assert UI elements present / absent
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay extra attention to:
    • src/screens/Wallet/Send/Form.tsx — ensure all call sites use the consolidated helpers and behavior unchanged.
    • src/test/screens/mocks.ts — verify mockSvcWallet shape matches production interfaces used by tested components.
    • src/test/screens/wallet/send.test.tsx — confirm test setup correctly isolates contexts and that assertions reflect intended render timing.

Possibly related PRs

  • End-to-End tests #202 — Modifies src/screens/Wallet/Send/Form.tsx (adds InputAmount name prop); likely interacts with the SendForm refactor.
  • soft settle #171 — Adjusts src/test/screens/wallet/transaction.test.tsx assertions similarly; related testing pattern changes.

Suggested reviewers

  • Kukks
  • louisinger

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Send tests' accurately describes the main focus of the pull request, which adds unit tests for the Wallet Send screen component along with supporting test infrastructure.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch send_tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 11, 2025

Deploying wallet-signet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0771343
Status: ✅  Deploy successful!
Preview URL: https://33dd7b08.wallet-23u.pages.dev
Branch Preview URL: https://send-tests.wallet-23u.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 11, 2025

Deploying wallet-mutinynet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0771343
Status: ✅  Deploy successful!
Preview URL: https://209105ef.arkade-wallet.pages.dev
Branch Preview URL: https://send-tests.arkade-wallet.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 11, 2025

Deploying wallet-bitcoin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0771343
Status: ✅  Deploy successful!
Preview URL: https://deb9a66b.wallet-bitcoin.pages.dev
Branch Preview URL: https://send-tests.wallet-bitcoin.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/screens/mocks.ts (1)

87-137: Consider using deterministic identity for test stability.

The mockSvcWallet is comprehensive and well-structured. However, using SingleKey.fromRandomBytes() on line 88 creates a new random identity on each test run, which could lead to non-deterministic test behavior if any test logic depends on the identity value.

If deterministic behavior is desired, consider creating the identity from a fixed seed:

 export const mockSvcWallet = {
-  identity: SingleKey.fromRandomBytes(),
+  identity: SingleKey.fromPrivateKey(new Uint8Array(32).fill(1)), // deterministic test identity
   getAddress: () => '',

Alternatively, if the current approach is intentional for test isolation, consider adding a comment explaining the rationale.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b32314 and 0acd150.

📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/screens/Wallet/Send/Form.tsx (1 hunks)
  • src/test/screens/mocks.ts (2 hunks)
  • src/test/screens/wallet/send.test.tsx (1 hunks)
  • src/test/screens/wallet/transaction.test.tsx (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-30T18:33:29.839Z
Learnt from: bordalix
Repo: arkade-os/wallet PR: 114
File: src/lib/asp.ts:0-0
Timestamp: 2025-06-30T18:33:29.839Z
Learning: In src/lib/asp.ts, only the collaborativeExit function should accept both IWallet and ServiceWorkerWallet types. Other wallet functions (getBalance, getTxHistory, getReceivingAddresses, redeemNotes, sendOnChain, settleVtxos) should maintain their original IWallet-only signatures and not be updated for consistency.

Applied to files:

  • src/test/screens/wallet/send.test.tsx
  • src/test/screens/mocks.ts
  • src/test/screens/wallet/transaction.test.tsx
🧬 Code graph analysis (2)
src/test/screens/wallet/send.test.tsx (7)
src/providers/navigation.tsx (1)
  • NavigationContext (164-168)
src/test/screens/mocks.ts (6)
  • mockNavigationContextValue (35-39)
  • mockAspContextValue (28-33)
  • mockFlowContextValue (59-72)
  • mockWalletContextValue (41-57)
  • mockLimitsContextValue (74-85)
  • mockSvcWallet (87-137)
src/providers/asp.tsx (1)
  • AspContext (15-20)
src/providers/flow.tsx (1)
  • FlowContext (82-95)
src/providers/wallet.tsx (1)
  • WalletContext (40-54)
src/providers/limits.tsx (1)
  • LimitsContext (28-39)
src/screens/Wallet/Send/Form.tsx (1)
  • SendForm (43-399)
src/screens/Wallet/Send/Form.tsx (1)
src/providers/flow.tsx (1)
  • SendInfo (24-36)
🔇 Additional comments (6)
package.json (1)

35-35: LGTM!

The new unit test script is well-structured and follows the existing pattern. The exclude pattern correctly filters out e2e tests.

src/screens/Wallet/Send/Form.tsx (1)

70-77: LGTM! Centralized helper functions improve maintainability.

Moving these helper functions to a consistent location near the top of the component body improves code organization and eliminates duplication. The smartSetError function appropriately centralizes the logic for handling Ark server unreachability, and setState provides a clean wrapper for common state updates.

src/test/screens/wallet/transaction.test.tsx (4)

84-85: Correct fix: Use queryByText for negative assertions.

This change correctly uses queryByText instead of findByText for checking element absence. The findByText method returns a promise and will throw an error if the element is not found, making it unsuitable for negative assertions. The queryByText method returns null synchronously when an element is not found, which is the appropriate choice for .not.toBeInTheDocument() assertions.


154-155: Correct fix: Use queryByText for negative assertions.

Same improvement as in the previous test case - correctly using queryByText for checking element absence.


189-190: Correct fix: Use queryByText for negative assertions.

Same improvement as in the previous test cases - correctly using queryByText for checking element absence.


226-227: Correct fix: Use queryByText for negative assertions.

Same improvement as in the previous test cases - correctly using queryByText for checking element absence.

<NavigationContext.Provider value={mockNavigationContextValue}>
<AspContext.Provider value={mockAspContextValue}>
<FlowContext.Provider value={mockFlowContextValue}>
<WalletContext.Provider value={{ ...mockWalletContextValue, svcWallet: mockSvcWallet as any }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid type assertion with as any.

The as any cast bypasses type checking and could hide type mismatches between mockSvcWallet and the expected svcWallet type. This defeats the purpose of TypeScript's type safety.

Consider defining a proper type for mockSvcWallet or use a more specific type assertion. You can check the actual type expected by WalletContext and ensure mockSvcWallet conforms to it:

-<WalletContext.Provider value={{ ...mockWalletContextValue, svcWallet: mockSvcWallet as any }}>
+<WalletContext.Provider value={{ ...mockWalletContextValue, svcWallet: mockSvcWallet }}>

If there are type mismatches, update mockSvcWallet in mocks.ts to properly implement the required interface rather than using as any.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/test/screens/wallet/send.test.tsx around line 41, replace the unsafe `as
any` cast on mockSvcWallet by ensuring mockSvcWallet is typed to the exact
svcWallet type expected by WalletContext: import (or reference) the
WalletContext svcWallet interface/type, update the mock implementation in
mocks.ts to include all required properties/methods so it conforms to that
interface, and use that concrete type (or a narrow type assertion only if
unavoidable) when providing value to WalletContext.Provider so TypeScript
enforces compatibility rather than bypassing checks.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0acd150 and 0771343.

📒 Files selected for processing (2)
  • src/test/screens/mocks.ts (3 hunks)
  • src/test/screens/wallet/send.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/screens/wallet/send.test.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-30T18:33:29.839Z
Learnt from: bordalix
Repo: arkade-os/wallet PR: 114
File: src/lib/asp.ts:0-0
Timestamp: 2025-06-30T18:33:29.839Z
Learning: In src/lib/asp.ts, only the collaborativeExit function should accept both IWallet and ServiceWorkerWallet types. Other wallet functions (getBalance, getTxHistory, getReceivingAddresses, redeemNotes, sendOnChain, settleVtxos) should maintain their original IWallet-only signatures and not be updated for consistency.

Applied to files:

  • src/test/screens/mocks.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/test/screens/mocks.ts (2)

35-53: LGTM! Mock context values are well-structured.

The new mock context exports provide appropriate default values for testing scenarios.


143-156: Verify that undefined properties are intentional.

Several properties are set to undefined (sendMessage, clear, getStatus, reload). If tests attempt to call these as functions, they will fail with "undefined is not a function" errors.

Please confirm whether:

  1. These properties are intentionally undefined because they're unused in the tests
  2. They should be stubbed as no-op functions: () => {} or () => Promise.resolve()

If they should be stubbed, apply this diff:

-  sendMessage: undefined,
+  sendMessage: () => {},
-  clear: undefined,
-  getStatus: undefined,
-  reload: undefined,
+  clear: () => Promise.resolve(),
+  getStatus: () => Promise.resolve(undefined),
+  reload: () => Promise.resolve(),

}

export const mockSvcWallet = {
identity: SingleKey.fromRandomBytes(),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Non-deterministic mock identity may cause test flakiness.

Using SingleKey.fromRandomBytes() creates a different identity on each test run, which can lead to non-deterministic test behavior if tests depend on consistent identity values.

Consider using a deterministic seed for reproducible tests:

-  identity: SingleKey.fromRandomBytes(),
+  identity: SingleKey.fromSeed(new Uint8Array(32).fill(1)), // deterministic seed

Alternatively, if randomness is acceptable for your test scenarios, you can ignore this suggestion.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/test/screens/mocks.ts around line 108, the mock identity is created with
SingleKey.fromRandomBytes() which yields a non-deterministic value; replace it
with a deterministic identity (for example use SingleKey.fromSeed() or
fromBytes() with a fixed seed/byte array or a constant test key) so tests are
reproducible, or explicitly document/feature-flag the randomness if you intend
to keep it.

@bordalix bordalix merged commit 82ad320 into master Nov 11, 2025
6 checks passed
This was referenced Nov 15, 2025
@bordalix bordalix deleted the send_tests branch November 26, 2025 14:30
@coderabbitai coderabbitai bot mentioned this pull request Dec 17, 2025
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.

2 participants