Change AccountOAuthScreen()
to AccountOAuthView()
This commit is contained in:
parent
cb6520efd2
commit
6ff458da6c
6 changed files with 49 additions and 147 deletions
|
@ -1,7 +1,6 @@
|
|||
package app.k9mail.feature.account.oauth.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -24,7 +23,6 @@ import app.k9mail.feature.account.oauth.ui.item.SignInItem
|
|||
internal fun AccountOAuthContent(
|
||||
state: State,
|
||||
onEvent: (Event) -> Unit,
|
||||
contentPadding: PaddingValues,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val resources = LocalContext.current.resources
|
||||
|
@ -33,7 +31,6 @@ internal fun AccountOAuthContent(
|
|||
modifier = Modifier
|
||||
.testTag("AccountOAuthContent")
|
||||
.then(modifier),
|
||||
contentPadding = contentPadding,
|
||||
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double, Alignment.CenterVertically),
|
||||
) {
|
||||
if (state.isLoading) {
|
||||
|
@ -53,7 +50,6 @@ internal fun AccountOAuthContent(
|
|||
} else {
|
||||
item(key = "sign_in") {
|
||||
SignInItem(
|
||||
emailAddress = state.emailAddress,
|
||||
onSignInClick = { onEvent(Event.SignInClicked) },
|
||||
isGoogleSignIn = state.isGoogleSignIn,
|
||||
)
|
||||
|
@ -69,7 +65,6 @@ internal fun AccountOAuthContentK9Preview() {
|
|||
AccountOAuthContent(
|
||||
state = State(),
|
||||
onEvent = {},
|
||||
contentPadding = PaddingValues(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +76,6 @@ internal fun AccountOAuthContentThunderbirdPreview() {
|
|||
AccountOAuthContent(
|
||||
state = State(),
|
||||
onEvent = {},
|
||||
contentPadding = PaddingValues(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
package app.k9mail.feature.account.oauth.ui
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import app.k9mail.core.ui.compose.common.mvi.observe
|
||||
import app.k9mail.core.ui.compose.designsystem.template.Scaffold
|
||||
import app.k9mail.feature.account.common.ui.AppTitleTopHeader
|
||||
import app.k9mail.feature.account.common.ui.WizardNavigationBar
|
||||
import app.k9mail.feature.account.oauth.R
|
||||
import app.k9mail.feature.account.oauth.domain.entity.OAuthResult
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Effect
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Event
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.ViewModel
|
||||
|
||||
@Composable
|
||||
fun AccountOAuthScreen(
|
||||
fun AccountOAuthView(
|
||||
onOAuthResult: (OAuthResult) -> Unit,
|
||||
viewModel: ViewModel,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -36,29 +30,9 @@ fun AccountOAuthScreen(
|
|||
}
|
||||
}
|
||||
|
||||
BackHandler {
|
||||
dispatch(Event.OnBackClicked)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppTitleTopHeader(stringResource(id = R.string.account_oauth_title))
|
||||
},
|
||||
bottomBar = {
|
||||
WizardNavigationBar(
|
||||
state = state.value.wizardNavigationBarState,
|
||||
nextButtonText = stringResource(id = R.string.account_oauth_button_next),
|
||||
backButtonText = stringResource(id = R.string.account_oauth_button_back),
|
||||
onNextClick = { },
|
||||
onBackClick = { dispatch(Event.OnBackClicked) },
|
||||
)
|
||||
},
|
||||
AccountOAuthContent(
|
||||
state = state.value,
|
||||
onEvent = { dispatch(it) },
|
||||
modifier = modifier,
|
||||
) { innerPadding ->
|
||||
AccountOAuthContent(
|
||||
state = state.value,
|
||||
onEvent = { dispatch(it) },
|
||||
contentPadding = innerPadding,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
|
@ -8,7 +8,6 @@ import app.k9mail.feature.account.oauth.ui.view.SignInView
|
|||
|
||||
@Composable
|
||||
internal fun LazyItemScope.SignInItem(
|
||||
emailAddress: String,
|
||||
onSignInClick: () -> Unit,
|
||||
isGoogleSignIn: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -17,7 +16,6 @@ internal fun LazyItemScope.SignInItem(
|
|||
modifier = modifier,
|
||||
) {
|
||||
SignInView(
|
||||
emailAddress = emailAddress,
|
||||
onSignInClick = onSignInClick,
|
||||
isGoogleSignIn = isGoogleSignIn,
|
||||
)
|
||||
|
|
|
@ -10,14 +10,11 @@ import androidx.compose.ui.text.style.TextAlign
|
|||
import app.k9mail.core.ui.compose.common.DevicePreviews
|
||||
import app.k9mail.core.ui.compose.designsystem.atom.button.Button
|
||||
import app.k9mail.core.ui.compose.designsystem.atom.text.TextCaption
|
||||
import app.k9mail.core.ui.compose.designsystem.atom.text.TextSubtitle1
|
||||
import app.k9mail.core.ui.compose.designsystem.molecule.input.EmailAddressInput
|
||||
import app.k9mail.core.ui.compose.theme.MainTheme
|
||||
import app.k9mail.feature.account.oauth.R
|
||||
|
||||
@Composable
|
||||
internal fun SignInView(
|
||||
emailAddress: String,
|
||||
onSignInClick: () -> Unit,
|
||||
isGoogleSignIn: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -27,14 +24,6 @@ internal fun SignInView(
|
|||
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double),
|
||||
modifier = modifier,
|
||||
) {
|
||||
TextSubtitle1(text = stringResource(id = R.string.account_oauth_sign_in_title))
|
||||
|
||||
EmailAddressInput(
|
||||
emailAddress = emailAddress,
|
||||
onEmailAddressChange = {},
|
||||
isEnabled = false,
|
||||
)
|
||||
|
||||
TextCaption(
|
||||
text = stringResource(id = R.string.account_oauth_sign_in_description),
|
||||
textAlign = TextAlign.Center,
|
||||
|
@ -57,7 +46,6 @@ internal fun SignInView(
|
|||
@Composable
|
||||
internal fun SignInViewPreview() {
|
||||
SignInView(
|
||||
emailAddress = "test@example.com",
|
||||
onSignInClick = {},
|
||||
isGoogleSignIn = false,
|
||||
)
|
||||
|
@ -67,7 +55,6 @@ internal fun SignInViewPreview() {
|
|||
@Composable
|
||||
internal fun SignInViewWithGooglePreview() {
|
||||
SignInView(
|
||||
emailAddress = "test@gmail.com",
|
||||
onSignInClick = {},
|
||||
isGoogleSignIn = true,
|
||||
)
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
package app.k9mail.feature.account.oauth.ui
|
||||
|
||||
import androidx.compose.ui.test.assertIsEnabled
|
||||
import androidx.compose.ui.test.assertIsNotEnabled
|
||||
import app.k9mail.core.ui.compose.testing.ComposeTest
|
||||
import app.k9mail.core.ui.compose.testing.onNodeWithTextIgnoreCase
|
||||
import app.k9mail.core.ui.compose.testing.setContent
|
||||
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
|
||||
import app.k9mail.feature.account.common.ui.WizardNavigationBarState
|
||||
import app.k9mail.feature.account.oauth.R
|
||||
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.oauth.domain.entity.OAuthResult
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Effect
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.State
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isNull
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class AccountOAuthScreenKtTest : ComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `should delegate navigation effects`() = runTest {
|
||||
val initialState = State()
|
||||
val viewModel = FakeAccountOAuthViewModel(initialState)
|
||||
var oAuthResult: OAuthResult? = null
|
||||
val authorizationState = AuthorizationState()
|
||||
|
||||
setContent {
|
||||
ThunderbirdTheme {
|
||||
AccountOAuthScreen(
|
||||
onOAuthResult = { oAuthResult = it },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(oAuthResult).isNull()
|
||||
|
||||
viewModel.effect(Effect.NavigateNext(authorizationState))
|
||||
|
||||
assertThat(oAuthResult).isEqualTo(OAuthResult.Success(authorizationState))
|
||||
|
||||
viewModel.effect(Effect.NavigateBack)
|
||||
|
||||
assertThat(oAuthResult).isEqualTo(OAuthResult.Failure)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should set navigation bar enabled state`() {
|
||||
val initialState = State(
|
||||
wizardNavigationBarState = WizardNavigationBarState(
|
||||
isNextEnabled = true,
|
||||
isBackEnabled = true,
|
||||
),
|
||||
)
|
||||
val viewModel = FakeAccountOAuthViewModel(initialState)
|
||||
|
||||
setContent {
|
||||
ThunderbirdTheme {
|
||||
AccountOAuthScreen(
|
||||
onOAuthResult = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
onNodeWithTextIgnoreCase(R.string.account_oauth_button_next).assertIsEnabled()
|
||||
onNodeWithTextIgnoreCase(R.string.account_oauth_button_back).assertIsEnabled()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should set navigation bar disabled state`() {
|
||||
val initialState = State(
|
||||
wizardNavigationBarState = WizardNavigationBarState(
|
||||
isNextEnabled = false,
|
||||
isBackEnabled = false,
|
||||
),
|
||||
)
|
||||
val viewModel = FakeAccountOAuthViewModel(initialState)
|
||||
|
||||
setContent {
|
||||
ThunderbirdTheme {
|
||||
AccountOAuthScreen(
|
||||
onOAuthResult = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
onNodeWithTextIgnoreCase(R.string.account_oauth_button_next).assertIsNotEnabled()
|
||||
onNodeWithTextIgnoreCase(R.string.account_oauth_button_back).assertIsNotEnabled()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package app.k9mail.feature.account.oauth.ui
|
||||
|
||||
import app.k9mail.core.ui.compose.testing.ComposeTest
|
||||
import app.k9mail.core.ui.compose.testing.setContent
|
||||
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
|
||||
import app.k9mail.feature.account.oauth.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.oauth.domain.entity.OAuthResult
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Effect
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.State
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isNull
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class AccountOAuthViewKtTest : ComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `should delegate navigation effects`() = runTest {
|
||||
val initialState = State()
|
||||
val viewModel = FakeAccountOAuthViewModel(initialState)
|
||||
var oAuthResult: OAuthResult? = null
|
||||
val authorizationState = AuthorizationState()
|
||||
|
||||
setContent {
|
||||
ThunderbirdTheme {
|
||||
AccountOAuthView(
|
||||
onOAuthResult = { oAuthResult = it },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(oAuthResult).isNull()
|
||||
|
||||
viewModel.effect(Effect.NavigateNext(authorizationState))
|
||||
|
||||
assertThat(oAuthResult).isEqualTo(OAuthResult.Success(authorizationState))
|
||||
|
||||
viewModel.effect(Effect.NavigateBack)
|
||||
|
||||
assertThat(oAuthResult).isEqualTo(OAuthResult.Failure)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue