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

Refactor Auth + Going forward score part 2 #190

Merged
merged 51 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a629349
update google signin auth
MaximeZmt Apr 19, 2022
8c1f5ac
Merge branch 'main' of github.com:MaximeZmt/SDP_2022-Vibester into main
MaximeZmt Apr 19, 2022
f264412
Merge branch 'main' into maximezmt/refactorauthp2
MaximeZmt Apr 24, 2022
2471a00
user profile improvement
MaximeZmt Apr 24, 2022
ef91af0
merged
MaximeZmt Apr 24, 2022
3ba66aa
test updates
MaximeZmt Apr 24, 2022
982f618
add persistance Setter
MaximeZmt Apr 24, 2022
704fb09
fixing test for idk numb of time
MaximeZmt Apr 25, 2022
a02c4bb
fixing test for idk numb of time 2
MaximeZmt Apr 25, 2022
4465122
adding hilt to a test
MaximeZmt Apr 25, 2022
a8e0bdf
fixing some other test
MaximeZmt Apr 25, 2022
42ef816
fixing some other test 2
MaximeZmt Apr 25, 2022
cea160e
adding hilt to a test 2
MaximeZmt Apr 25, 2022
fc4a990
removing hilt typing
MaximeZmt Apr 25, 2022
ee82439
dumb modif
MaximeZmt Apr 25, 2022
40277bd
removed hilt where it should not be
MaximeZmt Apr 25, 2022
e9a5c68
Merge branch 'main' into maximezmt/refactorauthp2
MaximeZmt Apr 25, 2022
de78a77
fix merging test error
MaximeZmt Apr 25, 2022
93fffce
small update
MaximeZmt Apr 26, 2022
c13377c
merged done
MaximeZmt Apr 26, 2022
9647fb1
patch profileActivityTest
MaximeZmt Apr 26, 2022
e57a324
patch profileActivityTest 2
MaximeZmt Apr 26, 2022
65e849e
patch profileActivityTest 3
MaximeZmt Apr 26, 2022
9f13f28
massive user update
MaximeZmt Apr 26, 2022
b8d646e
update tests
MaximeZmt Apr 27, 2022
c545546
some improvements
MaximeZmt Apr 27, 2022
e0dcb23
put scores update for typing game
MaximeZmt Apr 27, 2022
6c54d02
update search user welcome test
MaximeZmt Apr 27, 2022
ede24a3
refactor +add test + optimize imports
MaximeZmt Apr 27, 2022
06df4a8
update test
MaximeZmt Apr 27, 2022
75b8f0b
update test 2
MaximeZmt Apr 27, 2022
cea504f
try update
MaximeZmt Apr 27, 2022
82083fb
try update 2
MaximeZmt Apr 27, 2022
9b8d0d3
try update 3
MaximeZmt Apr 27, 2022
0fdd236
try update 666
MaximeZmt Apr 27, 2022
214c933
try update 666 2
MaximeZmt Apr 27, 2022
d498ddf
Update app/src/main/java/ch/sdp/vibester/activity/AuthenticationActiv…
MaximeZmt Apr 28, 2022
ffc2d11
Update app/src/main/java/ch/sdp/vibester/api/InternetState.kt
MaximeZmt Apr 28, 2022
d42d33a
Update app/src/main/java/ch/sdp/vibester/api/InternetState.kt
MaximeZmt Apr 28, 2022
56fbdd0
Update app/src/main/java/ch/sdp/vibester/activity/AuthenticationActiv…
MaximeZmt Apr 28, 2022
2864d98
Update app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt
MaximeZmt Apr 28, 2022
4402f27
Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
MaximeZmt Apr 28, 2022
19d6206
Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
MaximeZmt Apr 28, 2022
3d3b967
Update app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
MaximeZmt Apr 28, 2022
74f41bd
review updated
MaximeZmt Apr 28, 2022
8f9b1fb
Merge branch 'maximezmt/refactorauthp2' of github.com:MaximeZmt/SDP_2…
MaximeZmt Apr 28, 2022
713f865
review updated 2
MaximeZmt Apr 28, 2022
e10f9c5
all issues addressed
MaximeZmt Apr 28, 2022
5b3c21f
some other issues addressed
MaximeZmt Apr 28, 2022
ec89e32
renable a TestMode
MaximeZmt Apr 28, 2022
8e559fc
renable a TestMode 2
MaximeZmt Apr 28, 2022
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 @@ -14,6 +14,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import ch.sdp.vibester.R
import ch.sdp.vibester.TestMode
import ch.sdp.vibester.auth.FireBaseAuthenticator
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
Expand Down Expand Up @@ -179,6 +180,8 @@ class AuthenticationActivityTest {
val username = "[email protected]"
val password = "password"

TestMode.setTest()

val mockTask = createMockTask(true)
val mockUser = createMockUser(username)
every { mockAuthenticator.createAccount(username, password) } returns mockTask
Expand All @@ -187,7 +190,6 @@ class AuthenticationActivityTest {
onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
onView(withId(R.id.createAcc)).perform(click())

Intents.intended(IntentMatchers.hasComponent(CreateProfileActivity::class.java.name))
Intents.intended(IntentMatchers.hasExtra("email", username))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ 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 ch.sdp.vibester.TestMode
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -100,6 +103,8 @@ class BuzzerScreenActivityTest {
*/
@Test
fun checkIntentOnEnding() {
TestMode.setTest()
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved

val mockArray = arrayListOf<String>("One", "Two", "Three", "Four", "Five")

val incArray: ArrayList<String> = mockArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,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.action.ViewActions.*
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.UsersRepo
import ch.sdp.vibester.TestMode
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.user.User
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
Expand Down Expand Up @@ -38,14 +39,14 @@ class CreateProfileActivityTest {
}

@BindValue @JvmField
val mockUsersRepo = mockk<UsersRepo>()
val mockUsersRepo = mockk<DataGetter>()

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

every { mockUsersRepo.getUserData(any(), any()) } answers {
every { mockUsersRepo.getUserData(any()) } answers {
secondArg<(User) -> Unit>().invoke(User())
}
}
Expand All @@ -57,24 +58,28 @@ class CreateProfileActivityTest {

@Test
fun createAccCorrect() {
TestMode.setTest()
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved

var username = "mockUsername"
var mockEmail = "[email protected]"

val intent = Intent(ApplicationProvider.getApplicationContext(), CreateProfileActivity::class.java)
intent.putExtra("email", mockEmail)
intent.putExtra("isUnitTest", true)

createMockInvocation(mockEmail)

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

onView(withId(R.id.accountUsername)).perform(ViewActions.typeText(username),
ViewActions.closeSoftKeyboard()
onView(withId(R.id.accountUsername)).perform(typeText(username),
closeSoftKeyboard()
)

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

Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name))
Intents.intended(IntentMatchers.hasExtra("email", mockEmail))
Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name))
Intents.intended(IntentMatchers.hasExtra("email", mockEmail))
Intents.intended(IntentMatchers.hasExtra("isUnitTest", true))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ 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 ch.sdp.vibester.TestMode
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -23,8 +26,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class GameEndingActivityTest {

@Rule
@JvmField
@get:Rule
val activityRule = ActivityScenarioRule(GameEndingActivity::class.java)

@Before
Expand All @@ -47,6 +49,8 @@ class GameEndingActivityTest {

@Test
fun checkIntentOnCalled() {
TestMode.setTest()
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved

incArray.addAll(arrayOf("One", "Two", "Three"))
statNames.addAll(
arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import androidx.test.rule.GrantPermissionRule
import ch.sdp.vibester.R
import ch.sdp.vibester.api.LastfmMethod
import ch.sdp.vibester.helper.TypingGameManager
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.not
import org.junit.*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good change!

import org.junit.Assert.assertEquals
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LyricsBelongGameActivityTest {

private val sleepTime: Long = 5000
private val songName = "Thunder"
private val artistName = "Imagine Dragons"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.UsersRepo
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.model.UserSharedPref
import ch.sdp.vibester.user.User
import dagger.hilt.android.testing.BindValue
Expand Down Expand Up @@ -42,11 +42,11 @@ class ProfileActivityTest {
}

@BindValue @JvmField
val mockUsersRepo = mockk<UsersRepo>()
val mockUsersRepo = mockk<DataGetter>()

private fun createMockInvocation(mockUser: User) {
every { mockUsersRepo.getUserData(any(), any()) } answers {
secondArg<(User) -> Unit>().invoke(mockUser)
private fun createMockInvocation(mockProfile: User) {
every { mockUsersRepo.getUserData(any()) } answers {
secondArg<(User) -> Unit>().invoke(mockProfile)
}
every { mockUsersRepo.updateFieldString(any(), any(), any()) } answers {}
}
Expand All @@ -61,9 +61,10 @@ class ProfileActivityTest {
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)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

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

onView(withId(R.id.username)).check(matches(withText(inputProfile.username)))
Expand All @@ -76,6 +77,8 @@ class ProfileActivityTest {
fun clickBackToMain(){
val ctx = ApplicationProvider.getApplicationContext() as Context
val intent = Intent(ctx, ProfileActivity::class.java)
intent.putExtra("isUnitTest", true)

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

onView(withId(R.id.profile_returnToMain)).perform(click())
Expand All @@ -88,6 +91,8 @@ class ProfileActivityTest {
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)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

UserSharedPref.setUser(ctx, inputProfile, false)
createMockInvocation(inputProfile)
Expand All @@ -110,6 +115,8 @@ class ProfileActivityTest {
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)
intent.putExtra("isUnitTest", true)
intent.putExtra("userTestProfile", inputProfile)

UserSharedPref.setUser(ctx, inputProfile, false)
createMockInvocation(inputProfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import ch.sdp.vibester.R
import ch.sdp.vibester.api.LastfmMethod
import ch.sdp.vibester.helper.TypingGameManager
import ch.sdp.vibester.model.Song
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
Expand All @@ -30,6 +32,20 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TypingGameActivityTest {

@JvmField
@get:Rule
val activityRule = ActivityScenarioRule(TypingGameActivity::class.java)

@Before
fun setUp() {
Intents.init()
}

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

private val expectedSize = 200
private fun setGameManager(numSongs:Int = 1, valid: Boolean = true): TypingGameManager {
val epilogue = "{\"tracks\":{\"track\":["
Expand All @@ -50,21 +66,6 @@ class TypingGameActivityTest {
return gameManager
}

@Rule
@JvmField
val activityRule = ActivityScenarioRule(TypingGameActivity::class.java)

@Before
fun setUp() {
Intents.init()
}

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


@Test
fun spaceGenTest() {
val height = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.sdp.vibester.activity

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.intent.Intents
Expand All @@ -9,6 +11,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.TestMode
import com.google.firebase.auth.FirebaseAuth
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand All @@ -17,6 +20,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.manipulation.Ordering

@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
Expand Down Expand Up @@ -71,6 +75,7 @@ class WelcomeActivityTest {

@Test
fun checkIntentOnSearch() {
TestMode.setTest()
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
onView(withId(R.id.welcome_search)).perform(click())
intended(hasComponent(SearchUserActivity::class.java.name))
}
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/ch/sdp/vibester/TestMode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ch.sdp.vibester

class TestMode private constructor(){
jiabaow marked this conversation as resolved.
Show resolved Hide resolved
companion object{
private var isTest: Boolean = false

fun setTest(){
isTest = true
}

fun isTest(): Boolean {
return isTest
}


}
}
Loading