Skip to content

refactor: improve testability and prevent film repetition on reroll - #66

Merged
Nacchofer31 merged 3 commits into
masterfrom
fix/refactor-film-extraction
Jul 29, 2026
Merged

refactor: improve testability and prevent film repetition on reroll#66
Nacchofer31 merged 3 commits into
masterfrom
fix/refactor-film-extraction

Conversation

@Nacchofer31

Copy link
Copy Markdown
Owner

This PR improves the RandomFilm feature's testability by using injected dispatchers instead of hardcoded Dispatchers.IO, and prevents the same film from being shown consecutively when using the reroll feature.

  • Added randomExcluding extension function for Set that returns a random element while excluding a specific element using a key selector for comparison
  • Includes comprehensive unit tests covering edge cases (empty set, null exclude, single element, key-based comparison)
    RandomFilm Feature
  • Replaced hardcoded Dispatchers.IO with injected DispatcherProvider for better testability
  • Wrapped repository calls in withContext(dispatchers.io) to ensure proper dispatcher usage
  • Implemented film repetition prevention using randomExcluding with name as the comparison key
  • Reroll button now only appears when numberOfResults > 1
    Tests
  • Fixed reroll button test by passing numberOfResults parameter
  • Added animation completion test for LoadingOrPrompt to improve code coverage

Add utility function to get a random element from a set while
excluding a specific element using a key selector for comparison.
Includes comprehensive unit tests.
…petition

Replace hardcoded Dispatchers.IO with injected DispatcherProvider for
better testability. Use randomExcluding to avoid showing the same film
on reroll. Wrap repository calls in withContext(dispatchers.io).
Conditionally show reroll button only when numberOfResults > 1.
Fix reroll button test by passing numberOfResults parameter.
Add test to verify loading animation completes full cycle for
better code coverage.
@Nacchofer31 Nacchofer31 self-assigned this Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...film/presentation/viewmodel/RandomFilmViewModel.kt 93.33% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Nacchofer31
Nacchofer31 merged commit 29c5e8a into master Jul 29, 2026
7 checks passed
@Nacchofer31
Nacchofer31 deleted the fix/refactor-film-extraction branch July 29, 2026 15:08
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