Skip to content

Commit

Permalink
[#12] Pass string resource to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Nov 25, 2022
1 parent bb354ce commit cc527b5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.nimblehq.blisskmmic.presentation.model

data class NotificationUI(
data class NotificationUiModel(
val title: String,
val message: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
) {
Expand Down Expand Up @@ -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) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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"
Expand Down

0 comments on commit cc527b5

Please sign in to comment.