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

Kamila/remove handle #202

Merged
merged 6 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -41,7 +41,7 @@ class CreateProfileActivityTest {
val mockUsersRepo = mockk<UsersRepo>()

private fun createMockInvocation(email: String) {
every {mockUsersRepo.createUser(any(), any(), any(), any())} answers {
every {mockUsersRepo.createUser(any(), any(), any())} answers {
lastArg<(String) -> Unit>().invoke(email)
}

Expand All @@ -58,7 +58,6 @@ class CreateProfileActivityTest {
@Test
fun createAccCorrect() {
var username = "mockUsername"
var handle = "mockHandle"
var mockEmail = "[email protected]"

val intent = Intent(ApplicationProvider.getApplicationContext(), CreateProfileActivity::class.java)
Expand All @@ -71,9 +70,7 @@ class CreateProfileActivityTest {
onView(withId(R.id.accountUsername)).perform(ViewActions.typeText(username),
ViewActions.closeSoftKeyboard()
)
onView(withId(R.id.accountHandle)).perform(ViewActions.typeText(handle),
ViewActions.closeSoftKeyboard()
)

onView(withId(R.id.createButton)).perform(ViewActions.click())

Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ class ProfileActivityTest {

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

createMockInvocation(inputProfile)
UserSharedPref.setUser(ctx, inputProfile, false)
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.handle)).check(matches(withText(inputProfile.handle)))
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())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,4 @@ class ScoreBoardActivityTest {
)
}
}

@Test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this test is removed? Does it relate to handle?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The order of the users in the firebase is not deterministic. We have been deleting/adding users, so the user positions always change. I believe the removal of the test will not decrease any coverage of your changes

fun recycleViewShowItemTest() {
onView(withId(R.id.recycler_view)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
5,
click()
)
)
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 @@ -69,6 +69,7 @@ class SearchUserActivityTest {
)
}
}

