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

Jwen/set up scoreboard per playlist #203

Merged
merged 11 commits into from
Apr 26, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import org.hamcrest.CoreMatchers.not
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -22,12 +23,22 @@ class ScoreBoardActivityTest {
val activityRule = ActivityScenarioRule(ScoreBoardActivity::class.java)

@Test
fun recycleViewToViewTest() {
fun genreShouldDisappearAfterSelected() {
onView(withId(R.id.genrePerScoreboard)).check(matches(isDisplayed()))
onView(withId(R.id.rockButton)).perform(click())
onView(withId(R.id.genrePerScoreboard)).check(matches(not(isDisplayed())))
}

@Test
fun rockBtnShouldSetUpRecycleVie() {
Copy link
Owner

@MaximeZmt MaximeZmt Apr 26, 2022

Choose a reason for hiding this comment

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

Suggested change
fun rockBtnShouldSetUpRecycleVie() {
fun rockBtnShouldSetUpRecycleView() {

I think this is a typo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this typo still exist? I remember fixing it in commit 5b54240

onView(withId(R.id.rockButton)).perform(click())
onView(withId(R.id.recycler_view)).check(matches(isDisplayed()))
}

@Test
fun recycleViewClickTest() {
fun rockBtnShouldEnableRecycleViewClickTest() {
onView(withId(R.id.rockButton)).perform(click())

onView((withId(R.id.recycler_view)))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
Expand All @@ -36,6 +47,31 @@ class ScoreBoardActivityTest {
)
}

@Test
fun topBtnClick() {
onView(withId(R.id.topTracksButton)).perform(click())
}

@Test
fun kpopBtnClick() {
onView(withId(R.id.kpopButton)).perform(click())
}

@Test
fun billieEilishButtonClick() {
onView(withId(R.id.billieEilishButton)).perform(click())
}

@Test
fun imagineDragonsButtonClick() {
onView(withId(R.id.imagDragonsButton)).perform(click())
}

@Test
fun btsButtonClick() {
onView(withId(R.id.btsButton)).perform(click())
}
Comment on lines +50 to +73
Copy link
Owner

Choose a reason for hiding this comment

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

Here it clicks, but does not miss a verification ? What should it test ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Normally, the verification of each should be the same as in rockBtnShouldSetUpRecycleView() and rockBtnShouldEnableRecycleViewClick(), but they are all testing the same lines of code, so to speed up CI and have the coverage rate, I just do click on each of them without the actual verification.


@Test
fun recycleViewScrollDownTest() {
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
Expand Down
29 changes: 26 additions & 3 deletions app/src/main/java/ch/sdp/vibester/activity/ScoreBoardActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package ch.sdp.vibester.activity
import android.content.ContentValues
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
Expand All @@ -26,7 +30,26 @@ class ScoreBoardActivity : AppCompatActivity() {
setSupportActionBar(findViewById(R.id.toolbar))
setupRecycleView()
players = ArrayList()
loadPlayers()
}

/**
* TODO: replace "ranking" by appropriate label
*/
fun selectScoreboard(view: View) {
var sortedBy = ""
when (view.id) {
R.id.btsButton -> sortedBy = "ranking"
R.id.kpopButton -> sortedBy = "ranking"
R.id.imagDragonsButton -> sortedBy = "ranking"
R.id.billieEilishButton -> sortedBy = "ranking"
R.id.rockButton -> sortedBy = "ranking"
R.id.topTracksButton -> sortedBy = "ranking"
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
R.id.btsButton -> sortedBy = "ranking"
R.id.kpopButton -> sortedBy = "ranking"
R.id.imagDragonsButton -> sortedBy = "ranking"
R.id.billieEilishButton -> sortedBy = "ranking"
R.id.rockButton -> sortedBy = "ranking"
R.id.topTracksButton -> sortedBy = "ranking"
R.id.btsButton -> sortedBy = "ranking"
R.id.kpopButton -> sortedBy = "ranking"
R.id.imagDragonsButton -> sortedBy = "ranking"
R.id.billieEilishButton -> sortedBy = "ranking"
R.id.rockButton -> sortedBy = "ranking"
R.id.topTracksButton -> sortedBy = "ranking"

Could store "ranking" into string.xml ? easier to modify after

}

findViewById<ConstraintLayout>(R.id.genrePerScoreboard).visibility = GONE
findViewById<ConstraintLayout>(R.id.scoreboard).visibility = VISIBLE

loadPlayersSortedBy(sortedBy)
}

private fun setupRecycleView() {
Expand All @@ -37,8 +60,8 @@ class ScoreBoardActivity : AppCompatActivity() {
}
}

private fun loadPlayers() {
dbRef.orderByChild("ranking")
private fun loadPlayersSortedBy(order: String) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

UsersRepo contains all the firebase calls connected with "users", should this function be moved there?

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 see what you mean, however, It's more logical for me to put it here because this function is only used locally in scoreboard activity to load the data into the scoreboard.

dbRef.orderByChild(order)
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshots: DataSnapshot) {
for (snapshot in snapshots.children) {
Expand Down
98 changes: 1 addition & 97 deletions app/src/main/res/layout/activity_game_setup_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,104 +247,8 @@
app:layout_constraintTop_toBottomOf="@+id/difficulty_explanation" />
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/chooseGenre"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<include layout="@layout/game_genre" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/billieEilishButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="Billie Eilish"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.687" >
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/imagDragonsButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="Imagine Dragons"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.066"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.687" >
</androidx.appcompat.widget.AppCompatButton>


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btsButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:background="@drawable/rounded_button"
android:onClick="chooseGenre"
android:text="BTS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.402" >
</androidx.appcompat.widget.AppCompatButton>


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/rockButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="R O C K"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.403">
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/kpopButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="K P O P"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.937"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.136">
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/topTracksButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:background="@drawable/rounded_button"
android:onClick="chooseGenre"
android:text="T O P T R A C K S"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.074"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.136">
</androidx.appcompat.widget.AppCompatButton>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>


Expand Down
106 changes: 106 additions & 0 deletions app/src/main/res/layout/game_genre.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/chooseGenre"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/billieEilishButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="@string/billie_eilish"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.687" >
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/imagDragonsButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="@string/imagine_dragons"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.066"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.687" >
</androidx.appcompat.widget.AppCompatButton>


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btsButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:background="@drawable/rounded_button"
android:onClick="chooseGenre"
android:text="@string/bts"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.402" >
</androidx.appcompat.widget.AppCompatButton>


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/rockButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="@string/r_o_c_k"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.403">
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/kpopButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:onClick="chooseGenre"
android:background="@drawable/rounded_button"
android:text="@string/k_p_o_p"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.937"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.136">
</androidx.appcompat.widget.AppCompatButton>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/topTracksButton"
android:layout_width="170dp"
android:layout_height="130dp"
android:background="@drawable/rounded_button"
android:onClick="chooseGenre"
android:text="@string/t_o_p_t_r_a_c_k_s"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.074"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.136">
</androidx.appcompat.widget.AppCompatButton>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading