From cc527b550250eab0d9d3215a73d6f0758839f910 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 25 Nov 2022 10:12:40 +0700 Subject: [PATCH] [#12] Pass string resource to ui --- .../presentation/helpers/MokoLocalize.kt | 6 ------ ...{NotificationUI.kt => NotificationUiModel.kt} | 2 +- .../resetpassword/ResetPasswordViewModel.kt | 10 +++++----- .../presentation/helpers/MokoLocalizeTest.kt | 16 ---------------- .../resetpassword/ResetPasswordViewModelTest.kt | 6 +++--- 5 files changed, 9 insertions(+), 31 deletions(-) rename shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/{NotificationUI.kt => NotificationUiModel.kt} (75%) diff --git a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalize.kt b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalize.kt index fdab2450..1a414940 100644 --- a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalize.kt +++ b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalize.kt @@ -12,12 +12,6 @@ class MokoLocalize { if (id == MR.strings.common_error.toString()) { return StringDesc.Resource(MR.strings.common_error) } - else if (id == MR.strings.reset_password_success_notification_title.toString()) { - return StringDesc.Resource((MR.strings.reset_password_success_notification_title)) - } - else if (id == MR.strings.reset_password_success_notification_message.toString()) { - return StringDesc.Resource((MR.strings.reset_password_success_notification_message)) - } return null } } diff --git a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUI.kt b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUiModel.kt similarity index 75% rename from shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUI.kt rename to shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUiModel.kt index 5cb3d1e8..e95fe04f 100644 --- a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUI.kt +++ b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/model/NotificationUiModel.kt @@ -1,6 +1,6 @@ package co.nimblehq.blisskmmic.presentation.model -data class NotificationUI( +data class NotificationUiModel( val title: String, val message: String ) diff --git a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModel.kt b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModel.kt index 161f3f08..491c8fda 100644 --- a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModel.kt +++ b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModel.kt @@ -3,7 +3,7 @@ package co.nimblehq.blisskmmic.presentation.modules.resetpassword import co.nimblehq.blisskmmic.MR import co.nimblehq.blisskmmic.data.network.helpers.toErrorMessage import co.nimblehq.blisskmmic.domain.usecase.ResetPasswordUseCase -import co.nimblehq.blisskmmic.presentation.model.NotificationUI +import co.nimblehq.blisskmmic.presentation.model.NotificationUiModel import kotlinx.coroutines.MainScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch data class ResetPasswordViewState( - val successNotification: NotificationUI? = null, + val successNotification: NotificationUiModel? = null, val isLoading: Boolean = false, val error: String? = null ) { @@ -40,9 +40,9 @@ class ResetPasswordViewModel(private val resetPasswordUseCase: ResetPasswordUseC } } .collect { _ -> - val notification = NotificationUI( - MR.strings.reset_password_success_notification_title.toString(), - MR.strings.reset_password_success_notification_message.toString() + val notification = NotificationUiModel( + MR.strings.reset_password_success_notification_title, + MR.strings.reset_password_success_notification_message ) mutableViewState.update { ResetPasswordViewState(notification, false) } } diff --git a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalizeTest.kt b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalizeTest.kt index 54d6a683..9f587691 100644 --- a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalizeTest.kt +++ b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/helpers/MokoLocalizeTest.kt @@ -14,22 +14,6 @@ class MokoLocalizeTest { StringDesc.Resource(MR.strings.common_error) } - @Test - fun `When calling localize with reset_password_success_notification_title desc, it returns correct StringDesc`() { - MokoLocalize().localize( - MR.strings.reset_password_success_notification_title.toString() - ) shouldBe - StringDesc.Resource(MR.strings.reset_password_success_notification_title) - } - - @Test - fun `When calling localize with reset_password_success_notification_message desc, it returns correct StringDesc`() { - MokoLocalize().localize( - MR.strings.reset_password_success_notification_message.toString() - ) shouldBe - StringDesc.Resource(MR.strings.reset_password_success_notification_message) - } - @Test fun `When calling localize with an unknown desc, it returns null`() { MokoLocalize().localize("unknown") shouldBe null diff --git a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModelTest.kt b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModelTest.kt index f71fcd4b..a9e26ec5 100644 --- a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModelTest.kt +++ b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/resetpassword/ResetPasswordViewModelTest.kt @@ -45,7 +45,7 @@ class ResetPasswordViewModelTest { } @Test - fun `When calling reset with success response, it changes viewState to success`() = runTest { + fun `When calling reset with success response, it changes viewState to success with correct item`() = runTest { mocker.every { resetPasswordUseCase(email) } returns flow { emit(resultMessage) } @@ -55,11 +55,11 @@ class ResetPasswordViewModelTest { val result = resetPasswordViewModel .viewState .first { it.successNotification != null } - result.successNotification?.title shouldBe MR.strings.reset_password_success_notification_title.toString() + result.successNotification?.title shouldBe MR.strings.reset_password_success_notification_title + result.successNotification?.message shouldBe MR.strings.reset_password_success_notification_message result.isLoading shouldBe false } - @Suppress("MaxLineLength") @Test fun `When calling reset with faliure response, it changes viewState to error`() = runTest { val errorMessage = "Test Error"