Skip to content

feat: add integration test for holdings entry count after buy/sell tr… - #611

Merged
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
abimbolaalabi:feat/holdings-page
Jul 26, 2026
Merged

feat: add integration test for holdings entry count after buy/sell tr…#611
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
abimbolaalabi:feat/holdings-page

Conversation

@abimbolaalabi

Copy link
Copy Markdown

…ade sequence

Implementation Summary: Holdings Trade Sequence Integration Test

Test File
src/pages/tests/LandingPage.holdingsTradeSequence.integration.test.tsx

Approach
A single end-to-end integration test fires Buy/Sell trades against the LandingPage component and asserts the holdings entry header count after every state mutation. The component is rendered inside MemoryRouter with all external dependencies mocked.

Holdings Derivation (Under Test)

  • index 0 in the API response maps to featuredHoldings (mutable via handleConfirmTrade in LandingPage.tsx:810, starts at 3).
  • Indices 1+ map to DEMO_HELD_KEY_QUANTITIES = [0, 2, 1] (immutable per session).
  • heldKeyPositions is filtered to entries where quantity > 0, producing the displayed holdings list.
  • The displayed entry count is read from data-testid="holdings-header-entry-count".

Test Flow (2 creators -> 5 steps)
Step Action featuredHoldings Held (>0)
Init API returns 2 creators 3 (A) A(3), B(2)
1 Sell 3 (A) 0 (A) B(2)
2 Buy 1 (A) 1 (A) A(1), B(2)
3 Buy 2 (A) 3 (A) A(3), B(2)
4 Sell 3 (A) 0 (A) B(2)

Mocks

  • courseService.getCourses: Returns resolved twoCreators array
  • useNetworkMismatch: Returns { isMismatch: false }
  • useStaleData: Returns { stale: false }
  • StellarConnectionQualityBadge: Returns static
  • CreatorCard: Renders
  • FeaturedCreatorAudienceChip: Renders inert
    - prevents SectionErrorBoundary from collapsing the creator profile section (contains Buy/Sell buttons)
  • framer-motion: Stubs AnimatePresence, LayoutGroup, motion.div/h1/button as static HTML elements

Key Helpers

  • confirmTrade(side, amount) - getAllByRole finds both desktop and mobile Buy/Sell buttons; fills amount input; clicks confirm.
  • waitForHoldingsHeaderCount(n) - Polls getByTestId until textContent equals n.
  • waitForDialogToClose() - Polls queryByRole('dialog') until null.

Radix UI Dialog Workaround
Dialog.Portal applies aria-hidden="true" to all non-dialog elements, breaking getByRole queries. confirmTrade uses getAllByRole so it must wait for dialog to fully close between trades.

Timing
handleConfirmTrade chains setTimeout(resolve, 900) then setTimeout(resolve, 250) (~1.15s per trade). With 4 trades + initial render, wall-clock exceeds vitest 5s default. Test uses 30s timeout.

Pre-existing Warnings (Not Introduced)

  • creator-NaN duplicate key warning (component-level issue)
  • No QueryClient set from FeaturedCreatorAudienceChip (caught by SectionErrorBoundary)

Closes #604

…ade sequence

Implementation Summary: Holdings Trade Sequence Integration Test

Test File
src/pages/__tests__/LandingPage.holdingsTradeSequence.integration.test.tsx

Approach
A single end-to-end integration test fires Buy/Sell trades against the LandingPage component and asserts the holdings entry header count after every state mutation. The component is rendered inside MemoryRouter with all external dependencies mocked.

Holdings Derivation (Under Test)
- index 0 in the API response maps to featuredHoldings (mutable via handleConfirmTrade in LandingPage.tsx:810, starts at 3).
- Indices 1+ map to DEMO_HELD_KEY_QUANTITIES = [0, 2, 1] (immutable per session).
- heldKeyPositions is filtered to entries where quantity > 0, producing the displayed holdings list.
- The displayed entry count is read from data-testid="holdings-header-entry-count".

Test Flow (2 creators -> 5 steps)
Step    Action    featuredHoldings    Held (>0)
Init    API returns 2 creators    3 (A)    A(3), B(2)
1    Sell 3 (A)    0 (A)    B(2)
2    Buy 1 (A)    1 (A)    A(1), B(2)
3    Buy 2 (A)    3 (A)    A(3), B(2)
4    Sell 3 (A)    0 (A)    B(2)

Mocks
- courseService.getCourses: Returns resolved twoCreators array
- useNetworkMismatch: Returns { isMismatch: false }
- useStaleData: Returns { stale: false }
- StellarConnectionQualityBadge: Returns static <div role="status">
- CreatorCard: Renders <article aria-label={title}>
- FeaturedCreatorAudienceChip: Renders inert <div data-testid="mock-audience-chip"> - prevents SectionErrorBoundary from collapsing the creator profile section (contains Buy/Sell buttons)
- framer-motion: Stubs AnimatePresence, LayoutGroup, motion.div/h1/button as static HTML elements

Key Helpers
- confirmTrade(side, amount) - getAllByRole finds both desktop and mobile Buy/Sell buttons; fills amount input; clicks confirm.
- waitForHoldingsHeaderCount(n) - Polls getByTestId until textContent equals n.
- waitForDialogToClose() - Polls queryByRole('dialog') until null.

Radix UI Dialog Workaround
Dialog.Portal applies aria-hidden="true" to all non-dialog elements, breaking getByRole queries. confirmTrade uses getAllByRole so it must wait for dialog to fully close between trades.

Timing
handleConfirmTrade chains setTimeout(resolve, 900) then setTimeout(resolve, 250) (~1.15s per trade). With 4 trades + initial render, wall-clock exceeds vitest 5s default. Test uses 30s timeout.

Pre-existing Warnings (Not Introduced)
- creator-NaN duplicate key warning (component-level issue)
- No QueryClient set from FeaturedCreatorAudienceChip (caught by SectionErrorBoundary)
@drips-wave

drips-wave Bot commented Jul 25, 2026

Copy link
Copy Markdown

@abimbolaalabi 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

@Chucks1093
Chucks1093 merged commit 9a885ca into accesslayerorg:dev Jul 26, 2026
1 check 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 integration test for holdings page rendering correct entry count after buy and sell sequence

2 participants