-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into build/update-compose-…
…kotlin
- Loading branch information
Showing
11 changed files
with
521 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ jobs: | |
run: ./gradlew detekt | ||
|
||
- name: Run Tests | ||
run: ./gradlew test | ||
run: ./gradlew testDevDebugUnitTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
app/src/androidTest/java/com/monstarlab/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
app/src/test/java/com/monstarlab/features/login/domain/usecase/LoginUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.monstarlab.features.login.domain.usecase | ||
|
||
import com.monstarlab.features.auth.domain.models.AuthToken | ||
import com.monstarlab.features.auth.domain.repository.AuthRepository | ||
import com.monstarlab.features.user.domain.repository.UserRepository | ||
import io.mockk.clearAllMocks | ||
import io.mockk.coEvery | ||
import io.mockk.mockk | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import kotlinx.coroutines.test.runTest | ||
|
||
class LoginUseCaseTest { | ||
|
||
private lateinit var authRepository: AuthRepository | ||
private lateinit var userRepository: UserRepository | ||
private lateinit var loginUseCase: LoginUseCase | ||
|
||
@Before | ||
fun setUp() { | ||
authRepository = mockk() | ||
userRepository = mockk() | ||
loginUseCase = LoginUseCase(authRepository, userRepository) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
clearAllMocks() | ||
} | ||
|
||
/** | ||
* GIVEN | ||
* - Auth token is returned | ||
* - Retrieving user is returned | ||
* WHEN | ||
* - User logs in | ||
* THEN | ||
* - Result is successful | ||
*/ | ||
@Test | ||
fun testLoginSuccess() = runTest { | ||
// GIVEN | ||
val email = "[email protected]" | ||
val password = "password" | ||
|
||
coEvery { authRepository.login(email, password) } returns AuthToken("token") | ||
coEvery { userRepository.get() } returns mockk() | ||
|
||
// WHEN | ||
val result = loginUseCase.invoke(email, password) | ||
|
||
// THEN | ||
assertEquals("Result is successful", true, result.isSuccess) | ||
} | ||
|
||
/** | ||
* GIVEN | ||
* - Auth token throws an exception | ||
* - Retrieving user is returned | ||
* WHEN | ||
* - User logs in | ||
* THEN | ||
* - Result is unsuccessful | ||
*/ | ||
@Test | ||
fun testLoginFailure() = runTest { | ||
// GIVEN | ||
val email = "[email protected]" | ||
val password = "password" | ||
|
||
coEvery { authRepository.login(email, password) } throws Exception() | ||
coEvery { userRepository.get() } returns mockk() | ||
|
||
// WHEN | ||
val result = loginUseCase.invoke(email, password) | ||
|
||
// THEN | ||
assertEquals("Result is unsuccessful", false, result.isSuccess) | ||
} | ||
|
||
/** | ||
* GIVEN | ||
* - Auth token is returned | ||
* - Retrieving user throws an exception | ||
* WHEN | ||
* - User logs in | ||
* THEN | ||
* - Result is unsuccessful | ||
*/ | ||
@Test | ||
fun testLoginFailureWhenUserRetrievalFails() = runTest { | ||
// GIVEN | ||
val email = "[email protected]" | ||
val password = "password" | ||
|
||
coEvery { authRepository.login(email, password) } returns AuthToken("token") | ||
coEvery { userRepository.get() } throws Exception() | ||
|
||
// WHEN | ||
val result = loginUseCase.invoke(email, password) | ||
|
||
// THEN | ||
assertEquals("Result is unsuccessful", false, result.isSuccess) | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
app/src/test/java/com/monstarlab/features/login/ui/LoginScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.monstarlab.features.login.ui | ||
|
||
import androidx.compose.ui.test.assert | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertIsEnabled | ||
import androidx.compose.ui.test.hasClickAction | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextReplacement | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class LoginScreenTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val mockActions: LoginActions = mockk(relaxed = true) | ||
|
||
@Before | ||
fun setUp() { | ||
composeTestRule.setContent { | ||
LoginScreen(state = LoginState(), actions = mockActions) | ||
} | ||
} | ||
|
||
/** | ||
* GIVEN: | ||
* - Initial state of the login screen | ||
* WHEN: | ||
* - The screen is displayed | ||
* THEN: | ||
* - Email field should be enabled, displayed, and contain "[email protected]" | ||
* - Password field should be enabled and displayed | ||
* - Login button should be enabled and displayed | ||
*/ | ||
@Test | ||
fun testInitialState() { | ||
composeTestRule | ||
.onNodeWithText("E-Mail") | ||
.assertIsEnabled() | ||
.assertIsDisplayed() | ||
.assert(hasText("[email protected]")) | ||
|
||
composeTestRule | ||
.onNodeWithText("Password") | ||
.assertIsEnabled() | ||
.assertIsDisplayed() | ||
|
||
composeTestRule | ||
.onNode(hasText("Login") and hasClickAction()) | ||
.assertIsEnabled() | ||
.assertIsDisplayed() | ||
} | ||
|
||
/** | ||
* GIVEN: | ||
* - Initial email is "[email protected]" | ||
* - Test email is "[email protected]" | ||
* WHEN: | ||
* - User types "[email protected]" into the email field | ||
* THEN: | ||
* - onEmailChange action should be called with "[email protected]" | ||
*/ | ||
@Test | ||
fun testEmailInput() { | ||
composeTestRule | ||
.onNodeWithText("E-Mail") | ||
.performTextReplacement("[email protected]") | ||
|
||
verify { mockActions.onEmailChange("[email protected]") } | ||
} | ||
|
||
/** | ||
* GIVEN: | ||
* - Initial password is empty | ||
* - Test password is "secret" | ||
* WHEN: | ||
* - User types "secret" into the password field | ||
* THEN: | ||
* - onPasswordChange action should be called with "secret" | ||
*/ | ||
@Test | ||
fun testPasswordInput() { | ||
composeTestRule | ||
.onNodeWithText("Password") | ||
.performTextReplacement("secret") | ||
|
||
verify { mockActions.onPasswordChange("secret") } | ||
} | ||
|
||
/** | ||
* GIVEN: | ||
* - User is on the login screen | ||
* WHEN: | ||
* - User clicks the login button | ||
* THEN: | ||
* - onLoginClick action should be called | ||
*/ | ||
@Test | ||
fun testLoginButtonClick() { | ||
composeTestRule | ||
.onNode(hasText("Login") and hasClickAction()) | ||
.performClick() | ||
|
||
verify { mockActions.onLoginClick() } | ||
} | ||
} |
Oops, something went wrong.