Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Dec 23, 2024
1 parent 669a269 commit 75ea1df
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ fun ChangelogScreen(
.fillMaxWidth()
.drawVerticalScrollbar(
scrollState,
MaterialTheme.colorScheme.onSurface.copy(alpha = AlphaScrollbar)
MaterialTheme.colorScheme.onSurface.copy(alpha = AlphaScrollbar),
)
.verticalScroll(scrollState)
,
.verticalScroll(scrollState),
verticalArrangement = Arrangement.spacedBy(Dimens.mediumPadding),
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ val uiModule = module {
single { androidContext().assets }
single { androidContext().contentResolver }

single { ChangelogRepository(get(), get(), get(), MainScope()) }
single { ChangelogRepository(get(), get(), get()) }
single { UserPreferencesRepository(get(), get()) }
single { SettingsRepository(get()) }
single { MullvadProblemReport(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.mullvad.mullvadvpn.repository

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
Expand All @@ -16,15 +18,19 @@ class ChangelogRepository(
private val dataProvider: IChangelogDataProvider,
private val userPreferencesRepository: UserPreferencesRepository,
private val buildVersion: BuildVersion,
scope: CoroutineScope,
dispatcher: CoroutineDispatcher = Dispatchers.IO,
) {
val hasUnreadChangelog: StateFlow<Boolean> =
userPreferencesRepository.preferencesFlow
.map {
getLastVersionChanges().isNotEmpty() &&
buildVersion.code > it.versionCodeForLatestShownChangelogNotification
}
.stateIn(scope, started = SharingStarted.Eagerly, initialValue = false)
.stateIn(
CoroutineScope(dispatcher),
started = SharingStarted.Eagerly,
initialValue = false,
)

suspend fun setDismissNewChangelogNotification() {
userPreferencesRepository.setHasDisplayedChangelogNotification()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ package net.mullvad.mullvadvpn.repository

import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import net.mullvad.mullvadvpn.lib.common.test.assertLists
import net.mullvad.mullvadvpn.util.IChangelogDataProvider
import org.junit.jupiter.api.Test

@ExperimentalCoroutinesApi
class ChangelogRepositoryTest {

private val mockDataProvider: IChangelogDataProvider = mockk()

private val changelogRepository = ChangelogRepository(dataProvider = mockDataProvider)
private val changelogRepository =
ChangelogRepository(
mockDataProvider,
mockk(relaxed = true),
mockk(),
UnconfinedTestDispatcher(),
)

@Test
fun `when given a changelog text should return a list of correctly formatted strings`() {
Expand Down

0 comments on commit 75ea1df

Please sign in to comment.