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

Jwen/redesign profile add ranking #273

Merged
merged 23 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package ch.sdp.vibester.activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.CalendarContract.CalendarCache.URI
import android.widget.ImageView
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
Expand Down Expand Up @@ -48,11 +46,11 @@ class ProfileActivityTest {
}

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

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

private fun createMockUser(): FirebaseUser {
Expand Down Expand Up @@ -95,7 +93,7 @@ class ProfileActivityTest {

@Test
fun checkProfileData() {
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8)
Copy link
Collaborator

@Tsathogguaa Tsathogguaa May 9, 2022

Choose a reason for hiding this comment

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

Same here, basically if possible, all the URLS lol

val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)

Expand All @@ -106,14 +104,20 @@ class ProfileActivityTest {
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.username)).check(matches(withText(inputProfile.username)))
onView(withId(R.id.correctSongs)).check(matches(withText(inputProfile.correctSongs.toString())))
onView(withId(R.id.totalGames)).check(matches(withText(inputProfile.totalGames.toString())))
onView(withId(R.id.ranking)).check(matches(withText(inputProfile.ranking.toString())))
onView(withId(R.id.profile_total_games_stat)).check(matches(withText(inputProfile.totalGames.toString())))
}

@Test
fun clickBackToMain(){
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
fun clickScoresShowScores() {
val scorePerGenre: Map<String, Int> = mapOf(
"top tracks" to 1,
"kpop" to 2,
"rock" to 3,
"BTS" to 4,
"Imagine Dragons" to 5,
"Billie Eilish" to 6)
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing with the link here. It seems to be the same one as the previous comment

12, scores = scorePerGenre)
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)

Expand All @@ -122,14 +126,37 @@ class ProfileActivityTest {
createMockImageGetter()

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.profile_scores)).perform(click())

onView(withId(R.id.profile_scroll_stat)).check(matches(isDisplayed()))

onView(withId(R.id.profile_top_tracks)).check(matches(withText(inputProfile.scores.getOrDefault("top tracks", 0).toString())))
onView(withId(R.id.profile_kpop)).check(matches(withText(inputProfile.scores.getOrDefault("kpop", 0).toString())))
onView(withId(R.id.profile_rock)).check(matches(withText(inputProfile.scores.getOrDefault("rock", 0).toString())))
onView(withId(R.id.profile_bts)).check(matches(withText(inputProfile.scores.getOrDefault("BTS", 0).toString())))
onView(withId(R.id.profile_imagine_dragons)).check(matches(withText(inputProfile.scores.getOrDefault("Imagine Dragons", 0).toString())))
onView(withId(R.id.profile_billie_eilish)).check(matches(withText(inputProfile.scores.getOrDefault("Billie Eilish", 0).toString())))
}

@Test
fun clickBackToMain(){
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a test class so shouldn't be an issue, but would it be possible to put links in strings.xml? It would help others with understanding where that link leads to

val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)

createMockDataGetter(inputProfile)
createMockAuthenticatorInvocation()
createMockImageGetter()

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.profile_returnToMain)).perform(click())

Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name))
}

@Test
fun shouldShowQrCode() {
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0)
val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8)

val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
Expand All @@ -139,16 +166,16 @@ class ProfileActivityTest {
createMockImageGetter()

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

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

onView(withId(R.id.QrCodePage)).check(matches(isDisplayed()))
onView(withId(R.id.profileContent)).check(matches(not(isDisplayed())))
onView(withId(R.id.qrCode)).check(matches(isDisplayed()))
}

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

Expand All @@ -159,14 +186,15 @@ class ProfileActivityTest {
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.showQRCode)).perform(click())
onView(withId(R.id.qrCode_returnToProfile)).perform(click())

onView(withId(R.id.QrCodePage)).check(matches(not(isDisplayed())))
onView(withId(R.id.profileContent)).check(matches(isDisplayed()))
}


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

