Skip to content

Commit

Permalink
chore: apply ktfmt code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rihabbelmekki committed Oct 17, 2024
1 parent 0e4cc33 commit 63dc3f7
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,104 +23,103 @@ import org.mockito.Mockito.`when`

class ProfileInformationScreenTest {

private lateinit var profileRepository: ProfileRepository
private lateinit var profileViewModel: ProfileViewModel
private lateinit var navigationActions: NavigationActions
private lateinit var firebaseAuth: FirebaseAuth

@get:Rule val composeTestRule = createComposeRule()

private val mockUserProfile =
UserProfile(username = "JohnDoe", bio = "This is a bio", email = "john.doe@example.com")

@Before
fun setUp() {

profileRepository = mock(ProfileRepository::class.java)
profileViewModel = ProfileViewModel(profileRepository)
navigationActions = mock(NavigationActions::class.java)
firebaseAuth = mock(FirebaseAuth::class.java)

// Define navigation action behavior
`when`(navigationActions.currentRoute()).thenReturn(Screen.PROFILE_INFORMATION)
}

@Test
fun displayAllComponents() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Check that the main components are displayed
composeTestRule.onNodeWithTag("editProfileScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileTitle").assertIsDisplayed()
composeTestRule.onNodeWithTag("goBackButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileUsername").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileEmail").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileBio").assertIsDisplayed()
composeTestRule.onNodeWithTag("profileSave").assertIsDisplayed()
composeTestRule.onNodeWithTag("profileLogout").assertIsDisplayed()

// Check button texts
composeTestRule.onNodeWithTag("profileSave").assertTextEquals("Save")
composeTestRule.onNodeWithTag("profileLogout").assertTextEquals("Sign out")
}

@Test
fun saveButtonDisabledWhenFieldsAreEmpty() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Initially, all fields are empty, so the save button should be disabled
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill in username, bio, and email
composeTestRule.onNodeWithTag("editProfileUsername").performTextInput("JohnDoe")
composeTestRule.onNodeWithTag("editProfileEmail").performTextInput("john.doe@example.com")
composeTestRule.onNodeWithTag("editProfileBio").performTextInput("This is a bio")

// Now all fields are filled, so the save button should be enabled
composeTestRule.onNodeWithTag("profileSave").assertIsEnabled()
}

@Test
fun saveButtonDisabledWhenAnyFieldIsEmpty() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Initially, all fields are empty, so the save button should be disabled
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill only the username, leave other fields empty
composeTestRule.onNodeWithTag("editProfileUsername").performTextInput("JohnDoe")
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill in the email and leave the bio empty
composeTestRule.onNodeWithTag("editProfileEmail").performTextInput("john.doe@example.com")
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Now fill the bio
composeTestRule.onNodeWithTag("editProfileBio").performTextInput("This is a bio")

// Now all fields are filled, the save button should be enabled
composeTestRule.onNodeWithTag("profileSave").assertIsEnabled()
}

@Test
fun saveButtonWorks() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Perform click on the save button
composeTestRule.onNodeWithTag("profileSave").performClick()

// Mock behavior can be asserted in ViewModel (not shown here, as it's logic dependent)
}

@Test
fun logoutButtonWorks() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Perform click on the sign-out button
composeTestRule.onNodeWithTag("profileLogout").performClick()

// Verify that the navigation action to the landing screen was triggered
Mockito.verify(navigationActions).navigateTo(Screen.LANDING)
}

}
private lateinit var profileRepository: ProfileRepository
private lateinit var profileViewModel: ProfileViewModel
private lateinit var navigationActions: NavigationActions
private lateinit var firebaseAuth: FirebaseAuth

@get:Rule val composeTestRule = createComposeRule()

private val mockUserProfile =
UserProfile(username = "JohnDoe", bio = "This is a bio", email = "john.doe@example.com")

@Before
fun setUp() {

profileRepository = mock(ProfileRepository::class.java)
profileViewModel = ProfileViewModel(profileRepository)
navigationActions = mock(NavigationActions::class.java)
firebaseAuth = mock(FirebaseAuth::class.java)

// Define navigation action behavior
`when`(navigationActions.currentRoute()).thenReturn(Screen.PROFILE_INFORMATION)
}

