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

Jwen/scoreboard data #197

Merged
merged 8 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dependencies {
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'junit:junit:4.13.2'
implementation 'com.google.firebase:firebase-firestore-ktx:24.0.2'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20180813'
testImplementation 'org.robolectric:robolectric:4.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.* //change this import
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.database.ImageRepo
import ch.sdp.vibester.database.UsersRepo
import ch.sdp.vibester.profile.UserProfile
import ch.sdp.vibester.user.User
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand Down Expand Up @@ -48,7 +46,7 @@ class CreateProfileActivityTest {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.* //change this import
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.database.UsersRepo
import ch.sdp.vibester.model.UserSharedPref
import ch.sdp.vibester.profile.UserProfile
import ch.sdp.vibester.user.User
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand Down Expand Up @@ -42,9 +41,9 @@ class ProfileActivityTest {
@BindValue @JvmField
val mockUsersRepo = mockk<UsersRepo>()

private fun createMockInvocation(mockProfile: UserProfile) {
private fun createMockInvocation(mockUser: User) {
every { mockUsersRepo.getUserData(any(), any()) } answers {
secondArg<(UserProfile) -> Unit>().invoke(mockProfile)
secondArg<(User) -> Unit>().invoke(mockUser)
}
every { mockUsersRepo.updateFieldString(any(), any(), any()) } answers {}
}
Expand All @@ -56,7 +55,7 @@ class ProfileActivityTest {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ScoreBoardActivityTest {
onView((withId(R.id.recycler_view)))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
2,
click()
2, click()
)
)
}
Expand All @@ -58,7 +57,7 @@ class ScoreBoardActivityTest {
click()
)
)
val nameItem = "Cinnamon Roll"
val nameItem = "YOLO" //name of the player at the 5th position
onView(withText(nameItem)).check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package ch.sdp.vibester.model

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import ch.sdp.vibester.profile.UserProfile
import org.junit.Assert
import ch.sdp.vibester.user.User
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -33,7 +32,7 @@ class UserSharedPrefTest {
val correctSongs: Int = 16
val ranking: Int = 6

val pro = UserProfile(handle, username, image, email, totalGames, bestScore, correctSongs, ranking)
val pro = User(handle, username, image, email, totalGames, bestScore, correctSongs, ranking)
UserSharedPref.setUser(ctx, pro, false)
UserSharedPref.updateScore(ctx, 1, -1, 0, 1)
Thread.sleep(1000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ch.sdp.vibester.profile

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import ch.sdp.vibester.user.User
import ch.sdp.vibester.user.UserProfileAdapter
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.junit.Test
Expand All @@ -11,19 +11,19 @@ class UserProfileAdapterTest {

@Test
fun recyclerViewShowsCorrectCount() {
val user1 = UserProfile("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = UserProfile("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val users: MutableList<UserProfile> = arrayListOf()
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "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)
MatcherAssert.assertThat(userProfileViewHolder.itemCount, CoreMatchers.equalTo(2))
}

@Test
fun itemTypeIsCorrect() {
val user1 = UserProfile("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = UserProfile("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val users: MutableList<UserProfile> = arrayListOf()
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "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 defaultType = 0
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ch.sdp.vibester.scoreboard

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import ch.sdp.vibester.user.User
import ch.sdp.vibester.user.UserScoreboardAdapter
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test


class UserScoreboardAdapterTest {
@Test
fun recyclerViewShowsCorrectCount() {
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> =
UserScoreboardAdapter(players)
assertThat(userScoreboardViewHolder.itemCount, equalTo(2))
}

@Test
fun itemTypeIsCorrect() {
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> =
UserScoreboardAdapter(players)
val defaultType = 0
assertThat(userScoreboardViewHolder.getItemViewType(0), equalTo(defaultType))
}

@Test
fun setupAdapterForRecyclerView() {
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
recyclerView.layoutManager =
LinearLayoutManager(ApplicationProvider.getApplicationContext())
val playerAdapter = UserScoreboardAdapter(players)
recyclerView.adapter = playerAdapter
val newPlayers: MutableList<User> = arrayListOf()
newPlayers.add(User("test3", "Scone", "https://images.app.goo.gl/YkBi16zwyjB7ejj96", "[email protected]"))
playerAdapter.addPlayers(newPlayers)
playerAdapter.notifyDataSetChanged()
}

@Test
fun addPlayersWorks() {
val user1 = User("test1", "Brownie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "Cookie", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
recyclerView.layoutManager =
LinearLayoutManager(ApplicationProvider.getApplicationContext())
val playerAdapter = UserScoreboardAdapter(players)
val player3 = User("test3", "Scone", "https://images.app.goo.gl/YkBi16zwyjB7ejj96", "[email protected]")
val updatedList = arrayListOf(player3)
playerAdapter.addPlayers(updatedList)
assertThat(playerAdapter.players == updatedList, equalTo(true))
}
}
9 changes: 4 additions & 5 deletions app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.drawable.toBitmap
import ch.sdp.vibester.R
import ch.sdp.vibester.api.BitmapGetterApi
import ch.sdp.vibester.model.UserSharedPref
import ch.sdp.vibester.database.UsersRepo
import ch.sdp.vibester.helper.IntentSwitcher
import ch.sdp.vibester.profile.UserProfile
import ch.sdp.vibester.user.User
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.firebase.auth.FirebaseAuth
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -47,7 +46,7 @@ class ProfileActivity : AppCompatActivity() {
val editUsername = findViewById<Button>(R.id.editUser)
val editHandle = findViewById<Button>(R.id.editHandle)

val logoutbutton = findViewById<Button>(R.id.logout)
val logoutButton = findViewById<Button>(R.id.logout)

val retToMain = findViewById<FloatingActionButton>(R.id.profile_returnToMain)

Expand All @@ -63,7 +62,7 @@ class ProfileActivity : AppCompatActivity() {
IntentSwitcher.switchBackToWelcome(this)
}

logoutbutton.setOnClickListener{
logoutButton.setOnClickListener{
FirebaseAuth.getInstance().signOut()
IntentSwitcher.switchBackToWelcome(this)
}
Expand Down Expand Up @@ -123,7 +122,7 @@ class ProfileActivity : AppCompatActivity() {
}


private fun setupProfile(user: UserProfile){
private fun setupProfile(user: User){

// Currently assuming that empty username means no user !
if (user.username != ""){
Expand Down
Loading