Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Kamila/fix friends double click #225

Merged
merged 31 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5068fb6
DataGetter: fix the doubleClick of Add button
kamilababayeva Apr 30, 2022
5ba6203
User: add friends subfield
kamilababayeva Apr 30, 2022
fc07400
DataGetter: change function to get userData from firebase
kamilababayeva Apr 30, 2022
b4c2525
UserProfileAdapter: do not display add button if user is a friend
kamilababayeva Apr 30, 2022
e739fa3
UserProfileAdapter: add ocmmnets, fix the function names
kamilababayeva Apr 30, 2022
97ec8d0
ProfileActivity: remove unnecessary test
kamilababayeva Apr 30, 2022
2fcff82
UserProfileAdapter: add check for the current user
kamilababayeva Apr 30, 2022
0c1020f
UserProfileAdapter: function to change visibility
kamilababayeva Apr 30, 2022
3e7ef93
dataGetter: fix the creation of user
kamilababayeva May 1, 2022
cec7905
ProfileActivity: mock the database
kamilababayeva May 1, 2022
3785329
AuthenticationActivityTest: mock user uid
kamilababayeva May 1, 2022
1bc600a
AuthenticationActivityTest: fix mocking
kamilababayeva May 1, 2022
c19c12b
WelcomeActivity: remove unnecessary check
kamilababayeva May 1, 2022
103c121
MockUserProfileAdapter, modify tests
kamilababayeva May 1, 2022
7010c9d
Update app/src/androidTest/java/ch/sdp/vibester/activity/CreateProfil…
kamilababayeva May 2, 2022
dd12bdf
Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
kamilababayeva May 2, 2022
7ff0dc9
Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
kamilababayeva May 2, 2022
b3b860f
Update app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActiv…
kamilababayeva May 2, 2022
cc03a49
Update app/src/main/java/ch/sdp/vibester/user/User.kt
kamilababayeva May 2, 2022
1bd872e
Update app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt
kamilababayeva May 2, 2022
32c73ed
Update app/src/main/java/ch/sdp/vibester/database/DataGetter.kt
kamilababayeva May 2, 2022
5633bbb
Update app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt
kamilababayeva May 2, 2022
276b5b7
Update app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt
kamilababayeva May 2, 2022
d16590a
Update app/src/main/java/ch/sdp/vibester/user/UserProfileAdapter.kt
kamilababayeva May 2, 2022
cf974fe
add comments, fix the spacing
kamilababayeva May 2, 2022
c8061b0
Add comment about the user's friends value
kamilababayeva May 2, 2022
15e9a49
User: fix the comment
kamilababayeva May 2, 2022
9d65444
Merge branch 'main' into kamila/fix_friends_double_click
kamilababayeva May 2, 2022
90acff6
ProfileActivity: fix query
kamilababayeva May 2, 2022
e631fd5
fixes after merge
kamilababayeva May 2, 2022
9f46736
ScoreboardActivityTest: remove one test to fix later
kamilababayeva May 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class AuthenticationActivityTest {
return taskResult
}

private fun createMockUser(email: String): FirebaseUser {
private fun createMockUser(email: String, uid: String = "mockUID"): FirebaseUser {
val mockUser = mockk<FirebaseUser>()
every { mockUser.email } returns email
every { mockUser.uid } returns uid

return mockUser
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CreateProfileActivityTest {
lastArg<(String) -> Unit>().invoke(email)
}

every { mockUsersRepo.getUserData(any()) } answers {
every { mockUsersRepo.getUserData(any(), any()) } answers {
secondArg<(User) -> Unit>().invoke(User())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.TestMode
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.user.User
import com.google.firebase.auth.FirebaseUser
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand All @@ -42,16 +44,31 @@ class ProfileActivityTest {
Intents.init()
}

@BindValue @JvmField
val mockAuthenticatior = mockk<FireBaseAuthenticator>()

private fun createMockAuthenticatorInvocation() {
val mockUser = createMockUser()
every { mockAuthenticatior.getCurrUser() } returns mockUser
}

private fun createMockUser(): FirebaseUser {
val email = "[email protected]"
val uid = "mockuseruid"
val mockUser = mockk<FirebaseUser>()
every { mockUser.email } returns email
every { mockUser.uid } returns uid
return mockUser
}

@BindValue @JvmField
val mockUsersRepo = mockk<DataGetter>()

private fun createMockInvocation(mockProfile: User) {
every { mockUsersRepo.getUserData(any()) } answers {
every { mockUsersRepo.getUserData(any(), any()) } answers {
secondArg<(User) -> Unit>().invoke(mockProfile)
}
every { mockUsersRepo.updateFieldString(any(), any(), any()) } answers {}

every { mockUsersRepo.getUserData(any())} answers {}
}

@After
Expand All @@ -64,10 +81,9 @@ class ProfileActivityTest {
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

createMockInvocation(inputProfile)
createMockAuthenticatorInvocation()
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.username)).check(matches(withText(inputProfile.username)))
Expand All @@ -78,9 +94,11 @@ class ProfileActivityTest {

@Test
fun clickBackToMain(){
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
intent.putExtra("isUnitTest", true)
createMockInvocation(inputProfile)
createMockAuthenticatorInvocation()

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

Expand All @@ -94,11 +112,9 @@ class ProfileActivityTest {
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

createMockInvocation(inputProfile)

createMockAuthenticatorInvocation()
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

val newUsername = "Lalisa Bon idomesniu"
Expand All @@ -117,10 +133,9 @@ class ProfileActivityTest {
val inputProfile = User( "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

createMockInvocation(inputProfile)
createMockAuthenticatorInvocation()

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,89 @@
package ch.sdp.vibester.activity

import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.user.User
import com.google.firebase.auth.FirebaseUser
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.every
import io.mockk.mockk
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith



@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class SearchUserActivityTest {

@get:Rule
val activityRule = ActivityScenarioRule(SearchUserActivity::class.java)
@get:Rule(order = 0)
var hiltRule = HiltAndroidRule(this)

@BindValue @JvmField
val mockUsersRepo = mockk<DataGetter>()

private fun createMockInvocation() {
val mockUser1 = User("mockUser1", uid = "mockUser1uid")
val mockUser2 = User("mockUser2", uid = "mockUser2uid")
val mockUser3 = User("mockUser3", uid = "mockUser3uid")
val mockUser = User("mockUser", uid = "mockUseruid", friends = mapOf(Pair(mockUser2.uid,true), Pair(mockUser3.uid,true)))

val mockUsers = arrayListOf<User>(mockUser1, mockUser2, mockUser3)
every {mockUsersRepo.searchByField(any(), any(), any())} answers {
lastArg<(ArrayList<User>) -> Unit>().invoke(mockUsers)
}

every {mockUsersRepo.getUserData(any(), any())} answers {
secondArg<(User) -> Unit>().invoke(mockUser)
}

every {mockUsersRepo.updateFieldSubFieldBoolean(any(), any(), any(), any())} answers {}
}

@BindValue @JvmField
val mockAuthenticator = mockk<FireBaseAuthenticator>()

private fun createMockAuthenticator(){
val mockUser = createMockUser()
every {mockAuthenticator.getCurrUser()} returns mockUser
}

private fun createMockUser(email: String = "[email protected]", uid: String = "mockUseruid"): FirebaseUser {
val mockUser = mockk<FirebaseUser>()
every { mockUser.email } returns email
every { mockUser.uid } returns uid

return mockUser
}

@Before
fun setUp() {
hiltRule.inject()
Intents.init()
}

Expand All @@ -42,13 +94,27 @@ class SearchUserActivityTest {

@Test
fun recycleViewToViewTest() {
onView(ViewMatchers.withId(R.id.searchList))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)

createMockInvocation()
createMockAuthenticator()

val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.searchList))
.check(matches(ViewMatchers.isDisplayed()))
}

@Test
fun recycleViewClickTest() {
onView((ViewMatchers.withId(R.id.searchList)))
val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)

createMockInvocation()
createMockAuthenticator()

val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)

onView((withId(R.id.searchList)))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
2,
Expand All @@ -59,35 +125,56 @@ class SearchUserActivityTest {

@Test
fun recycleViewScrollDownTest() {
val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)

createMockInvocation()
createMockAuthenticator()

val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)

val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
val itemCount = recyclerView.adapter?.itemCount
if (itemCount != null) {
onView(ViewMatchers.withId(R.id.searchList)).perform(
onView(withId(R.id.searchList)).perform(
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
itemCount.minus(1)
)
)
}
}

@Test
fun recycleViewCheckEmpty() {
val inputTxt= "TESTESTESTEST"
onView(ViewMatchers.withId(R.id.searchUserET)).perform(ViewActions.typeText(inputTxt),
ViewActions.closeSoftKeyboard())
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
val itemCount = recyclerView.adapter?.itemCount
assertEquals(itemCount, null)
fun checkIconVisible(){
val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)

createMockInvocation()
createMockAuthenticator()

val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)

checkRecyclerSubViews(R.id.searchList, 2, withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE), R.id.addFriendBtn);
checkRecyclerSubViews(R.id.searchList, 2, withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), R.id.addedFriendIcon);
}

@Test
fun checkAddBtnClick(){
onView(ViewMatchers.withId(R.id.searchList))
val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)

createMockInvocation()
createMockAuthenticator()

val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)

checkRecyclerSubViews(R.id.searchList, 0, withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), R.id.addFriendBtn);
checkRecyclerSubViews(R.id.searchList, 0, withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE), R.id.addedFriendIcon);
onView(withId(R.id.searchList))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
2,
0,
clickOnViewChild(R.id.addFriendBtn))
)
checkRecyclerSubViews(R.id.searchList, 0, withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE), R.id.addFriendBtn);
checkRecyclerSubViews(R.id.searchList, 0, withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), R.id.addedFriendIcon);
}

/**
Expand All @@ -98,6 +185,32 @@ class SearchUserActivityTest {

override fun getDescription() = "Click on a child view with specified id."

override fun perform(uiController: UiController, view: View) = click().perform(uiController, view.findViewById<View>(viewId))
override fun perform(uiController: UiController, view: View) = click().perform(uiController, view.findViewById(viewId))
}

/**
* Custom functions to match the item views inside Recycle View
*/
fun checkRecyclerSubViews( recyclerViewId: Int, position: Int, itemMatcher: Matcher<View?>, subViewId: Int) {
onView(withId(recyclerViewId)).perform(
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
position
)
)
.check(matches(atPositionOnView(position, itemMatcher, subViewId)))
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
}

fun atPositionOnView(position: Int, itemMatcher: Matcher<View?>, targetViewId: Int): Matcher<View?> {
return object : BoundedMatcher<View?, RecyclerView>(RecyclerView::class.java) {
override fun describeTo(description: Description) {
description.appendText("has view id $itemMatcher at position $position")
}

override fun matchesSafely(recyclerView: RecyclerView): Boolean {
val viewHolder = recyclerView.findViewHolderForAdapterPosition(position)
val targetView = viewHolder!!.itemView.findViewById<View>(targetViewId)
return itemMatcher.matches(targetView)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ch.sdp.vibester.profile

import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.user.User
import ch.sdp.vibester.user.UserProfileAdapter
import org.hamcrest.CoreMatchers
Expand All @@ -15,7 +17,7 @@ class UserProfileAdapterTest {
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val users: MutableList<User> = arrayListOf()
users.addAll(listOf(user1, user2))
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users)
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter())
MatcherAssert.assertThat(userProfileViewHolder.itemCount, CoreMatchers.equalTo(2))
}

Expand All @@ -25,7 +27,7 @@ class UserProfileAdapterTest {
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val users: MutableList<User> = arrayListOf()
users.addAll(listOf(user1, user2))
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users)
val userProfileViewHolder: RecyclerView.Adapter<UserProfileAdapter.UserProfileViewHolder> = UserProfileAdapter(users, FireBaseAuthenticator(), DataGetter())
val defaultType = 0
MatcherAssert.assertThat(
userProfileViewHolder.getItemViewType(0),
Expand Down
Loading