Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Adding Friend Page features after reset #43

Merged
merged 26 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34dc8b1
Re-Adding Friend Page features after reset
bhvrgav Mar 24, 2022
5bf2ed8
Implemented Button Clickability
bhvrgav Mar 29, 2022
5c2857d
Merge branch 'main' into feat/friendspage
bhvrgav Mar 29, 2022
5b71e18
Merge branch 'main' into feat/friendspage
bhvrgav Mar 31, 2022
ece49de
Add Friends Page to bottom navigation
bhvrgav Mar 31, 2022
703a9a3
Attempt to write tests
bhvrgav Mar 31, 2022
63bfe88
Merge branch 'main' into feat/friendspage
bhvrgav Apr 2, 2022
34a7cea
Added PlayerInfo Fragment & Navigations
bhvrgav Apr 2, 2022
8706c33
Created DataObject to pass dummy info
bhvrgav Apr 2, 2022
7a4694f
Create Data Object for Mock Data & Wrote some tests
bhvrgav Apr 2, 2022
bb67074
Connected InfoPage, Added navigation and wrote tests
bhvrgav Apr 4, 2022
7469ed7
Merge with main
bhvrgav Apr 4, 2022
8f9c6bb
Revert "Merge with main"
bhvrgav Apr 4, 2022
4ba4d52
Revert "Revert "Merge with main""
bhvrgav Apr 4, 2022
b5c17e1
Removed an unnecessary fragment
bhvrgav Apr 4, 2022
a7d7c5a
Merge branch 'main' into feat/friendspage
bhvrgav Apr 6, 2022
6f93947
Small edit in tests
bhvrgav Apr 6, 2022
70d5aab
Merge branch 'main' into feat/friendspage
bhvrgav Apr 6, 2022
573be61
Fixed git issue
bhvrgav Apr 6, 2022
4512f66
minor addition
bhvrgav Apr 7, 2022
2e56644
Merge branch 'main' into feat/friendspage
gaetschwartz Apr 7, 2022
77c0d6a
Fix for navigation error
bhvrgav Apr 7, 2022
c9c12e4
Changed location of FriendsInfo data file
bhvrgav Apr 7, 2022
695c7ec
Merge branch 'main' into feat/friendspage
bhvrgav Apr 7, 2022
12fd236
Fixed build for bar
leonardopennino Apr 7, 2022
3227ad9
Remove checkBackHome test
bhvrgav Apr 7, 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
48 changes: 48 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package ch.epfl.sweng.rps.ui.friends

import android.view.View
import android.widget.ImageButton
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import ch.epfl.sweng.rps.FriendListAdapter
import ch.epfl.sweng.rps.MainActivity
import ch.epfl.sweng.rps.R
import ch.epfl.sweng.rps.models.FakeFriendsData
import org.hamcrest.Matcher

import org.junit.Rule
import org.junit.Test


class FriendsFragmentTest {

val LIST_ITEM = FakeFriendsData.myFriendsData.size - 1
val thisFriend = FakeFriendsData.myFriendsData[LIST_ITEM]

@Rule
@JvmField
val activityRule = ActivityScenarioRule(MainActivity::class.java)

@Test
fun checkFriendsFragment(){
onView(withId(R.id.nav_friends)).perform(click())
onView(withId(R.id.fragment_friends)).check(matches(isDisplayed()))
}

@Test
fun test_isRecyclerViewVisible_onLaunch() {
onView(withId(R.id.nav_friends)).perform(click())
onView(withId(R.id.friendListRecyclerView)).check(matches(isDisplayed()))
}

@Test
fun test_FriendInfoFragmentShown_onInfoButtonClick() {
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.fragment_info_page)).check(matches(isDisplayed()))
}

@Test
fun test_GameFragmentShown_onPlayButtonClick() {
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickPlayButton(R.id.playButton)))

onView(withId(R.id.fragment_game)).check(matches(isDisplayed()))
}

@Test
fun test_CorrectGamesPlayedShows_onInfoButtonClick(){
val gamesPlayed = thisFriend.gamesPlayed
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.gamesPlayedText_infoPage)).check(matches(withText("Games Played: $gamesPlayed")))
}
@Test
fun test_CorrectGamesWonShows_onInfoButtonClick(){
val gamesWon = thisFriend.gamesWon
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.gamesWonText_infoPage)).check(matches(withText("Games Won: $gamesWon")))
}

@Test
fun test_CorrectUserNameShows_onInfoButtonClick(){

onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.userName_infoPage)).check(matches(withText(thisFriend.username)))
}

@Test
fun test_CorrectWinRateShows_onInfoButtonClick(){
val winRate = thisFriend.winRate
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.winRateText_infoPage)).check(matches(withText("Win Rate: $winRate%")))
}

@Test
fun test_offlineStatusShows_onInfoButtonClick(){
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.offlineImage_infoPage)).check(matches(isDisplayed()))
}

@Test
fun test_onlineStatusShows_onInfoButtonClick(){
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(0,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.onlineImage_infoPage)).check(matches(isDisplayed()))
}

@Test
fun test_returnsToFriendFragment_onBackButtonClick(){
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.infoPage_backButton)).perform(click())

onView(withId(R.id.fragment_friends)).check(matches(isDisplayed()))
}

@Test
fun test_goesToGameFragment_onPlayButtonClick(){
onView(withId(R.id.nav_friends)).perform(click())

onView(withId(R.id.friendListRecyclerView))
.perform(actionOnItemAtPosition<FriendListAdapter.CardViewHolder>(LIST_ITEM,ClickButtonAction.clickInfoButton(R.id.infoButton)))

onView(withId(R.id.infoPage_playButton)).perform(click())

onView(withId(R.id.fragment_game)).check(matches(isDisplayed()))
}

}
class ClickButtonAction {
companion object {
fun clickInfoButton(childId: Int): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return isAssignableFrom(ImageButton::class.java)
}

override fun getDescription(): String {
return "InfoButton Clicked"
}

override fun perform(uiController: UiController?, view: View?) {
val v = view?.findViewById<ImageButton>(childId)
v?.performClick()
}

}
}

fun clickPlayButton(childId: Int): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return isAssignableFrom(ImageButton::class.java)
}

override fun getDescription(): String {
return "PlayButton Clicked"
}

override fun perform(uiController: UiController?, view: View?) {
val v = view?.findViewById<ImageButton>(childId)
v?.performClick()
}

}
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/ch/epfl/sweng/rps/models/FakeFriendsData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ch.epfl.sweng.rps.models

import ch.epfl.sweng.rps.ui.friends.FriendsInfo

object FakeFriendsData {
val myFriendsData = listOf(
FriendsInfo("RPSKing88", 120, 76, 63.3, true),
FriendsInfo("Meliodas19", 220, 110, 50.0, true),
FriendsInfo("Urtrash", 86, 32, 37.2, true),
FriendsInfo("Ben10", 14, 12, 85.7, true),
FriendsInfo("JustGary", 455, 343, 75.4, false),
FriendsInfo("RockFirst", 141, 118, 83.7, false),
FriendsInfo("ulose", 63, 28, 44.4, false),
FriendsInfo("GameMstr", 90, 12, 13.3, false),
FriendsInfo("Narut0", 312, 211, 67.6, false),
FriendsInfo("Insomnix", 166, 65, 39.2, false),
FriendsInfo("JustGary", 455, 343, 75.4, false),
FriendsInfo("RockFirst", 141, 118, 83.7, false),
FriendsInfo("ulose", 63, 28, 44.4, false)
)
}
78 changes: 78 additions & 0 deletions app/src/main/java/ch/epfl/sweng/rps/ui/friends/FriendsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ch.epfl.sweng.rps.ui.friends

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.epfl.sweng.rps.FriendListAdapter
import ch.epfl.sweng.rps.R
import ch.epfl.sweng.rps.models.FakeFriendsData


class FriendsFragment : Fragment(), FriendListAdapter.OnButtonClickListener {


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_friends, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val friends = FakeFriendsData.myFriendsData
val recyclerView = view.findViewById<RecyclerView>(R.id.friendListRecyclerView)


//Get info from Fake Data object and display
recyclerView.layoutManager = LinearLayoutManager(activity)
recyclerView.adapter = FriendListAdapter(friends, this)

}
//Button Click Listeners
override fun onButtonClick(position: Int,friends: List<FriendsInfo>, view: View) {
val username = friends[position].username
val gamesPlayed = friends[position].gamesPlayed
val gamesWon = friends[position].gamesWon
val winRate = friends[position].winRate
val isOnline = friends[position].isOnline


//if info button is clicked
if (view == view.findViewById(R.id.infoButton)) {
Log.i("Press info", "This is $username's info")
Toast.makeText(activity, "This is $username's info", Toast.LENGTH_SHORT).show()
//Move to infoPage on button click
findNavController().navigate(R.id.action_nav_friends_to_infoPage_Fragment, Bundle().apply {
//Passing all the info to be displayed in the Info Page
putString("userName", username)
putString("gamesPlayed", "Games Played: $gamesPlayed")
putString("gamesWon", "Games Won: $gamesWon")
putString("winRate", "Win Rate: $winRate%")
putBoolean("isOnline", isOnline)
})

}
//if play button is clicked
else if (view == view.findViewById(R.id.playButton)){
Log.i("Press info", "You will play a game with $username")
Toast.makeText(activity, "You will play a game with $username", Toast.LENGTH_SHORT).show()

//Move to game fragment on button click
findNavController().navigate(R.id.action_nav_friends_to_gameFragment)
}
}



}
12 changes: 12 additions & 0 deletions app/src/main/java/ch/epfl/sweng/rps/ui/friends/FriendsInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ch.epfl.sweng.rps.ui.friends

data class FriendsInfo(
val username : String,
val gamesPlayed : Int,
val gamesWon : Int,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit weird to me to have this class here. But I am not sure. Maybe this could be in models??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, let me move that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will also work on changing to UI in the next sprint to match the rest of the application. Didn't have enough time for that this week

val winRate : Double,
val isOnline : Boolean
)



Loading