diff --git a/app/src/androidTest/java/ch/sdp/vibester/UtilTest.kt b/app/src/androidTest/java/ch/sdp/vibester/UtilTest.kt deleted file mode 100644 index f081c9a67..000000000 --- a/app/src/androidTest/java/ch/sdp/vibester/UtilTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package ch.sdp.vibester - -import ch.sdp.vibester.util.Util -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class UtilTest { - @Test - fun newIdIsCorrectLength() { - assertEquals(Util.createNewId().length, 10) - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/AuthenticationActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/AuthenticationActivityTest.kt index 2336bc2d8..b9d4f7c6e 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/AuthenticationActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/AuthenticationActivityTest.kt @@ -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 @@ -131,6 +132,13 @@ class AuthenticationActivityTest { onView(withId(R.id.email)).check(matches(withText("Empty email or password"))) } + @Test + fun returnToMain() { + onView(withId(R.id.authentication_returnToMain)).perform(click()) + Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name)) + } + + @Test fun stringValidationWrongEmail() { val username = "john" @@ -179,6 +187,8 @@ class AuthenticationActivityTest { val username = "user@user.com" val password = "password" + TestMode.setTest() + val mockTask = createMockTask(true) val mockUser = createMockUser(username) every { mockAuthenticator.createAccount(username, password) } returns mockTask @@ -187,7 +197,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)) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerScreenActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerScreenActivityTest.kt index b82cfe2a6..be87a7a8c 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerScreenActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerScreenActivityTest.kt @@ -14,6 +14,7 @@ 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 org.junit.After import org.junit.Before import org.junit.Rule diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerSetupActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerSetupActivityTest.kt index c0a64452c..bc0102996 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerSetupActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/BuzzerSetupActivityTest.kt @@ -1,8 +1,5 @@ package ch.sdp.vibester.activity -import android.content.Context import android.content.Intent -import android.widget.FrameLayout -import android.widget.LinearLayout import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onData @@ -22,7 +19,6 @@ import ch.sdp.vibester.R import org.hamcrest.Matchers import org.junit.After import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/CreateProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/CreateProfileActivityTest.kt index 2b130eef2..eadeffe9b 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/CreateProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/CreateProfileActivityTest.kt @@ -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.espresso.matcher.ViewMatchers.withId 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 @@ -38,16 +39,17 @@ class CreateProfileActivityTest { } @BindValue @JvmField - val mockUsersRepo = mockk() + val mockUsersRepo = mockk() 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()) } + } @After @@ -57,24 +59,27 @@ class CreateProfileActivityTest { @Test fun createAccCorrect() { + TestMode.setTest() var username = "mockUsername" var mockEmail = "mockEmail@test.com" val intent = Intent(ApplicationProvider.getApplicationContext(), CreateProfileActivity::class.java) intent.putExtra("email", mockEmail) + intent.putExtra("isUnitTest", true) createMockInvocation(mockEmail) val scn: ActivityScenario = 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)) } } \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt index ff30d3b5b..dd7688044 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt @@ -1,22 +1,10 @@ package ch.sdp.vibester.activity -import android.content.Intent -import android.view.View -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.* import androidx.test.ext.junit.rules.ActivityScenarioRule -import ch.sdp.vibester.R import org.junit.After -import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule -import org.junit.Test -import java.io.File class DownloadActivityTest { diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/GameEndingActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/GameEndingActivityTest.kt index bd33fe975..6de9594fa 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/GameEndingActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/GameEndingActivityTest.kt @@ -14,6 +14,7 @@ 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 org.junit.After import org.junit.Before import org.junit.Rule @@ -23,8 +24,7 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class GameEndingActivityTest { - @Rule - @JvmField + @get:Rule val activityRule = ActivityScenarioRule(GameEndingActivity::class.java) @Before @@ -71,6 +71,7 @@ class GameEndingActivityTest { Intent(ApplicationProvider.getApplicationContext(), GameEndingActivity::class.java) intent.putExtra("playerName", name) intent.putExtra("nbIncorrectSong", nbInc) + intent.putExtra("Winner Name", "Testing the Placeholder") intent.putStringArrayListExtra("str_arr_inc", incArray) intent.putStringArrayListExtra("str_arr_name", statNames) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt index 2e44abb86..850b0c381 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/GameSetupActivityTest.kt @@ -8,6 +8,7 @@ import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.Intents.intended +import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra import androidx.test.espresso.matcher.ViewMatchers.withId @@ -52,6 +53,16 @@ class GameSetupActivityTest { onView(withId(R.id.difficulty_spinner)).check(matches(withSpinnerText("Easy"))) } + @Test + fun checkReturnButton() { + onView(withId(R.id.local_buzzer_game_button)).perform(scrollTo(), click()) + onView(withId(R.id.btsButton)).perform(click()) + onView(withId(R.id.gameSetup_returnToMain)).perform(click()) + onView(withId(R.id.gameSetup_returnToMain)).perform(click()) + onView(withId(R.id.gameSetup_returnToMain)).perform(click()) + Intents.intended(IntentMatchers.hasComponent(WelcomeActivity::class.java.name)) + } + @Test fun checkCustomSelectMedium() { onView(withId(R.id.local_buzzer_game_button)).perform(scrollTo(), click()) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt index 045e291c3..d09ca1306 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt @@ -17,12 +17,16 @@ import ch.sdp.vibester.R import ch.sdp.vibester.api.LastfmMethod import ch.sdp.vibester.helper.TypingGameManager import org.hamcrest.CoreMatchers.not -import org.junit.* +import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Rule +import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class LyricsBelongGameActivityTest { + private val sleepTime: Long = 5000 private val songName = "Thunder" private val artistName = "Imagine Dragons" diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt index 307314158..e7a6d8c7c 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ProfileActivityTest.kt @@ -10,11 +10,12 @@ import androidx.test.espresso.action.ViewActions.click 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.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText 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.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 @@ -42,13 +43,15 @@ class ProfileActivityTest { } @BindValue @JvmField - val mockUsersRepo = mockk() + val mockUsersRepo = mockk() - 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 {} + + every { mockUsersRepo.getUserData(any())} answers {} } @After @@ -61,9 +64,10 @@ class ProfileActivityTest { val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "lisa@test.com", 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 = ActivityScenario.launch(intent) onView(withId(R.id.username)).check(matches(withText(inputProfile.username))) @@ -76,6 +80,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 = ActivityScenario.launch(intent) onView(withId(R.id.profile_returnToMain)).perform(click()) @@ -88,8 +94,9 @@ class ProfileActivityTest { val inputProfile = User("Lalisa Bon","bit.ly/3IUnyAF", "lisa@test.com", 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) val scn: ActivityScenario = ActivityScenario.launch(intent) @@ -110,8 +117,9 @@ class ProfileActivityTest { val inputProfile = User( "Lalisa Bon","bit.ly/3IUnyAF", "lisa@test.com", 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) val scn: ActivityScenario = ActivityScenario.launch(intent) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ScoreBoardActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ScoreBoardActivityTest.kt index 8549856f1..30fe70ac0 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ScoreBoardActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ScoreBoardActivityTest.kt @@ -6,7 +6,8 @@ import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions -import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +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 diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt index e64c99df5..3065522af 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/TypingGameActivityTest.kt @@ -13,10 +13,12 @@ import androidx.test.espresso.action.ViewActions.click 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.* +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +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 ch.sdp.vibester.api.LastfmMethod import ch.sdp.vibester.helper.TypingGameManager import ch.sdp.vibester.model.Song @@ -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\":[" @@ -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 @@ -109,6 +110,7 @@ class TypingGameActivityTest { @Test fun guessLayoutTest() { + TestMode.setTest() val inputTxt = """ { "resultCount":1, @@ -199,7 +201,7 @@ class TypingGameActivityTest { */ @Test fun checkIntentOnEnding() { - + TestMode.setTest() val inputTxt = """ { "resultCount":1, @@ -274,6 +276,7 @@ class TypingGameActivityTest { @Test fun nextButtonOnClick(){ + TestMode.setTest() val gameManager = setGameManager(2) assertEquals(gameManager.getSongList().size, 2) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/WelcomeActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/WelcomeActivityTest.kt index 154f11527..b642ebf55 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/WelcomeActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/WelcomeActivityTest.kt @@ -9,6 +9,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 @@ -71,7 +72,13 @@ class WelcomeActivityTest { @Test fun checkIntentOnSearch() { + TestMode.setTest() onView(withId(R.id.welcome_search)).perform(click()) intended(hasComponent(SearchUserActivity::class.java.name)) } + + @Test + fun checkIntentOnSearchWithoutTestMode() { + onView(withId(R.id.welcome_search)).perform(click()) + } } \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/auth/FireBaseAuthenticatorTest.kt b/app/src/androidTest/java/ch/sdp/vibester/auth/FireBaseAuthenticatorTest.kt new file mode 100644 index 000000000..51f44bdc5 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/auth/FireBaseAuthenticatorTest.kt @@ -0,0 +1,32 @@ +package ch.sdp.vibester.auth + +import androidx.test.core.app.ApplicationProvider +import ch.sdp.vibester.TestMode +import org.junit.Assert.assertEquals +import org.junit.Assert.assertThrows +import org.junit.Test + +class FireBaseAuthenticatorTest { + + @Test + fun checkTestModeGetMail(){ + TestMode.setTest() + assertEquals("", FireBaseAuthenticator.getCurrentUserMail()) + } + + @Test + fun checkTestModeGetUID(){ + TestMode.setTest() + assertEquals("", FireBaseAuthenticator.getCurrentUID()) + } + + @Test + fun checkGoogleFakeRequestCode(){ + assertEquals("Authentication error", FireBaseAuthenticator.googleActivityResult(0, 0, null, ApplicationProvider.getApplicationContext())) + } + + @Test + fun checkGoogleFakeGoodCode(){ + assertEquals("Authentication error", FireBaseAuthenticator.googleActivityResult(1000, 0, null, ApplicationProvider.getApplicationContext())) + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/model/UserSharedPrefTest.kt b/app/src/androidTest/java/ch/sdp/vibester/model/UserSharedPrefTest.kt deleted file mode 100644 index 63349a2ed..000000000 --- a/app/src/androidTest/java/ch/sdp/vibester/model/UserSharedPrefTest.kt +++ /dev/null @@ -1,49 +0,0 @@ -package ch.sdp.vibester.model - -import android.content.Context -import androidx.test.core.app.ApplicationProvider -import ch.sdp.vibester.user.User -import org.junit.Assert.assertEquals -import org.junit.Test - -class UserSharedPrefTest { - @Test - fun sharedPrefTest(){ - val ctx = ApplicationProvider.getApplicationContext() as Context - - val mailTest = "lisa@test.com" - UserSharedPref.userReset(ctx, mailTest) - UserSharedPref.updateUsername(ctx, "Lalisa Bon") - UserSharedPref.updateScore(ctx) - Thread.sleep(1000) -// assertEquals(mailTest, UserSharedPref.getUser(ctx).email) //TODO temporary disable does not pass on CI - } - - @Test - fun sharedPrefTest2(){ - val ctx = ApplicationProvider.getApplicationContext() as Context - val username: String = "myUsername" - val image: String = "myImage" - val email: String = "myEmail" - val totalGames: Int = 10 - val bestScore: Int = 27 - val correctSongs: Int = 16 - val ranking: Int = 6 - - 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.username, updated.username) - assertEquals(pro.image, updated.image) - assertEquals(pro.email, updated.email) - assertEquals(pro.totalGames+1, updated.totalGames) - assertEquals(pro.bestScore-1, updated.bestScore) - assertEquals(pro.correctSongs, updated.correctSongs) - assertEquals(pro.ranking+1, updated.ranking) - } - - -} diff --git a/app/src/main/java/ch/sdp/vibester/TestMode.kt b/app/src/main/java/ch/sdp/vibester/TestMode.kt new file mode 100644 index 000000000..098889896 --- /dev/null +++ b/app/src/main/java/ch/sdp/vibester/TestMode.kt @@ -0,0 +1,26 @@ +package ch.sdp.vibester + + +/** + * This class represent a state manager that can be used in unit test + * It may be used to disable certain features for unit test + */ +class TestMode private constructor(){ + companion object{ + private var isTest: Boolean = false + + /** + * Setter for IsTest() + */ + fun setTest(){ + isTest = true + } + + /** + * Is Test enabled + */ + fun isTest(): Boolean { + return isTest + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt index 250374bd0..4355466b0 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt @@ -2,6 +2,7 @@ package ch.sdp.vibester.activity import android.content.Intent import android.os.Bundle +import android.util.Log import android.view.Window import android.widget.Button import android.widget.EditText @@ -9,24 +10,40 @@ import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import ch.sdp.vibester.R +import ch.sdp.vibester.TestMode import ch.sdp.vibester.auth.FireBaseAuthenticator +import ch.sdp.vibester.database.DataGetter +import ch.sdp.vibester.helper.IntentSwitcher import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions +import com.google.android.gms.common.api.ApiException import com.google.android.gms.tasks.Task +import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.firebase.auth.AuthResult +import com.google.firebase.auth.FirebaseAuth +import com.google.firebase.auth.FirebaseUser +import com.google.firebase.auth.GoogleAuthProvider +import com.google.firebase.auth.ktx.auth +import com.google.firebase.ktx.Firebase import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint class AuthenticationActivity : AppCompatActivity() { + private val AUTHENTICATION_PERMISSION_CODE = 1000 private lateinit var googleSignInClient: GoogleSignInClient + @Inject + lateinit var dataGetter: DataGetter + @Inject lateinit var authenticator: FireBaseAuthenticator + private lateinit var auth: FirebaseAuth + private lateinit var email: TextView override fun onCreate(savedInstanceState: Bundle?) { @@ -35,17 +52,23 @@ class AuthenticationActivity : AppCompatActivity() { supportActionBar?.hide() setContentView(R.layout.activity_authentication) + val googleSignInToken = "7687769601-qiqrp6kt48v89ub76k9lkpefh9ls36ha.apps.googleusercontent.com" + val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestIdToken(googleSignInToken) .requestEmail() .build() googleSignInClient = GoogleSignIn.getClient(this, gso) + auth = Firebase.auth val btCreateAcc = findViewById