🧪 Add Reactivity and Edge Case Tests for GetDashboardStatsUseCase#43
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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.
| // 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() |
There was a problem hiding this comment.
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)| // 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() |
There was a problem hiding this comment.
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().
| // 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) |
🎯 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