Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ff458da authored by cketti's avatar cketti
Browse files

Change `AccountOAuthScreen()` to `AccountOAuthView()`

parent cb6520ef
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
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(),
        )
    }
}
+5 −31
Original line number Diff line number Diff line
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) },
            )
        },
        modifier = modifier,
    ) { innerPadding ->
    AccountOAuthContent(
        state = state.value,
        onEvent = { dispatch(it) },
            contentPadding = innerPadding,
        modifier = modifier,
    )
}
}
+0 −2
Original line number Diff line number Diff line
@@ -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,
        )
+0 −13
Original line number Diff line number Diff line
@@ -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,
    )
+44 −0
Original line number Diff line number Diff line
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
@@ -18,7 +13,7 @@ import assertk.assertions.isNull
import kotlinx.coroutines.test.runTest
import org.junit.Test

class AccountOAuthScreenKtTest : ComposeTest() {
class AccountOAuthViewKtTest : ComposeTest() {

    @Test
    fun `should delegate navigation effects`() = runTest {
@@ -29,7 +24,7 @@ class AccountOAuthScreenKtTest : ComposeTest() {

        setContent {
            ThunderbirdTheme {
                AccountOAuthScreen(
                AccountOAuthView(
                    onOAuthResult = { oAuthResult = it },
                    viewModel = viewModel,
                )
@@ -46,50 +41,4 @@ class AccountOAuthScreenKtTest : ComposeTest() {

        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()
    }
}
Loading