Expand All @@ -176,18 +204,20 @@ class ProfileActivityTest {

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
val newUsername = "Lalisa Bon idomesniu"

onView(withId(R.id.editUser)).perform(click())
onView(withId(0)).perform(
ViewActions.typeText(newUsername),
ViewActions.closeSoftKeyboard()
)
onView(withText("OK")).perform(click())

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

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

Expand All @@ -196,15 +226,15 @@ class ProfileActivityTest {
createMockImageGetter()

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

onView(withId(R.id.editUser)).perform(click())
onView(withText("Cancel")).perform(click())

onView(withId(R.id.username)).check(matches(withText("Lalisa Bon")))
}

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

Expand All @@ -214,12 +244,13 @@ class ProfileActivityTest {

val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.showQRCode)).perform(click())

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

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

Expand Down
40 changes: 29 additions & 11 deletions app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import android.graphics.*
import android.net.Uri
import android.os.Bundle
import android.text.InputType
import android.util.Log
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.Window
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -69,6 +65,7 @@ class ProfileActivity : AppCompatActivity() {
setRetToMainBtnListener()
setShowQrCodeBtnListener()
setQrCodeToProfileBtnListener()
setScoreBtnListener()

queryDatabase()
}
Expand Down Expand Up @@ -107,7 +104,7 @@ class ProfileActivity : AppCompatActivity() {
* Generic listener for the show qr code button.
*/
private fun setShowQrCodeBtnListener() {
findViewById<Button>(R.id.showQRCode).setOnClickListener {
findViewById<ImageView>(R.id.showQRCode).setOnClickListener {
setLayoutVisibility(R.id.QrCodePage, true)
setLayoutVisibility(R.id.profileContent, false)
}
Expand All @@ -123,9 +120,27 @@ class ProfileActivity : AppCompatActivity() {
}
}

/**
* Generic listener for the score button, show the score per genre statistic on click
*/
private fun setScoreBtnListener() {
findViewById<Button>(R.id.profile_scores).setOnClickListener {
toggleVisibility(R.id.profile_scroll_stat)
}
}

/**
* toggle the given layout's visibility
* @param layout: The given ScrollView id to modify
*/
private fun toggleVisibility(layout: Int) {
if (findViewById<ScrollView>(layout).visibility == VISIBLE) findViewById<ScrollView>(layout).visibility = GONE
else if (findViewById<ScrollView>(layout).visibility == GONE) findViewById<ScrollView>(layout).visibility = VISIBLE
}

/**
* Sets the given layout's visibility.
* @param layout: The given layout to modify.
* @param layout: The given constraint layout to modify.
* @param isVisible: The indicator of which visibility to choose.
* True for VISIBLE, false for GONE.
*/
Expand Down Expand Up @@ -226,10 +241,13 @@ class ProfileActivity : AppCompatActivity() {
* @param user: The user from which we will recover the text to set.
*/
private fun setTextOfMultipleViews(user: User) {
setTextOfView(R.id.totalGames, user.totalGames)
setTextOfView(R.id.correctSongs, user.correctSongs)
setTextOfView(R.id.bestScore, user.bestScore)
setTextOfView(R.id.ranking, user.ranking)
setTextOfView(R.id.profile_total_games_stat, user.totalGames)
setTextOfView(R.id.profile_top_tracks, user.scores.getOrDefault("top tracks", 0))
setTextOfView(R.id.profile_kpop, user.scores.getOrDefault("kpop", 0))
setTextOfView(R.id.profile_rock, user.scores.getOrDefault("rock", 0))
setTextOfView(R.id.profile_bts, user.scores.getOrDefault("BTS", 0))
setTextOfView(R.id.profile_imagine_dragons, user.scores.getOrDefault("Imagine Dragons", 0))
setTextOfView(R.id.profile_billie_eilish, user.scores.getOrDefault("Billie Eilish", 0))
}

/**
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/ch/sdp/vibester/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ data class User(
var image: String = "",
var email: String = "",
var totalGames: Int = 0,
var bestScore: Int = 0,
var correctSongs: Int = 0,
var ranking: Int = 0,
var uid: String = "",
var friends: Map<String, Boolean> = mapOf(),
Expand Down
Binary file added app/src/main/res/drawable/qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading