-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'report-a-problem-input-not-kept-across-navigation-droid…
…-508'
- Loading branch information
Showing
7 changed files
with
139 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/ProblemReportRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.mullvad.mullvadvpn.repository | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import net.mullvad.mullvadvpn.dataproxy.UserReport | ||
|
||
class ProblemReportRepository { | ||
private val _problemReport = MutableStateFlow(UserReport("", "")) | ||
val problemReport: StateFlow<UserReport> = _problemReport.asStateFlow() | ||
|
||
fun setEmail(email: String) { | ||
_problemReport.value = _problemReport.value.copy(email = email) | ||
} | ||
|
||
fun setDescription(description: String) { | ||
_problemReport.value = _problemReport.value.copy(description = description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ import app.cash.turbine.test | |
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.verify | ||
import kotlin.test.assertEquals | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.test.runTest | ||
import net.mullvad.mullvadvpn.dataproxy.MullvadProblemReport | ||
import net.mullvad.mullvadvpn.dataproxy.SendProblemReportResult | ||
import net.mullvad.mullvadvpn.dataproxy.UserReport | ||
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule | ||
import net.mullvad.mullvadvpn.repository.ProblemReportRepository | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
|
@@ -20,14 +24,18 @@ class ReportProblemModelTest { | |
@get:Rule val testCoroutineRule = TestCoroutineRule() | ||
|
||
@MockK private lateinit var mockMullvadProblemReport: MullvadProblemReport | ||
@MockK(relaxed = true) private lateinit var mockProblemReportRepository: ProblemReportRepository | ||
|
||
private val problemReportFlow = MutableStateFlow(UserReport("", "")) | ||
|
||
private lateinit var viewModel: ReportProblemViewModel | ||
|
||
@Before | ||
fun setUp() { | ||
MockKAnnotations.init(this) | ||
coEvery { mockMullvadProblemReport.collectLogs() } returns true | ||
viewModel = ReportProblemViewModel(mockMullvadProblemReport) | ||
coEvery { mockProblemReportRepository.problemReport } returns problemReportFlow | ||
viewModel = ReportProblemViewModel(mockMullvadProblemReport, mockProblemReportRepository) | ||
} | ||
|
||
@After | ||
|
@@ -114,4 +122,43 @@ class ReportProblemModelTest { | |
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testUpdateEmail() = runTest { | ||
// Arrange | ||
val email = "[email protected]" | ||
|
||
// Act | ||
viewModel.updateEmail(email) | ||
|
||
// Assert | ||
verify { mockProblemReportRepository.setEmail(email) } | ||
} | ||
|
||
@Test | ||
fun testUpdateDescription() = runTest { | ||
// Arrange | ||
val description = "My description" | ||
|
||
// Act | ||
viewModel.updateDescription(description) | ||
|
||
// Assert | ||
verify { mockProblemReportRepository.setDescription(description) } | ||
} | ||
|
||
@Test | ||
fun testUpdateProblemReport() = runTest { | ||
// Arrange | ||
val userReport = UserReport("[email protected]", "My description") | ||
|
||
// Act, Assert | ||
viewModel.uiState.test { | ||
awaitItem() | ||
problemReportFlow.value = userReport | ||
val result = awaitItem() | ||
assertEquals(userReport.email, result.email) | ||
assertEquals(userReport.description, result.description) | ||
} | ||
} | ||
} |