Used fixed timezome to fix failing Password History test (#943)

This commit is contained in:
Brian Yencho 2024-02-01 12:24:22 -06:00 committed by Álison Fernandes
parent 8156e306f5
commit a8f24f5f55

View file

@ -22,10 +22,13 @@ import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Instant
import java.util.TimeZone
class PasswordHistoryViewModelTest : BaseViewModelTest() {
@ -38,6 +41,16 @@ class PasswordHistoryViewModelTest : BaseViewModelTest() {
every { getVaultItemStateFlow("mockId-1") } returns mutableVaultItemFlow
}
@BeforeEach
fun setUp() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
}
@AfterEach
fun tearDown() {
TimeZone.setDefault(null)
}
@Test
fun `initial state should be correct`() = runTest {
val viewModel = createViewModel()
@ -67,9 +80,9 @@ class PasswordHistoryViewModelTest : BaseViewModelTest() {
viewModel.stateFlow.test {
val expectedState = createPasswordHistoryState(
viewState = PasswordHistoryState.ViewState.Error(
message = R.string.an_error_has_occurred.asText(),
),
viewState = PasswordHistoryState.ViewState.Error(
message = R.string.an_error_has_occurred.asText(),
),
)
val actualState = awaitItem()
assertEquals(expectedState, actualState)
@ -162,7 +175,7 @@ class PasswordHistoryViewModelTest : BaseViewModelTest() {
passwords = listOf(
PasswordHistoryState.GeneratedPassword(
password = "mockPassword-1",
date = "10/27/23 6:00 AM",
date = "10/27/23 12:00 PM",
),
),
),