mirror of
https://github.com/bitwarden/android.git
synced 2026-06-02 10:56:56 -05:00
BIT-484: Add deletion date and time pickers (#548)
This commit is contained in:
@@ -30,7 +30,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
class AddSendScreenTest : BaseComposeTest() {
|
||||
|
||||
@@ -604,7 +604,7 @@ class AddSendScreenTest : BaseComposeTest() {
|
||||
noteInput = "",
|
||||
isHideEmailChecked = false,
|
||||
isDeactivateChecked = false,
|
||||
deletionDate = Instant.parse("2023-10-27T12:00:00Z"),
|
||||
deletionDate = ZonedDateTime.parse("2023-10-27T12:00:00Z"),
|
||||
expirationDate = null,
|
||||
)
|
||||
|
||||
|
||||
@@ -28,13 +28,14 @@ import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.util.TimeZone
|
||||
import java.time.ZoneOffset
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
class AddSendViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val clock = Clock.fixed(
|
||||
Instant.parse("2023-10-27T12:00:00Z"),
|
||||
TimeZone.getTimeZone("UTC").toZoneId(),
|
||||
ZoneOffset.UTC,
|
||||
)
|
||||
private val mutableUserStateFlow = MutableStateFlow<UserState?>(DEFAULT_USER_STATE)
|
||||
private val authRepository: AuthRepository = mockk {
|
||||
@@ -89,7 +90,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val initialState = DEFAULT_STATE.copy(viewState = viewState)
|
||||
val mockSendView = mockk<SendView>()
|
||||
every { viewState.toSendView() } returns mockSendView
|
||||
every { viewState.toSendView(clock) } returns mockSendView
|
||||
val sendUrl = "www.test.com/send/test"
|
||||
val resultSendView = mockk<SendView> {
|
||||
every { toSendUrl(DEFAULT_ENVIRONMENT_URL) } returns sendUrl
|
||||
@@ -117,7 +118,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val initialState = DEFAULT_STATE.copy(viewState = viewState)
|
||||
val mockSendView = mockk<SendView>()
|
||||
every { viewState.toSendView() } returns mockSendView
|
||||
every { viewState.toSendView(clock) } returns mockSendView
|
||||
coEvery { vaultRepository.createSend(mockSendView) } returns CreateSendResult.Error
|
||||
val viewModel = createViewModel(initialState)
|
||||
|
||||
@@ -180,6 +181,27 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `DeletionDateChange should store the new deletion date`() {
|
||||
val viewModel = createViewModel()
|
||||
val newDeletionDate = ZonedDateTime.parse("2024-09-13T00:00Z")
|
||||
// DEFAULT deletion date is "2023-11-03T00:00Z"
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
|
||||
viewModel.trySendAction(AddSendAction.DeletionDateChange(newDeletionDate))
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
viewState = DEFAULT_VIEW_STATE.copy(
|
||||
common = DEFAULT_COMMON_STATE.copy(
|
||||
deletionDate = newDeletionDate,
|
||||
),
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ChooseFileClick should emit ShowToast`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
@@ -353,7 +375,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
noteInput = "",
|
||||
isHideEmailChecked = false,
|
||||
isDeactivateChecked = false,
|
||||
deletionDate = Instant.parse("2023-11-03T12:00:00Z"),
|
||||
deletionDate = ZonedDateTime.parse("2023-11-03T00:00Z"),
|
||||
expirationDate = null,
|
||||
)
|
||||
|
||||
|
||||
@@ -4,24 +4,15 @@ import com.bitwarden.core.SendFileView
|
||||
import com.bitwarden.core.SendType
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.addsend.AddSendState
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.ZoneOffset
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
class AddSendStateExtensionsTest {
|
||||
|
||||
private val fixedInstant: Instant = Instant.parse("2023-10-27T12:00:00Z")
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
// Some individual tests call mockkStatic so we will make sure this is always undone.
|
||||
unmockkStatic(Instant::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toSendView should create an appropriate SendView with file type`() {
|
||||
val sendView = createMockSendView(number = 1, type = SendType.FILE).copy(
|
||||
@@ -37,12 +28,10 @@ class AddSendStateExtensionsTest {
|
||||
sizeName = "",
|
||||
),
|
||||
)
|
||||
mockkStatic(Instant::class)
|
||||
every { Instant.now() } returns fixedInstant
|
||||
|
||||
val result = DEFAULT_VIEW_STATE
|
||||
.copy(selectedType = AddSendState.ViewState.Content.SendType.File)
|
||||
.toSendView()
|
||||
.toSendView(FIXED_CLOCK)
|
||||
|
||||
assertEquals(sendView, result)
|
||||
}
|
||||
@@ -56,34 +45,35 @@ class AddSendStateExtensionsTest {
|
||||
accessCount = 0U,
|
||||
file = null,
|
||||
)
|
||||
mockkStatic(Instant::class)
|
||||
every { Instant.now() } returns fixedInstant
|
||||
|
||||
val result = DEFAULT_VIEW_STATE.toSendView()
|
||||
val result = DEFAULT_VIEW_STATE.toSendView(FIXED_CLOCK)
|
||||
|
||||
assertEquals(sendView, result)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DEFAULT_COMMON_STATE = AddSendState.ViewState.Content.Common(
|
||||
name = "mockName-1",
|
||||
maxAccessCount = 1,
|
||||
passwordInput = "mockPassword-1",
|
||||
noteInput = "mockNotes-1",
|
||||
isHideEmailChecked = false,
|
||||
isDeactivateChecked = false,
|
||||
deletionDate = Instant.parse("2023-10-27T12:00:00Z"),
|
||||
expirationDate = Instant.parse("2023-10-27T12:00:00Z"),
|
||||
)
|
||||
|
||||
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(
|
||||
input = "mockText-1",
|
||||
isHideByDefaultChecked = false,
|
||||
)
|
||||
|
||||
private val DEFAULT_VIEW_STATE = AddSendState.ViewState.Content(
|
||||
common = DEFAULT_COMMON_STATE,
|
||||
selectedType = DEFAULT_SELECTED_TYPE_STATE,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val FIXED_CLOCK: Clock = Clock.fixed(
|
||||
Instant.parse("2023-10-27T12:00:00Z"),
|
||||
ZoneOffset.UTC,
|
||||
)
|
||||
|
||||
private val DEFAULT_COMMON_STATE = AddSendState.ViewState.Content.Common(
|
||||
name = "mockName-1",
|
||||
maxAccessCount = 1,
|
||||
passwordInput = "mockPassword-1",
|
||||
noteInput = "mockNotes-1",
|
||||
isHideEmailChecked = false,
|
||||
isDeactivateChecked = false,
|
||||
deletionDate = ZonedDateTime.parse("2023-10-27T12:00:00Z"),
|
||||
expirationDate = ZonedDateTime.parse("2023-10-27T12:00:00Z"),
|
||||
)
|
||||
|
||||
private val DEFAULT_SELECTED_TYPE_STATE = AddSendState.ViewState.Content.SendType.Text(
|
||||
input = "mockText-1",
|
||||
isHideByDefaultChecked = false,
|
||||
)
|
||||
|
||||
private val DEFAULT_VIEW_STATE = AddSendState.ViewState.Content(
|
||||
common = DEFAULT_COMMON_STATE,
|
||||
selectedType = DEFAULT_SELECTED_TYPE_STATE,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user