diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/SignupViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/SignupViewModelTest.kt index bc91f5ea..fb6672c3 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/SignupViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/SignupViewModelTest.kt @@ -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 @@ -46,7 +46,7 @@ class SignupViewModelTest { @Before fun setup() { Dispatchers.setMain(mainThreadSurrogate) - viewModel = SignupViewModel(repository, responseHandler) + viewModel = SignupViewModel(mockAuthRepository, mockResponseHandler) viewModel.setEmail(validEmail) } @@ -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) } @@ -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) } @@ -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 @@ -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 @@ -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) } @@ -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) } @@ -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 @@ -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 @@ -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) } @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)