The TradeForm component is a critical part of the CompactX application that handles token swapping functionality. It includes input/output token selection, amount entry, quote fetching, and swap execution.
Test: should handle input amount changes
- Verify that users can enter numerical values into the input amount field
- Ensure the input updates the UI correctly
- Confirm that the quote is requested when amount changes
- Validate that the input accepts valid numbers and handles invalid inputs appropriately
Test: should show "Getting Quote..." during loading
- Verify that a loading indicator appears while fetching a quote
- Ensure the loading state is triggered when:
- Input token is selected
- Output token is selected
- Amount is changed
- Confirm the loading state is cleared when quote is received
Test: should handle quote error state
- Verify appropriate error messages are displayed when quote fetching fails
- Ensure the UI handles error states gracefully
- Confirm that users can recover from error states by:
- Changing input/output tokens
- Modifying amounts
- Retrying the quote
Test: should handle swap execution
- Verify that the swap button is enabled when a valid quote exists
- Ensure proper handling of the swap transaction:
- Transaction submission
- Loading states during transaction
- Success/failure notifications
- Confirm the form resets appropriately after successful swap
- Portal Container
- Create a dedicated portal container for Ant Design dropdowns
- Clean up portal container after each test
-
Token Selection
- Mock available tokens list
- Mock token balances
- Mock price data
-
Network Interactions
- Mock wallet connection state
- Mock quote fetching
- Mock transaction broadcasting
-
Token Selection
selectInputToken(); // Helper to select input token selectOutputToken(); // Helper to select output token
-
Amount Entry
enterAmount(); // Helper to enter swap amount
The main challenge appears to be with the dropdown testing implementation:
- Dropdowns are not being found in the DOM after opening
- This affects all tests that require token selection
- The issue might be related to:
- Timing of dropdown rendering
- Portal container setup
- Ant Design's dropdown implementation
- Test environment configuration
- Verify portal container setup is working correctly
- Review dropdown rendering lifecycle
- Consider adding additional waiting/assertion logic for dropdown visibility
- May need to modify how we interact with Ant Design dropdowns in tests
- Consider adding debugging logs to track dropdown rendering state