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

Unverified Commit 49bde4fa authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Remove needles initial state loading as it is covered by the LoadAccountState event

parent c5404215
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -15,11 +15,8 @@ import app.k9mail.feature.account.server.config.ui.incoming.AccountIncomingConfi
class AccountIncomingConfigViewModel(
    private val validator: Validator,
    private val accountStateRepository: AccountDomainContract.AccountStateRepository,
    initialState: State? = null,
) : BaseViewModel<State, Event, Effect>(
    initialState = initialState ?: accountStateRepository.getState().toIncomingConfigState(),
),
    ViewModel {
    initialState: State = State(),
) : BaseViewModel<State, Event, Effect>(initialState = initialState), ViewModel {

    @Suppress("CyclomaticComplexMethod")
    override fun event(event: Event) {
+2 −5
Original line number Diff line number Diff line
@@ -14,11 +14,8 @@ import app.k9mail.feature.account.server.config.ui.outgoing.AccountOutgoingConfi
class AccountOutgoingConfigViewModel(
    private val validator: Validator,
    private val accountStateRepository: AccountDomainContract.AccountStateRepository,
    initialState: State? = State(),
) : BaseViewModel<State, Event, Effect>(
    initialState = initialState ?: accountStateRepository.getState().toOutgoingConfigState(),
),
    ViewModel {
    initialState: State = State(),
) : BaseViewModel<State, Event, Effect>(initialState = initialState), ViewModel {

    override fun event(event: Event) {
        when (event) {
+1 −42
Original line number Diff line number Diff line
@@ -35,46 +35,6 @@ class AccountIncomingConfigViewModelTest {
    @get:Rule
    val mainDispatcherRule = MainDispatcherRule()

    @Test
    fun `should take initial state from repository when no initial state is provided`() = runTest {
        val accountState = AccountState(
            emailAddress = "test@example.com",
            incomingServerSettings = ServerSettings(
                "imap",
                "imap.example.com",
                123,
                MailConnectionSecurity.SSL_TLS_REQUIRED,
                AuthType.PLAIN,
                "username",
                "password",
                clientCertificateAlias = null,
                extra = emptyMap(),
            ),
        )
        val testSubject = createTestSubject(
            initialState = null,
            repository = InMemoryAccountStateRepository(accountState),
        )
        val turbines = turbines(testSubject)

        assertThatAndMviTurbinesConsumed(
            actual = turbines.awaitStateItem(),
            turbines = turbines,
        ) {
            isEqualTo(
                State(
                    protocolType = IncomingProtocolType.IMAP,
                    server = StringInputField(value = "imap.example.com"),
                    security = ConnectionSecurity.TLS,
                    port = NumberInputField(value = 123L),
                    authenticationType = AuthenticationType.PasswordCleartext,
                    username = StringInputField(value = "username"),
                    password = StringInputField(value = "password"),
                ),
            )
        }
    }

    @Test
    fun `should load account setup state when LoadAccountState event is received`() = runTest {
        val accountState = AccountState(
@@ -93,7 +53,6 @@ class AccountIncomingConfigViewModelTest {
        )
        val repository = InMemoryAccountStateRepository(AccountState())
        val testSubject = createTestSubject(
            initialState = null,
            repository = repository,
        )
        val turbines = turbinesWithInitialStateCheck(testSubject, State())
@@ -434,7 +393,7 @@ class AccountIncomingConfigViewModelTest {

    private companion object {
        fun createTestSubject(
            initialState: State? = null,
            initialState: State = State(),
            validator: AccountIncomingConfigContract.Validator = FakeAccountIncomingConfigValidator(),
            repository: AccountDomainContract.AccountStateRepository = InMemoryAccountStateRepository(),
        ) = AccountIncomingConfigViewModel(
+1 −41
Original line number Diff line number Diff line
@@ -33,45 +33,6 @@ class AccountOutgoingConfigViewModelTest {
    @get:Rule
    val mainDispatcherRule = MainDispatcherRule()

    @Test
    fun `should take initial state from repository when no initial state is provided`() = runTest {
        val accountState = AccountState(
            emailAddress = "test@example.com",
            outgoingServerSettings = ServerSettings(
                "smtp",
                "smtp.example.com",
                123,
                MailConnectionSecurity.SSL_TLS_REQUIRED,
                AuthType.PLAIN,
                "username",
                "password",
                clientCertificateAlias = null,
                extra = emptyMap(),
            ),
        )
        val testSubject = createTestSubject(
            initialState = null,
            repository = InMemoryAccountStateRepository(accountState),
        )
        val turbines = turbines(testSubject)

        assertThatAndMviTurbinesConsumed(
            actual = turbines.awaitStateItem(),
            turbines = turbines,
        ) {
            isEqualTo(
                State(
                    server = StringInputField(value = "smtp.example.com"),
                    security = ConnectionSecurity.TLS,
                    port = NumberInputField(value = 123L),
                    authenticationType = AuthenticationType.PasswordCleartext,
                    username = StringInputField(value = "username"),
                    password = StringInputField(value = "password"),
                ),
            )
        }
    }

    @Test
    fun `should load account setup state when LoadAccountState event is received`() = runTest {
        val accountState = AccountState(
@@ -90,7 +51,6 @@ class AccountOutgoingConfigViewModelTest {
        )
        val repository = InMemoryAccountStateRepository(AccountState())
        val testSubject = createTestSubject(
            initialState = null,
            repository = repository,
        )
        val turbines = turbinesWithInitialStateCheck(testSubject, State())
@@ -340,7 +300,7 @@ class AccountOutgoingConfigViewModelTest {

    private companion object {
        fun createTestSubject(
            initialState: State? = null,
            initialState: State = State(),
            validator: AccountOutgoingConfigContract.Validator = FakeAccountOutgoingConfigValidator(),
            repository: AccountDomainContract.AccountStateRepository = InMemoryAccountStateRepository(),
        ) = AccountOutgoingConfigViewModel(