Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions feature-settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ dependencies {

implementation(libs.hilt.android)
ksp(libs.hilt.compiler)

testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sayanthrock.rockreleasehub.feature.settings

import org.junit.Assert.assertEquals
import org.junit.Test

class SettingsViewModelTest {

@Test
fun `initial state is Success with isDarkMode true`() {
val viewModel = SettingsViewModel()
val currentState = viewModel.uiState.value

assertEquals(SettingsState.Success(isDarkMode = true), currentState)
Comment on lines +9 to +13

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
πŸ‘ | πŸ‘Ž

}

@Test
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)
Comment on lines +17 to +40

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
πŸ‘ | πŸ‘Ž

}
}
Loading