Hide set button when disabled

This commit is contained in:
andrew 2023-09-21 00:27:10 +09:30
parent 7738b19760
commit c492a74014
3 changed files with 58 additions and 14 deletions

View File

@ -67,7 +67,7 @@ fun DisappearingMessages(
} }
} }
OutlineButton( if (state.showSetButton) OutlineButton(
stringResource(R.string.expiration_settings_set_button_title), stringResource(R.string.expiration_settings_set_button_title),
modifier = Modifier modifier = Modifier
.align(Alignment.CenterHorizontally) .align(Alignment.CenterHorizontally)

View File

@ -182,17 +182,27 @@ class ExpirationSettingsViewModel(
data class UiState( data class UiState(
val cards: List<CardModel> = emptyList(), val cards: List<CardModel> = emptyList(),
val showGroupFooter: Boolean = false val showGroupFooter: Boolean = false,
val showSetButton: Boolean = true
) { ) {
constructor(state: State): this( constructor(state: State): this(
cards = listOfNotNull( cards = listOfNotNull(
typeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_delete_type), it) }, typeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_delete_type), it) },
timeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_timer), it) } timeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_timer), it) }
), ),
showGroupFooter = state.isGroup && state.isNewConfigEnabled showGroupFooter = state.isGroup && state.isNewConfigEnabled,
showSetButton = state.isSelfAdmin
) )
constructor(showGroupFooter: Boolean, vararg cards: CardModel): this(cards.asList(), showGroupFooter) constructor(
vararg cards: CardModel,
showGroupFooter: Boolean = false,
showSetButton: Boolean = true,
): this(
cards.asList(),
showGroupFooter,
showSetButton
)
} }
data class CardModel( data class CardModel(

View File

@ -83,7 +83,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_timer, R.string.activity_expiration_settings_timer,
typeOption(ExpiryMode.NONE, selected = true), typeOption(ExpiryMode.NONE, selected = true),
@ -123,7 +122,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_timer, R.string.activity_expiration_settings_timer,
typeOption(ExpiryMode.NONE, selected = true), typeOption(ExpiryMode.NONE, selected = true),
@ -136,6 +134,47 @@ class ExpirationSettingsViewModelTest {
) )
} }
@Test
fun `group, off, admin, new config`() = runTest {
mockGroup(ExpiryMode.NONE)
val viewModel = createViewModel()
advanceUntilIdle()
assertThat(
viewModel.state.value
).isEqualTo(
State(
isGroup = true,
isSelfAdmin = false,
address = GROUP_ADDRESS,
isNoteToSelf = false,
expiryMode = ExpiryMode.NONE,
isNewConfigEnabled = true,
persistedMode = ExpiryMode.NONE,
showDebugOptions = false
)
)
assertThat(
viewModel.uiState.value
).isEqualTo(
UiState(
CardModel(
R.string.activity_expiration_settings_timer,
typeOption(ExpiryMode.NONE, enabled = false, selected = true),
timeOption(ExpiryType.AFTER_SEND, 12.hours, enabled = false),
timeOption(ExpiryType.AFTER_SEND, 1.days, enabled = false),
timeOption(ExpiryType.AFTER_SEND, 7.days, enabled = false),
timeOption(ExpiryType.AFTER_SEND, 14.days, enabled = false)
),
showGroupFooter = true,
showSetButton = false
)
)
}
@Test @Test
fun `group, off, not admin, new config`() = runTest { fun `group, off, not admin, new config`() = runTest {
mockGroup(ExpiryMode.NONE) mockGroup(ExpiryMode.NONE)
@ -163,7 +202,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = true,
CardModel( CardModel(
R.string.activity_expiration_settings_timer, R.string.activity_expiration_settings_timer,
typeOption(ExpiryMode.NONE, enabled = false, selected = true), typeOption(ExpiryMode.NONE, enabled = false, selected = true),
@ -171,7 +209,9 @@ class ExpirationSettingsViewModelTest {
timeOption(ExpiryType.AFTER_SEND, 1.days, enabled = false), timeOption(ExpiryType.AFTER_SEND, 1.days, enabled = false),
timeOption(ExpiryType.AFTER_SEND, 7.days, enabled = false), timeOption(ExpiryType.AFTER_SEND, 7.days, enabled = false),
timeOption(ExpiryType.AFTER_SEND, 14.days, enabled = false) timeOption(ExpiryType.AFTER_SEND, 14.days, enabled = false)
) ),
showGroupFooter = true,
showSetButton = false,
) )
) )
} }
@ -204,7 +244,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE, selected = true), typeOption(ExpiryMode.NONE, selected = true),
@ -244,7 +283,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE), typeOption(ExpiryMode.NONE),
@ -291,7 +329,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE), typeOption(ExpiryMode.NONE),
@ -339,7 +376,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE), typeOption(ExpiryMode.NONE),
@ -387,7 +423,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE), typeOption(ExpiryMode.NONE),
@ -441,7 +476,6 @@ class ExpirationSettingsViewModelTest {
viewModel.uiState.value viewModel.uiState.value
).isEqualTo( ).isEqualTo(
UiState( UiState(
showGroupFooter = false,
CardModel( CardModel(
R.string.activity_expiration_settings_delete_type, R.string.activity_expiration_settings_delete_type,
typeOption(ExpiryMode.NONE), typeOption(ExpiryMode.NONE),