@Test
fun recycleViewCheckEmpty() {
val inputTxt= "TESTESTESTEST"
Expand All @@ -78,6 +79,7 @@ class SearchUserActivityTest {
val itemCount = recyclerView.adapter?.itemCount
assertEquals(itemCount, null)
}

@Test
fun checkAddBtnClick(){
onView(ViewMatchers.withId(R.id.searchList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class UserSharedPrefTest {
val mailTest = "[email protected]"
UserSharedPref.userReset(ctx, mailTest)
UserSharedPref.updateUsername(ctx, "Lalisa Bon")
UserSharedPref.updateHandle(ctx, "@lisa")
UserSharedPref.updateScore(ctx)
Thread.sleep(1000)
// assertEquals(mailTest, UserSharedPref.getUser(ctx).email) //TODO temporary disable does not pass on CI
Expand All @@ -23,7 +22,6 @@ class UserSharedPrefTest {
@Test
fun sharedPrefTest2(){
val ctx = ApplicationProvider.getApplicationContext() as Context
val handle: String = "myHandle"
val username: String = "myUsername"
val image: String = "myImage"
val email: String = "myEmail"
Expand All @@ -32,13 +30,12 @@ class UserSharedPrefTest {
val correctSongs: Int = 16
val ranking: Int = 6

val pro = User(handle, username, image, email, totalGames, bestScore, correctSongs, ranking)
val pro = User(username, image, email, totalGames, bestScore, correctSongs, ranking)
UserSharedPref.setUser(ctx, pro, false)
UserSharedPref.updateScore(ctx, 1, -1, 0, 1)
Thread.sleep(1000)
val updated = UserSharedPref.getUser(ctx)

assertEquals(pro.handle, updated.handle)
assertEquals(pro.username, updated.username)
assertEquals(pro.image, updated.image)
assertEquals(pro.email, updated.email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class UserProfileAdapterTest {

@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 user1 = User("test1", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "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)
Expand All @@ -21,8 +21,8 @@ class UserProfileAdapterTest {

@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 user1 = User("test1", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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 user1 = User("test1","https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2","https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> =
Expand All @@ -24,8 +24,8 @@ class UserScoreboardAdapterTest {

@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 user1 = User("test1", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> =
Expand All @@ -36,8 +36,8 @@ class UserScoreboardAdapterTest {

@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 user1 = User("test1", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val players: MutableList<User> = arrayListOf()
players.addAll(listOf(user1, user2))
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext())
Expand All @@ -46,22 +46,22 @@ class UserScoreboardAdapterTest {
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]"))
newPlayers.add(User("test3","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 user1 = User("test1", "https://images.app.goo.gl/yiPpy7JDRFaZRiAg9", "[email protected]")
val user2 = User("test2", "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 player3 = User("test3","https://images.app.goo.gl/YkBi16zwyjB7ejj96", "[email protected]")
val updatedList = arrayListOf(player3)
playerAdapter.addPlayers(updatedList)
assertThat(playerAdapter.players == updatedList, equalTo(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class CreateProfileActivity : AppCompatActivity() {

val email = intent.getStringExtra("email").toString()
val username = findViewById<EditText>(R.id.accountUsername)
val handle = findViewById<EditText>(R.id.accountHandle)

val btCreateAcc = findViewById<Button>(R.id.createButton)
val btnUploadImg = findViewById<Button>(R.id.uploadImg)
Expand All @@ -40,7 +39,6 @@ class CreateProfileActivity : AppCompatActivity() {
usersRepo.createUser(
email,
username.text.toString(),
handle.text.toString(),
this::startNewActivity)
}

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class ProfileActivity : AppCompatActivity() {
showGeneralDialog(R.id.username, "username")
}

editHandle.setOnClickListener {
showGeneralDialog(R.id.handle, "handle")
}

retToMain.setOnClickListener{
IntentSwitcher.switchBackToWelcome(this)
}
Expand Down Expand Up @@ -93,8 +89,6 @@ class ProfileActivity : AppCompatActivity() {

if(name == "username"){
UserSharedPref.updateUsername(this, input.text.toString())
}else if (name == "handle"){
UserSharedPref.updateHandle(this, input.text.toString())
}
}

Expand Down Expand Up @@ -127,9 +121,6 @@ class ProfileActivity : AppCompatActivity() {
// Currently assuming that empty username means no user !
if (user.username != ""){
findViewById<TextView>(R.id.username).text = user.username
if (user.handle != ""){
findViewById<TextView>(R.id.handle).text = user.handle
}
findViewById<TextView>(R.id.totalGames).text = user.totalGames.toString()
findViewById<TextView>(R.id.correctSongs).text = user.correctSongs.toString()
findViewById<TextView>(R.id.bestScore).text = user.bestScore.toString()
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/ch/sdp/vibester/database/UsersRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ class UsersRepo @Inject constructor() {
* This function creates a new user account in the database
* @param email the email of the new user
* @param username the username of the new user
* @param handle the handle of the new user
* @param callback function to be called when the the user has been created
*/
fun createUser(email: String, username: String, handle: String, callback: (String) -> Unit) {
var newUser = User(handle, username, "", email, 0, 0, 0, 0)
fun createUser(email: String, username: String, callback: (String) -> Unit) {
var newUser = User(username, "", email, 0, 0, 0, 0)
val newId = Util.createNewId()
dbRef.child(newId).setValue(newUser)
.addOnSuccessListener {
Expand Down
24 changes: 2 additions & 22 deletions app/src/main/java/ch/sdp/vibester/model/UserSharedPref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import java.util.*
*/
class UserSharedPref private constructor() {
companion object{
val HANDLE = "handle"
val USERNAME = "username"
val IMAGE = "image"
val EMAIL = "email"
Expand Down Expand Up @@ -54,7 +53,6 @@ class UserSharedPref private constructor() {
fun setUser(ctx: Context, user: User, online: Boolean){
val edit = getSharedPreferences(ctx)?.edit()
if (edit != null) {
edit.putString(HANDLE, user.handle)
edit.putString(USERNAME, user.username)
edit.putString(IMAGE, user.image)
edit.putString(EMAIL, user.email)
Expand Down Expand Up @@ -114,23 +112,6 @@ class UserSharedPref private constructor() {
}
}

/**
* Update the handle locally and in db (if enabled for the user)
* @param Context The app context
* @param handle new handle
*/
fun updateHandle(ctx: Context, handle: String){
val sharedPref = getSharedPreferences(ctx)
if(sharedPref != null){
val edit = sharedPref.edit()
edit.putString(HANDLE, handle)
if(sharedPref.getBoolean(ONLINE, false)) {
dbAccess.updateFieldString("testUser", handle, "handle")
}
edit.commit()
}
}


/**
* Getter for locally store profile
Expand All @@ -140,7 +121,6 @@ class UserSharedPref private constructor() {
fun getUser(ctx: Context): User {
val sharedPref = getSharedPreferences(ctx)

var handle = ""
var username = ""
var image = ""
var email = ""
Expand All @@ -150,7 +130,6 @@ class UserSharedPref private constructor() {
var ranking = -1

if(sharedPref != null) {
handle = sharedPref.getString(HANDLE, "").toString()
username = sharedPref.getString(USERNAME, "").toString()
image = sharedPref.getString(IMAGE, "").toString()
email = sharedPref.getString(EMAIL, "").toString()
Expand All @@ -159,7 +138,8 @@ class UserSharedPref private constructor() {
correctSongs = sharedPref.getInt(CORRECT_SONGS, 0)
ranking = sharedPref.getInt(RANKING, 0)
}
return User(handle, username, image, email, totalGames, bestScore, correctSongs, ranking)
return User(username, image, email, totalGames, bestScore, correctSongs, ranking)

}


Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/ch/sdp/vibester/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.sdp.vibester.user
import java.io.Serializable

data class User(
var handle: String = "",
var username: String = "",
var image: String = "",
var email: String = "",
Expand Down
Loading