Skip to content

Commit

Permalink
Align changelog ui state property name
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Sep 29, 2023
1 parent 29e0239 commit f9d2d87
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChangelogDialogTest {
@Test
fun testShowChangeLogWhenNeeded() {
// Arrange
every { mockedViewModel.changelogDialogUiState } returns
every { mockedViewModel.uiState } returns
MutableStateFlow(ChangelogDialogUiState.Show(listOf(CHANGELOG_ITEM)))
every { mockedViewModel.dismissChangelogDialog() } just Runs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ open class MainActivity : FragmentActivity() {
findViewById<ComposeView>(R.id.compose_view).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
setContent {
val state = changelogViewModel.changelogDialogUiState.collectAsState().value
val state = changelogViewModel.uiState.collectAsState().value
if (state is ChangelogDialogUiState.Show) {
AppTheme {
ChangelogDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ class ChangelogViewModel(
private val buildVersionCode: Int,
private val alwaysShowChangelog: Boolean
) : ViewModel() {
private val _changelogDialogUiState =
MutableStateFlow<ChangelogDialogUiState>(ChangelogDialogUiState.Hide)
val changelogDialogUiState = _changelogDialogUiState.asStateFlow()
private val _uiState = MutableStateFlow<ChangelogDialogUiState>(ChangelogDialogUiState.Hide)
val uiState = _uiState.asStateFlow()

fun refreshChangelogDialogUiState() {
val shouldShowChangelogDialog =
alwaysShowChangelog ||
changelogRepository.getVersionCodeOfMostRecentChangelogShowed() < buildVersionCode
_changelogDialogUiState.value =
_uiState.value =
if (shouldShowChangelogDialog) {
val changelogList = changelogRepository.getLastVersionChanges()
if (changelogList.isNotEmpty()) {
Expand All @@ -33,7 +32,7 @@ class ChangelogViewModel(

fun dismissChangelogDialog() {
changelogRepository.setVersionCodeOfMostRecentChangelogShowed(buildVersionCode)
_changelogDialogUiState.value = ChangelogDialogUiState.Hide
_uiState.value = ChangelogDialogUiState.Hide
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ class ChangelogViewModelTest {
@Test
fun testInitialState() = runBlockingTest {
// Arrange, Act, Assert
viewModel.changelogDialogUiState.test {
Assert.assertEquals(ChangelogDialogUiState.Hide, awaitItem())
}
viewModel.uiState.test { Assert.assertEquals(ChangelogDialogUiState.Hide, awaitItem()) }
}

@Test
fun testShowAndDismissChangelogDialog() = runBlockingTest {
viewModel.changelogDialogUiState.test {
viewModel.uiState.test {
// Arrange
val fakeList = listOf("test")
every { mockedChangelogRepository.getVersionCodeOfMostRecentChangelogShowed() } returns
Expand All @@ -70,7 +68,7 @@ class ChangelogViewModelTest {

@Test
fun testShowCaseChangelogWithEmptyListDialog() = runBlockingTest {
viewModel.changelogDialogUiState.test {
viewModel.uiState.test {
// Arrange
val fakeEmptyList = emptyList<String>()
every { mockedChangelogRepository.getVersionCodeOfMostRecentChangelogShowed() } returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class ViewModelTests {
"toastMessages",
"uiCloseAction",
"enterTransitionEndAction",
"accountToken",
"changelogDialogUiState"
"accountToken"
)
}
}

0 comments on commit f9d2d87

Please sign in to comment.