Skip to content

🧪 Add Reactivity and Edge Case Tests for GetDashboardStatsUseCase#43

Merged
Max97k merged 1 commit into
mainfrom
testing-improvement-dashboard-stats-12347842984059675557
Jun 23, 2026
Merged

🧪 Add Reactivity and Edge Case Tests for GetDashboardStatsUseCase#43
Max97k merged 1 commit into
mainfrom
testing-improvement-dashboard-stats-12347842984059675557

Conversation

@Max97k

@Max97k Max97k commented Jun 22, 2026

Copy link
Copy Markdown
Owner

🎯 What: Missing tests for the reactivity (Flow combination) of GetDashboardStatsUseCase, as well as an edge case handling unknown target currencies.
📊 Coverage: The test suite now covers reactive emissions when underlying data (holdings, selected currency, or exchange rate) is updated. It also covers the edge case where the exchange rate is completely ignored for unknown target currencies (e.g., USD to EUR conversion attempt).
Result: Improved overall test coverage and verified that dynamic inputs properly recalculate the DashboardStats state in real time.


PR created automatically by Jules for task 12347842984059675557 started by @Max97k

Added unit tests to GetDashboardStatsUseCaseTest to verify the reactive
nature of the Flow combination (holdings, selected currency, and exchange rate updates).
Also added a test for the fallback conversion case where target currency
is neither USD nor TWD.

Refactored FakeHoldingRepository slightly to accept a Flow to allow dynamic
updates in tests.

Co-authored-by: Max97k <14903047+Max97k@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds new unit tests to GetDashboardStatsUseCaseTest.kt to verify that the dashboard stats use case correctly reacts to updates in currency, exchange rates, and holdings, as well as handling unknown target currencies. The review feedback suggests improving the robustness of these reactivity tests by asserting intermediate states and the exact number of emissions instead of only asserting the final state.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +238 to +248
// Initial state
assertEquals(1600.0, results.last().totalValue, 0.0)

// Update currency and exchange rate
currencyFlow.value = "TWD"
exchangeRateFlow.value = 30.0f

// Should emit new stats reflecting the new currency and rate
assertEquals(48000.0, results.last().totalValue, 0.0)

job.cancel()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To make the reactivity test more robust and prevent false positives, we should assert the intermediate states and the exact number of emissions. Currently, if selectedCurrencyFlow updates did not trigger emissions but exchangeRateFlow updates did, the test would still pass because it only asserts results.last() at the very end. Asserting the list size and values after each individual update ensures both flows are independently reactive.

        // Initial state
        assertEquals(1, results.size)
        assertEquals(1600.0, results[0].totalValue, 0.0)

        // Update currency
        currencyFlow.value = "TWD"
        assertEquals(2, results.size)
        assertEquals(1600.0, results[1].totalValue, 0.0)

        // Update exchange rate
        exchangeRateFlow.value = 30.0f
        assertEquals(3, results.size)
        assertEquals(48000.0, results[2].totalValue, 0.0)

Comment on lines +273 to +283
// Initial state
assertEquals(1600.0, results.last().totalValue, 0.0)

// Update holdings
val holding2 = holding.copy(currentPrice = 170.0)
holdingsFlow.value = listOf(holding2)

// Should emit new stats reflecting the updated holding
assertEquals(1700.0, results.last().totalValue, 0.0)

job.cancel()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the currency reactivity test, asserting the intermediate states and the exact number of emissions makes the test more robust and ensures that the flow reacts to the holdings update correctly without relying on results.last().

Suggested change
// Initial state
assertEquals(1600.0, results.last().totalValue, 0.0)
// Update holdings
val holding2 = holding.copy(currentPrice = 170.0)
holdingsFlow.value = listOf(holding2)
// Should emit new stats reflecting the updated holding
assertEquals(1700.0, results.last().totalValue, 0.0)
job.cancel()
// Initial state
assertEquals(1, results.size)
assertEquals(1600.0, results[0].totalValue, 0.0)
// Update holdings
val holding2 = holding.copy(currentPrice = 170.0)
holdingsFlow.value = listOf(holding2)
// Should emit new stats reflecting the updated holding
assertEquals(2, results.size)
assertEquals(1700.0, results[1].totalValue, 0.0)

@Max97k Max97k merged commit bc25b4c into main Jun 23, 2026
1 check passed
@Max97k Max97k deleted the testing-improvement-dashboard-stats-12347842984059675557 branch June 23, 2026 04:40
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.

1 participant