Skip to content

🧪 test(settings): add missing tests for SettingsViewModel - #33

Open
SayanthRock wants to merge 1 commit into
mainfrom
test-settings-viewmodel-16912416769073291753
Open

🧪 test(settings): add missing tests for SettingsViewModel#33
SayanthRock wants to merge 1 commit into
mainfrom
test-settings-viewmodel-16912416769073291753

Conversation

@SayanthRock

@SayanthRock SayanthRock commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

User description

🎯 What: Added missing unit tests for SettingsViewModel in the feature-settings module.
📊 Coverage: Tests check the initial state of the SettingsState and the toggle behavior of isDarkMode state flow values.
Result: Enhanced module test coverage and guarantees behavior verification of the SettingsViewModel.


PR created automatically by Jules for task 16912416769073291753 started by @SayanthRock


CodeAnt-AI Description

Add coverage for SettingsViewModel dark mode behavior

What Changed

  • Added tests confirming settings start with dark mode enabled
  • Added tests confirming dark mode toggles off and back on correctly
  • Added the test dependencies needed to run these checks

Impact

✅ Verified default dark mode state
✅ Verified dark mode toggle behavior
✅ Fewer regressions in settings

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Tests
    • Added automated coverage for the settings view model’s initial dark mode state.
    • Verified that toggling dark mode updates the setting correctly in both directions.

Co-authored-by: SayanthRock <202829406+SayanthRock@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.

@codeant-ai

codeant-ai Bot commented Jul 27, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 242fcd9 Jul 27, 2026 · 10:36 10:38

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Jul 27, 2026

@ai-coding-guardrails ai-coding-guardrails 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.

Nice work! 😎

I didn't find anything of concern

Risk: 🟢 Low

Risk analysis

This PR adds unit tests for the SettingsViewModel and does not introduce any changes to production code or dependencies. As such, it has no forward-looking impact on security, data integrity, blast radius, reversibility, operational risk, or existing test coverage.

Did you know Zenable also supports GitLab SaaS and self-managed?

@ai-coding-guardrails ai-coding-guardrails Bot added the zenable/risk:low Zenable assessed this PR as LOW risk. label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a95c2f61-570e-4206-861e-5857b5ca8222

📥 Commits

Reviewing files that changed from the base of the PR and between 3cbe00a and 242fcd9.

📒 Files selected for processing (2)
  • feature-settings/build.gradle.kts
  • feature-settings/src/test/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModelTest.kt

📝 Walkthrough

Walkthrough

The settings feature adds JUnit and coroutine test dependencies and introduces SettingsViewModelTest, covering the initial dark-mode state and repeated toggleDarkMode() transitions.

Changes

Settings ViewModel tests

Layer / File(s) Summary
Settings state and toggle tests
feature-settings/build.gradle.kts, feature-settings/src/test/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModelTest.kt
Adds JUnit and coroutine test dependencies, then verifies the initial dark-mode state and transitions from enabled to disabled and back.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding missing tests for SettingsViewModel in the settings module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-settings-viewmodel-16912416769073291753

Comment @coderabbitai help to get the list of available commands.

