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
|
package app.k9mail.feature.account.oauth.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
@ -24,7 +23,6 @@ import app.k9mail.feature.account.oauth.ui.item.SignInItem
|
||||||
internal fun AccountOAuthContent(
|
internal fun AccountOAuthContent(
|
||||||
state: State,
|
state: State,
|
||||||
onEvent: (Event) -> Unit,
|
onEvent: (Event) -> Unit,
|
||||||
contentPadding: PaddingValues,
|
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val resources = LocalContext.current.resources
|
val resources = LocalContext.current.resources
|
||||||
|
@ -33,7 +31,6 @@ internal fun AccountOAuthContent(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.testTag("AccountOAuthContent")
|
.testTag("AccountOAuthContent")
|
||||||
.then(modifier),
|
.then(modifier),
|
||||||
contentPadding = contentPadding,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double, Alignment.CenterVertically),
|
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double, Alignment.CenterVertically),
|
||||||
) {
|
) {
|
||||||
if (state.isLoading) {
|
if (state.isLoading) {
|
||||||
|
@ -53,7 +50,6 @@ internal fun AccountOAuthContent(
|
||||||
} else {
|
} else {
|
||||||
item(key = "sign_in") {
|
item(key = "sign_in") {
|
||||||
SignInItem(
|
SignInItem(
|
||||||
emailAddress = state.emailAddress,
|
|
||||||
onSignInClick = { onEvent(Event.SignInClicked) },
|
onSignInClick = { onEvent(Event.SignInClicked) },
|
||||||
isGoogleSignIn = state.isGoogleSignIn,
|
isGoogleSignIn = state.isGoogleSignIn,
|
||||||
)
|
)
|
||||||
|
@ -69,7 +65,6 @@ internal fun AccountOAuthContentK9Preview() {
|
||||||
AccountOAuthContent(
|
AccountOAuthContent(
|
||||||
state = State(),
|
state = State(),
|
||||||
onEvent = {},
|
onEvent = {},
|
||||||
contentPadding = PaddingValues(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +76,6 @@ internal fun AccountOAuthContentThunderbirdPreview() {
|
||||||
AccountOAuthContent(
|
AccountOAuthContent(
|
||||||
state = State(),
|
state = State(),
|
||||||
onEvent = {},
|
onEvent = {},
|
||||||
contentPadding = PaddingValues(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,17 @@
|
||||||
package app.k9mail.feature.account.oauth.ui
|
package app.k9mail.feature.account.oauth.ui
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
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.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.domain.entity.OAuthResult
|
||||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.Effect
|
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.Event
|
||||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.ViewModel
|
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract.ViewModel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AccountOAuthScreen(
|
fun AccountOAuthView(
|
||||||
onOAuthResult: (OAuthResult) -> Unit,
|
onOAuthResult: (OAuthResult) -> Unit,
|
||||||
viewModel: ViewModel,
|
viewModel: ViewModel,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -36,29 +30,9 @@ fun AccountOAuthScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BackHandler {
|
AccountOAuthContent(
|
||||||
dispatch(Event.OnBackClicked)
|
state = state.value,
|
||||||
}
|
onEvent = { dispatch(it) },
|
||||||
|
|
||||||
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) },
|
|
||||||
)
|
|
||||||
},
|
|
||||||
modifier = modifier,
|
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
|
@Composable
|
||||||
internal fun LazyItemScope.SignInItem(
|
internal fun LazyItemScope.SignInItem(
|
||||||
emailAddress: String,
|
|
||||||
onSignInClick: () -> Unit,
|
onSignInClick: () -> Unit,
|
||||||
isGoogleSignIn: Boolean,
|
isGoogleSignIn: Boolean,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -17,7 +16,6 @@ internal fun LazyItemScope.SignInItem(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
SignInView(
|
SignInView(
|
||||||
emailAddress = emailAddress,
|
|
||||||
onSignInClick = onSignInClick,
|
onSignInClick = onSignInClick,
|
||||||
isGoogleSignIn = isGoogleSignIn,
|
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.common.DevicePreviews
|
||||||
import app.k9mail.core.ui.compose.designsystem.atom.button.Button
|
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.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.core.ui.compose.theme.MainTheme
|
||||||
import app.k9mail.feature.account.oauth.R
|
import app.k9mail.feature.account.oauth.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SignInView(
|
internal fun SignInView(
|
||||||
emailAddress: String,
|
|
||||||
onSignInClick: () -> Unit,
|
onSignInClick: () -> Unit,
|
||||||
isGoogleSignIn: Boolean,
|
isGoogleSignIn: Boolean,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -27,14 +24,6 @@ internal fun SignInView(
|
||||||
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double),
|
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double),
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
TextSubtitle1(text = stringResource(id = R.string.account_oauth_sign_in_title))
|
|
||||||
|
|
||||||
EmailAddressInput(
|
|
||||||
emailAddress = emailAddress,
|
|
||||||
onEmailAddressChange = {},
|
|
||||||
isEnabled = false,
|
|
||||||
)
|
|
||||||
|
|
||||||
TextCaption(
|
TextCaption(
|
||||||
text = stringResource(id = R.string.account_oauth_sign_in_description),
|
text = stringResource(id = R.string.account_oauth_sign_in_description),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
|
@ -57,7 +46,6 @@ internal fun SignInView(
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SignInViewPreview() {
|
internal fun SignInViewPreview() {
|
||||||
SignInView(
|
SignInView(
|
||||||
emailAddress = "test@example.com",
|
|
||||||
onSignInClick = {},
|
onSignInClick = {},
|
||||||
isGoogleSignIn = false,
|
isGoogleSignIn = false,
|
||||||
)
|
)
|
||||||
|
@ -67,7 +55,6 @@ internal fun SignInViewPreview() {
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SignInViewWithGooglePreview() {
|
internal fun SignInViewWithGooglePreview() {
|
||||||
SignInView(
|
SignInView(
|
||||||
emailAddress = "test@gmail.com",
|
|
||||||
onSignInClick = {},
|
onSignInClick = {},
|
||||||
isGoogleSignIn = true,
|
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