-
Notifications
You must be signed in to change notification settings - Fork 1
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
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 5bf2ed8
Implemented Button Clickability
bhvrgav 5c2857d
Merge branch 'main' into feat/friendspage
bhvrgav 5b71e18
Merge branch 'main' into feat/friendspage
bhvrgav ece49de
Add Friends Page to bottom navigation
bhvrgav 703a9a3
Attempt to write tests
bhvrgav 63bfe88
Merge branch 'main' into feat/friendspage
bhvrgav 34a7cea
Added PlayerInfo Fragment & Navigations
bhvrgav 8706c33
Created DataObject to pass dummy info
bhvrgav 7a4694f
Create Data Object for Mock Data & Wrote some tests
bhvrgav bb67074
Connected InfoPage, Added navigation and wrote tests
bhvrgav 7469ed7
Merge with main
bhvrgav 8f9c6bb
Revert "Merge with main"
bhvrgav 4ba4d52
Revert "Revert "Merge with main""
bhvrgav b5c17e1
Removed an unnecessary fragment
bhvrgav a7d7c5a
Merge branch 'main' into feat/friendspage
bhvrgav 6f93947
Small edit in tests
bhvrgav 70d5aab
Merge branch 'main' into feat/friendspage
bhvrgav 573be61
Fixed git issue
bhvrgav 4512f66
minor addition
bhvrgav 2e56644
Merge branch 'main' into feat/friendspage
gaetschwartz 77c0d6a
Fix for navigation error
bhvrgav c9c12e4
Changed location of FriendsInfo data file
bhvrgav 695c7ec
Merge branch 'main' into feat/friendspage
bhvrgav 12fd236
Fixed build for bar
leonardopennino 3227ad9
Remove checkBackHome test
bhvrgav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
190 changes: 190 additions & 0 deletions
190
app/src/androidTest/java/ch/epfl/sweng/rps/ui/friends/FriendsFragmentTest.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,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
21
app/src/main/java/ch/epfl/sweng/rps/models/FakeFriendsData.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,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
78
app/src/main/java/ch/epfl/sweng/rps/ui/friends/FriendsFragment.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,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
12
app/src/main/java/ch/epfl/sweng/rps/ui/friends/FriendsInfo.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,12 @@ | ||
package ch.epfl.sweng.rps.ui.friends | ||
|
||
data class FriendsInfo( | ||
val username : String, | ||
val gamesPlayed : Int, | ||
val gamesWon : Int, | ||
val winRate : Double, | ||
val isOnline : Boolean | ||
) | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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