Comment on lines +9 to +13
fun `initial state is Success with isDarkMode true`() {
val viewModel = SettingsViewModel()
val currentState = viewModel.uiState.value

assertEquals(SettingsState.Success(isDarkMode = true), currentState)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The test only verifies the ViewModel's hardcoded initial value and does not verify that the setting is consumed by the application's theme. MainActivity currently invokes RockReleaseHubTheme without passing this value, so this test can remain green while the rendered theme still follows the system setting instead of the settings screen's default. [incomplete implementation]

Severity Level: Critical 🚨
- ❌ Settings toggle does not change application colors.
- ❌ Settings screen gives false dark-mode feedback.
- ⚠️ Theme behavior remains controlled by system appearance.
Steps of Reproduction ✅
1. Launch the application through `MainActivity.onCreate()` at
`app/src/main/java/com/sayanthrock/rockreleasehub/MainActivity.kt:11-16`; it wraps
`AppNavGraph()` in `RockReleaseHubTheme` without supplying the settings value.

2. Navigate to the Settings destination registered at
`app/src/main/java/com/sayanthrock/rockreleasehub/AppNavGraph.kt:91-93`, which renders
`SettingsScreen()`.

3. Toggle the Dark Mode switch at
`feature-settings/src/main/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsScreen.kt:28-33`;
this only calls `SettingsViewModel.toggleDarkMode()`.

4. Observe that `SettingsViewModel` changes its in-memory state at
`feature-settings/src/main/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModel.kt:15-18`,
but `RockReleaseHubTheme` still selects `darkTheme` from `isSystemInDarkTheme()` by
default at
`core-designsystem/src/main/java/com/sayanthrock/rockreleasehub/core/designsystem/theme/Theme.kt:37-49`.
The added test at lines 9-13 remains green while the rendered application theme does not
change.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** feature-settings/src/test/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModelTest.kt
**Line:** 9:13
**Comment:**
	*Incomplete Implementation: The test only verifies the ViewModel's hardcoded initial value and does not verify that the setting is consumed by the application's theme. `MainActivity` currently invokes `RockReleaseHubTheme` without passing this value, so this test can remain green while the rendered theme still follows the system setting instead of the settings screen's default.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +17 to +40
fun `toggleDarkMode changes isDarkMode from true to false`() {
val viewModel = SettingsViewModel()

// Initial state is true
assertEquals(SettingsState.Success(isDarkMode = true), viewModel.uiState.value)

// Toggle
viewModel.toggleDarkMode()

// State should now be false
assertEquals(SettingsState.Success(isDarkMode = false), viewModel.uiState.value)
}

@Test
fun `toggleDarkMode changes isDarkMode from false to true`() {
val viewModel = SettingsViewModel()

// Toggle to false
viewModel.toggleDarkMode()
assertEquals(SettingsState.Success(isDarkMode = false), viewModel.uiState.value)

// Toggle back to true
viewModel.toggleDarkMode()
assertEquals(SettingsState.Success(isDarkMode = true), viewModel.uiState.value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: These tests cover only an in-memory StateFlow transition within one ViewModel instance. They do not verify that toggling changes the actual application theme or survives ViewModel/activity recreation, so they provide false confidence for the user-visible dark-mode behavior, which is currently not connected to RockReleaseHubTheme or persisted through DataStore. [incomplete implementation]

Severity Level: Critical 🚨
- ❌ Dark-mode preference resets after ViewModel recreation.
- ❌ Process recreation loses the user's setting.
- ⚠️ Toggle tests provide incomplete feature coverage.
Steps of Reproduction ✅
1. Open the Settings screen through the route at
`app/src/main/java/com/sayanthrock/rockreleasehub/AppNavGraph.kt:92`; its switch invokes
`toggleDarkMode()` at
`feature-settings/src/main/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsScreen.kt:28-33`.

2. Toggle the switch and confirm the added tests pass because
`SettingsViewModel.toggleDarkMode()` updates only `_uiState.value` at
`feature-settings/src/main/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModel.kt:15-18`.

3. Recreate the ViewModel, such as after its owning navigation entry or process is
recreated, by constructing a new `SettingsViewModel`; its initializer at
`SettingsViewModel.kt:11-13` always restores `SettingsState.Success(isDarkMode = true)`.

4. Inspect the feature's available persistence dependency at
`feature-settings/build.gradle.kts:42` and the source usage found in the module: no
DataStore read or write is connected to this ViewModel. The tests at lines 17-40 therefore
verify only one transient instance and cannot detect loss of the user's preference or its
missing connection to `RockReleaseHubTheme`.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** feature-settings/src/test/java/com/sayanthrock/rockreleasehub/feature/settings/SettingsViewModelTest.kt
**Line:** 17:40
**Comment:**
	*Incomplete Implementation: These tests cover only an in-memory `StateFlow` transition within one ViewModel instance. They do not verify that toggling changes the actual application theme or survives ViewModel/activity recreation, so they provide false confidence for the user-visible dark-mode behavior, which is currently not connected to `RockReleaseHubTheme` or persisted through DataStore.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files zenable/risk:low Zenable assessed this PR as LOW risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant