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

Commit

Permalink
Merge pull request #278 from MaximeZmt/kamila/fix_profile_activtiy
Browse files Browse the repository at this point in the history
ProfileActivityTests: put back profileactivity tests
  • Loading branch information
kamilababayeva authored May 12, 2022
2 parents 38f4b93 + 9a8aa7a commit e3fe186
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ch.sdp.vibester.activity

// FIXME: weird error on CI "java.lang.AssertionError: Activity never becomes requested state "[RESUMED, DESTROYED, CREATED, STARTED]" (last lifecycle transition = "PRE_ON_CREATE")"
/*
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -47,6 +45,11 @@ class ProfileActivityTest {
Intents.init()
}

@After
fun clean() {
Intents.release()
}

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

Expand Down Expand Up @@ -84,15 +87,9 @@ class ProfileActivityTest {

val mockImageURI = Uri.parse("https://raw.githubusercontent.com/Ashwinvalento/cartoon-avatar/master/lib/images/male/45.png")
private fun createMockImageGetter() {
every {mockImageGetter.fetchImage(any(), any())} answers {
secondArg<(Uri) -> Unit>().invoke(mockImageURI)
}
every {mockImageGetter.fetchImage(any(), any())} answers {}
}

@After
fun clean() {
Intents.release()
}

@Test
fun checkProfileData() {
Expand Down Expand Up @@ -249,25 +246,21 @@ class ProfileActivityTest {

onView(withId(R.id.qrCode)).check(matches(isDisplayed()))
}
// FIXME: CI never finds the view with ID "avatar"
@Test
fun checkIfPictureIsDisplayed() {
val inputProfile = User( "Lalisa Bon", R.string.test_profile_image.toString(), "[email protected]", 12, 8,"VvPB47tQCLdjz3YebilS6h5EXdJ3")
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
createMockDataGetter(inputProfile)
createMockAuthenticator()
createMockImageGetter()
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
Thread.sleep(5000)
onView(withId(R.id.avatar)).check(matches(isDisplayed()))
}
// FIXME

// @Test
// fun checkIfPictureIsDisplayed() {
// val inputProfile = User( "Lalisa Bon", R.string.test_profile_image.toString(), "[email protected]", 12, 8,"VvPB47tQCLdjz3YebilS6h5EXdJ3")
// val ctx = ApplicationProvider.getApplicationContext() as Context
// val intent = Intent(ctx, ProfileActivity::class.java)
//
// createMockDataGetter(inputProfile)
// createMockAuthenticator()
// createMockImageGetter()
//
// val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent)
// onView(withId(R.id.avatar)).check(matches(isDisplayed()))
// }

}

*/
14 changes: 7 additions & 7 deletions app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.graphics.*
import android.net.Uri
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.Window
Expand Down Expand Up @@ -104,8 +105,8 @@ class ProfileActivity : AppCompatActivity() {
*/
private fun setShowQrCodeBtnListener() {
findViewById<ImageView>(R.id.showQRCode).setOnClickListener {
setLayoutVisibility(R.id.QrCodePage, true)
setLayoutVisibility(R.id.profileContent, false)
setLayoutVisibility(findViewById<ConstraintLayout>(R.id.QrCodePage), true)
setLayoutVisibility(findViewById<RelativeLayout>(R.id.profileContent), false)
}
}

Expand All @@ -114,8 +115,8 @@ class ProfileActivity : AppCompatActivity() {
*/
private fun setQrCodeToProfileBtnListener() {
findViewById<FloatingActionButton>(R.id.qrCode_returnToProfile).setOnClickListener {
setLayoutVisibility(R.id.QrCodePage, false)
setLayoutVisibility(R.id.profileContent, true)
setLayoutVisibility(findViewById<ConstraintLayout>(R.id.QrCodePage), false)
setLayoutVisibility(findViewById<RelativeLayout>(R.id.profileContent), true)
}
}

Expand Down Expand Up @@ -143,8 +144,8 @@ class ProfileActivity : AppCompatActivity() {
* @param isVisible: The indicator of which visibility to choose.
* True for VISIBLE, false for GONE.
*/
private fun setLayoutVisibility(layout: Int, isVisible: Boolean){
findViewById<ConstraintLayout>(layout).visibility = if (isVisible) VISIBLE else GONE
private fun setLayoutVisibility(view: View, isVisible: Boolean){
view.visibility = if (isVisible) VISIBLE else GONE
}

/**
Expand Down Expand Up @@ -212,7 +213,6 @@ class ProfileActivity : AppCompatActivity() {
val bit = BitmapGetterApi.download(imageURI.toString())
bit.get(10, TimeUnit.SECONDS)
} catch (e: Exception){

null
}
}
Expand Down
105 changes: 69 additions & 36 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -8,20 +8,23 @@
tools:context=".activity.ProfileActivity">


<androidx.constraintlayout.widget.ConstraintLayout
<RelativeLayout
android:id="@+id/profileContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">


<RelativeLayout
android:id="@+id/profile_relativeLayout"
android:layout_width="403dp"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:layout_weight=".2"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -32,7 +35,12 @@
android:id="@+id/myCardView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="30dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="20dp"
app:cardCornerRadius="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
Expand All @@ -52,8 +60,8 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:layout_marginStart="13dp"
android:layout_marginTop="22dp"
android:layout_toEndOf="@id/myCardView"
android:text="@string/authentication_placeholderUsername"
android:textSize="20sp"
Expand Down Expand Up @@ -82,11 +90,16 @@

</RelativeLayout>


<TableLayout
android:id="@+id/profile_total_games"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_relativeLayout"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="80dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="80dp"
android:background="@drawable/table_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
Expand Down Expand Up @@ -121,17 +134,23 @@

</TableLayout>


<ScrollView
android:id="@+id/profile_scroll_stat"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_above="@+id/logout"
android:layout_below="@+id/profile_scores"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="40dp"
app:layout_constraintBottom_toTopOf="@+id/profile_returnToMain"
app:layout_constraintTop_toBottomOf="@+id/profile_scores"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_scores">

<TableLayout
android:id="@+id/profileStatistics"
Expand Down Expand Up @@ -306,41 +325,53 @@

</ScrollView>


<Button
android:id="@+id/logout"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_marginBottom="24dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="40dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="20dp"
android:layout_toStartOf="@+id/profile_returnToMain"
android:backgroundTint="@color/cg_blue"
android:elevation="10dp"
android:elevation="0dp"
android:stateListAnimator="@null"
android:text="logout"
android:translationZ="10dp"
app:layout_constraintRight_toLeftOf="@+id/profile_returnToMain"
app:layout_constraintTop_toBottomOf="@+id/profile_scroll_stat"
android:textColor="#F9FBE7"
android:translationZ="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintHorizontal_bias="0"
app:layout_constraintRight_toLeftOf="@+id/profile_returnToMain"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_scroll_stat"
app:layout_constraintVertical_bias="0" />

<Button
android:id="@+id/profile_scores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="52dp"
android:layout_marginTop="16dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="@+id/profile_total_games"
android:layout_alignParentStart="true"
android:layout_marginStart="60dp"
android:layout_marginTop="10dp"
android:backgroundTint="@color/cg_blue"
android:text="Scores"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_total_games" />

<Button
android:id="@+id/profile_friends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="72dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="@+id/profile_total_games"
android:layout_alignParentEnd="true"
android:layout_marginStart="83dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="60dp"
android:layout_toEndOf="@+id/profile_scores"
android:backgroundTint="@color/cg_blue"
android:text="Friends"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -350,19 +381,21 @@
android:id="@+id/profile_returnToMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="35dp"
android:layout_marginBottom="20dp"
android:backgroundTint="@color/light_coral"
android:clickable="true"
android:src="@android:drawable/ic_menu_revert"
app:borderWidth="0dp"
app:layout_constraintLeft_toRightOf="@+id/logout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/logout" />


</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

<include layout="@layout/display_qr_code" />

</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

0 comments on commit e3fe186

Please sign in to comment.