@Test
fun displayAllComponents() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Check that the main components are displayed
composeTestRule.onNodeWithTag("editProfileScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileTitle").assertIsDisplayed()
composeTestRule.onNodeWithTag("goBackButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileUsername").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileEmail").assertIsDisplayed()
composeTestRule.onNodeWithTag("editProfileBio").assertIsDisplayed()
composeTestRule.onNodeWithTag("profileSave").assertIsDisplayed()
composeTestRule.onNodeWithTag("profileLogout").assertIsDisplayed()

// Check button texts
composeTestRule.onNodeWithTag("profileSave").assertTextEquals("Save")
composeTestRule.onNodeWithTag("profileLogout").assertTextEquals("Sign out")
}

@Test
fun saveButtonDisabledWhenFieldsAreEmpty() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Initially, all fields are empty, so the save button should be disabled
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill in username, bio, and email
composeTestRule.onNodeWithTag("editProfileUsername").performTextInput("JohnDoe")
composeTestRule.onNodeWithTag("editProfileEmail").performTextInput("john.doe@example.com")
composeTestRule.onNodeWithTag("editProfileBio").performTextInput("This is a bio")

// Now all fields are filled, so the save button should be enabled
composeTestRule.onNodeWithTag("profileSave").assertIsEnabled()
}

@Test
fun saveButtonDisabledWhenAnyFieldIsEmpty() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Initially, all fields are empty, so the save button should be disabled
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill only the username, leave other fields empty
composeTestRule.onNodeWithTag("editProfileUsername").performTextInput("JohnDoe")
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Fill in the email and leave the bio empty
composeTestRule.onNodeWithTag("editProfileEmail").performTextInput("john.doe@example.com")
composeTestRule.onNodeWithTag("profileSave").assertIsNotEnabled()

// Now fill the bio
composeTestRule.onNodeWithTag("editProfileBio").performTextInput("This is a bio")

// Now all fields are filled, the save button should be enabled
composeTestRule.onNodeWithTag("profileSave").assertIsEnabled()
}

@Test
fun saveButtonWorks() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Perform click on the save button
composeTestRule.onNodeWithTag("profileSave").performClick()

// Mock behavior can be asserted in ViewModel (not shown here, as it's logic dependent)
}

@Test
fun logoutButtonWorks() {
composeTestRule.setContent { ProfileInformationScreen(profileViewModel, navigationActions) }

// Perform click on the sign-out button
composeTestRule.onNodeWithTag("profileLogout").performClick()

// Verify that the navigation action to the landing screen was triggered
Mockito.verify(navigationActions).navigateTo(Screen.LANDING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ class ProfileKtTest {
composeTestRule.onNodeWithText("Map").assertExists()
composeTestRule.onNodeWithText("Menu").assertExists()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ fun LookUpApp() {
navigation(startDestination = Screen.PROFILE, route = Route.PROFILE) {
composable(Screen.COLLECTION) { CollectionScreen(navigationActions) }
composable(Screen.PROFILE) { ProfileScreen(navigationActions) }
composable(Screen.PROFILE_INFORMATION) { ProfileInformationScreen(profileViewModel, navigationActions) }
composable(Screen.PROFILE_INFORMATION) {
ProfileInformationScreen(profileViewModel, navigationActions)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.lookupgroup27.lookup.model.profile

interface ProfileRepository {
fun init(onSuccess: () -> Unit)
fun init(onSuccess: () -> Unit)

fun getUserProfile(onSuccess: (UserProfile?) -> Unit, onFailure: (Exception) -> Unit)
fun getUserProfile(onSuccess: (UserProfile?) -> Unit, onFailure: (Exception) -> Unit)

fun updateUserProfile(profile: UserProfile, onSuccess: () -> Unit, onFailure: (Exception) -> Unit)
fun updateUserProfile(profile: UserProfile, onSuccess: () -> Unit, onFailure: (Exception) -> Unit)

fun logoutUser()
}
fun logoutUser()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class UserProfile(val username: String = " ", val email: String = " ", val
class ProfileRepositoryFirestore(
private val db: FirebaseFirestore,
private val auth: FirebaseAuth
) : ProfileRepository{
) : ProfileRepository {

// private val auth = FirebaseAuth.getInstance()
private val collectionPath = "users"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
Expand Down
Loading

0 comments on commit 63dc3f7

Please sign in to comment.