Skip to content

Commit

Permalink
Merge pull request #94 from snuhcs-course/test/signup-viewmodel
Browse files Browse the repository at this point in the history
Test: Signup viewmodel
  • Loading branch information
JH747 authored Dec 4, 2023
2 parents 352059f + 0a3ebf8 commit ce5636c
Showing 1 changed file with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SignupViewModelTest {
private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@MockK
private val repository: AuthRepository = mockk()
private val responseHandler: ResponseHandler = mockk()
private val mockAuthRepository: AuthRepository = mockk()
private val mockResponseHandler: ResponseHandler = mockk()
private lateinit var viewModel: SignupViewModel

// boundary condition: 15 characters in nickname field
Expand All @@ -46,7 +46,7 @@ class SignupViewModelTest {
@Before
fun setup() {
Dispatchers.setMain(mainThreadSurrogate)
viewModel = SignupViewModel(repository, responseHandler)
viewModel = SignupViewModel(mockAuthRepository, mockResponseHandler)
viewModel.setEmail(validEmail)
}

Expand All @@ -57,12 +57,19 @@ class SignupViewModelTest {
mainThreadSurrogate.close()
}

@Test
fun `should set email when called`() {
viewModel.setEmail(validEmail)

assertEquals(validEmail, viewModel.email.value)
}

@Test
fun `should set empty nickname before signup click when set nickname is called with empty nickname`() {
viewModel.setNickname(emptyNickname)

assertEquals(emptyNickname, viewModel.nicknameInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidNickname)
}

Expand All @@ -71,7 +78,7 @@ class SignupViewModelTest {
viewModel.setNickname(longNickname)

assertEquals(longNickname, viewModel.nicknameInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidNickname)
}

Expand All @@ -81,7 +88,7 @@ class SignupViewModelTest {

assertEquals(validNickname, viewModel.nicknameInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(true, viewModel.uiState.value.isValidNickname)
}

@Test
Expand Down Expand Up @@ -140,7 +147,7 @@ class SignupViewModelTest {

assertEquals(validNickname, viewModel.nicknameInput)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(true, viewModel.uiState.value.isValidNickname)
}

@Test
Expand All @@ -152,7 +159,7 @@ class SignupViewModelTest {
viewModel.setNickname(longNickname)

assertEquals(longNickname, viewModel.nicknameInput)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidNickname)
}

Expand All @@ -161,7 +168,7 @@ class SignupViewModelTest {
viewModel.setPassword(shortPassword)

assertEquals(shortPassword, viewModel.passwordInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
}

Expand All @@ -171,7 +178,14 @@ class SignupViewModelTest {

assertEquals(validPassword, viewModel.passwordInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
}

@Test
fun `should set password check when called`() {
viewModel.setPasswordCheck(validPassword)

assertEquals(validPassword, viewModel.passwordCheckInput)
}

@Test
Expand Down Expand Up @@ -208,7 +222,7 @@ class SignupViewModelTest {

assertEquals(validPassword, viewModel.passwordInput)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
}

@Test
Expand All @@ -220,7 +234,7 @@ class SignupViewModelTest {
viewModel.setPassword(shortPassword)

assertEquals(shortPassword, viewModel.passwordInput)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
}

Expand Down Expand Up @@ -269,7 +283,7 @@ class SignupViewModelTest {

assertEquals(validPassword, viewModel.passwordCheckInput)
assertEquals(null, viewModel.uiState.value.error?.type)
assertEquals(true, viewModel.uiState.value.isValidEmail)
assertEquals(false, viewModel.uiState.value.isValidEmail)
}

@Test
Expand All @@ -281,7 +295,7 @@ class SignupViewModelTest {

assertEquals(validPassword, viewModel.passwordCheckInput)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
}

@Test
Expand All @@ -295,7 +309,7 @@ class SignupViewModelTest {

assertEquals(shortPassword, viewModel.passwordCheckInput)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
}

@Test
Expand Down Expand Up @@ -337,7 +351,7 @@ class SignupViewModelTest {
viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(R.string.no_nickname, viewModel.uiState.value.error?.messageId)
Expand All @@ -352,7 +366,7 @@ class SignupViewModelTest {
viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(R.string.no_nickname, viewModel.uiState.value.error?.messageId)
Expand Down Expand Up @@ -397,7 +411,7 @@ class SignupViewModelTest {
viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(R.string.nickname_too_long, viewModel.uiState.value.error?.messageId)
Expand All @@ -412,7 +426,7 @@ class SignupViewModelTest {
viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(true, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.NICKNAME, viewModel.uiState.value.error?.type)
assertEquals(R.string.nickname_too_long, viewModel.uiState.value.error?.messageId)
Expand All @@ -426,7 +440,7 @@ class SignupViewModelTest {

viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(true, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
Expand All @@ -441,7 +455,7 @@ class SignupViewModelTest {

viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(true, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.PASSWORD, viewModel.uiState.value.error?.type)
Expand All @@ -456,7 +470,7 @@ class SignupViewModelTest {

viewModel.signup {}

assertEquals(false, viewModel.uiState.value.isValidNickname)
assertEquals(true, viewModel.uiState.value.isValidNickname)
assertEquals(false, viewModel.uiState.value.isValidPassword)
assertEquals(false, viewModel.uiState.value.isValidEmail)
assertEquals(SignupErrorType.PASSWORD_CHECK, viewModel.uiState.value.error?.type)
Expand Down

0 comments on commit ce5636c

Please sign in to comment.