Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Aug 15, 2024
1 parent 47b38c9 commit 5a59129
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ import kotlin.test.assertEquals
import kotlinx.coroutines.test.runTest
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.lib.model.BuildVersion
import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.repository.ChangelogRepository
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(TestCoroutineRule::class)
class ChangelogViewModelTest {
class MullvadAppViewModelTest {

@MockK private lateinit var mockedChangelogRepository: ChangelogRepository
@MockK private lateinit var connectionProxy: ConnectionProxy

private lateinit var viewModel: ChangelogViewModel
private lateinit var viewModel: MullvadAppViewModel

private val buildVersion = BuildVersion("1.0", 10)

Expand All @@ -43,7 +45,8 @@ class ChangelogViewModelTest {
// Arrange
every { mockedChangelogRepository.getVersionCodeOfMostRecentChangelogShowed() } returns
buildVersion.code
viewModel = ChangelogViewModel(mockedChangelogRepository, buildVersion, false)
viewModel =
MullvadAppViewModel(mockedChangelogRepository, connectionProxy, buildVersion, false)

// If we have the most up to date version code, we should not show the changelog dialog
viewModel.uiSideEffect.test { expectNoEvents() }
Expand All @@ -58,7 +61,8 @@ class ChangelogViewModelTest {
version
every { mockedChangelogRepository.getLastVersionChanges() } returns changes

viewModel = ChangelogViewModel(mockedChangelogRepository, buildVersion, false)
viewModel =
MullvadAppViewModel(mockedChangelogRepository, connectionProxy, buildVersion, false)
// Given a new version with a change log we should return it
viewModel.uiSideEffect.test {
assertEquals(awaitItem(), Changelog(version = buildVersion.name, changes = changes))
Expand All @@ -71,7 +75,8 @@ class ChangelogViewModelTest {
every { mockedChangelogRepository.getVersionCodeOfMostRecentChangelogShowed() } returns -1
every { mockedChangelogRepository.getLastVersionChanges() } returns emptyList()

viewModel = ChangelogViewModel(mockedChangelogRepository, buildVersion, false)
viewModel =
MullvadAppViewModel(mockedChangelogRepository, connectionProxy, buildVersion, false)
// Given a new version with a change log we should not return it
viewModel.uiSideEffect.test { expectNoEvents() }
}
Expand Down

0 comments on commit 5a59129

Please sign in to comment.