Skip to content

Commit

Permalink
✅Refactor LoginViewModelTest
Browse files Browse the repository at this point in the history
  • Loading branch information
89645321 committed Nov 3, 2023
1 parent c32b190 commit db57638
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.example.speechbuddy.repository.AuthRepository
import com.example.speechbuddy.ui.models.LoginErrorType
import com.example.speechbuddy.ui.models.SignupErrorType
import com.example.speechbuddy.utils.Resource
import com.example.speechbuddy.utils.Status
import com.example.speechbuddy.viewmodel.LoginViewModel
import com.example.speechbuddy.viewmodel.SignupViewModel
import io.mockk.coEvery
Expand Down Expand Up @@ -63,17 +64,17 @@ class LoginViewModelTest {
viewModel.setEmail(invalidEmail)

assertEquals(invalidEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.type, null)
assertEquals(viewModel.uiState.value.isValidEmail, false)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidEmail)
}

@Test
fun loginViewModel_setEmail_valid_beforeSignupClick() {
viewModel.setEmail(validEmail)

assertEquals(validEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.type, null)
assertEquals(viewModel.uiState.value.isValidEmail, false)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidEmail)
}

@Test
Expand All @@ -83,14 +84,14 @@ class LoginViewModelTest {
viewModel.login()

assertEquals(invalidEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.type, LoginErrorType.EMAIL)
assertEquals(viewModel.uiState.value.isValidEmail, false)
assertEquals(LoginErrorType.EMAIL, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidEmail)

viewModel.setEmail(validEmail)

assertEquals(validEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.type, null)
assertEquals(viewModel.uiState.value.isValidEmail, true)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(true, viewModel.uiState.value.isValidEmail)
}

@Test
Expand All @@ -108,16 +109,16 @@ class LoginViewModelTest {
viewModel.login()

assertEquals(notRegisteredEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.messageId, R.string.false_email)
assertEquals(viewModel.uiState.value.error?.type, LoginErrorType.EMAIL)
assertEquals(viewModel.uiState.value.isValidEmail, false)
assertEquals(LoginErrorType.EMAIL, viewModel.uiState.value.error?.type)
assertEquals(R.string.false_email, viewModel.uiState.value.error?.messageId)
assertEquals(false, viewModel.uiState.value.isValidEmail)

viewModel.setEmail(validEmail)

assertEquals(validEmail, viewModel.emailInput)
assertEquals(viewModel.uiState.value.error?.type, null)
assertEquals(viewModel.uiState.value.error?.messageId, null)
assertEquals(viewModel.uiState.value.isValidEmail, true)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(null, viewModel.uiState.value.error?.messageId)
assertEquals(true, viewModel.uiState.value.isValidEmail)
}
/*
@Test
Expand Down

0 comments on commit db57638

Please sign in to comment.