diff --git a/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt index fab09bd17..9d7bd379e 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt @@ -38,38 +38,83 @@ class SignInActivityTest { Register::class.java ) - @Test - fun logInCorrect() { - val username = "john@test.com" + fun logInIncorrect() { + val username = "johnyyy@test.com" val password = "password" onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) onView(withId(R.id.logIn)).perform(click()) Thread.sleep(3_000) - onView(withId(R.id.email)).check(matches(withText("john@test.com"))) + onView(withId(R.id.email)).check(matches(withText("Authentication error"))) } @Test - fun logInIncorrect() { - val username = "johnyyy@test.com" + fun createAccountIncorrect() { + val username = "john@test.com" val password = "password" onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) - onView(withId(R.id.logIn)).perform(click()) + onView(withId(R.id.createAcc)).perform(click()) Thread.sleep(3_000) onView(withId(R.id.email)).check(matches(withText("Authentication error"))) } @Test - fun createAccountIncorrect() { - val username = "john@test.com" + fun stringValidationEmptyUsername() { + onView(withId(R.id.createAcc)).perform(click()) + onView(withId(R.id.email)).check(matches(withText("Empty email or password"))) + } + + @Test + fun stringValidationEmptyUPassword() { + onView(withId(R.id.createAcc)).perform(click()) + onView(withId(R.id.email)).check(matches(withText("Empty email or password"))) + } + + @Test + fun stringValidationWrongEmail() { + val username = "john" val password = "password" 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()) + onView(withId(R.id.email)).check(matches(withText("Not an email"))) + } + + @Test + fun stringValidationShorPassword() { + val username = "john@test.com" + val password = "12345" + 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()) + onView(withId(R.id.email)).check(matches(withText("Password has to be at least 6 symbols"))) + } + + @Test + fun derinTest() { + val a = FireBaseAuthenticator() + a.googleActivityResult(-1,-1,null) + onView(withId(R.id.email)).check(matches(withText("TextView"))) + } + + @Test + fun ardaTest() { + val a = FireBaseAuthenticator() + a.googleActivityResult(1000,-1,null) + onView(withId(R.id.email)).check(matches(withText("TextView"))) + } + + @Test + fun logInCorrect() { + val username = "john@test.com" + val password = "password" + onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) + onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) + onView(withId(R.id.logIn)).perform(click()) Thread.sleep(3_000) - onView(withId(R.id.email)).check(matches(withText("Authentication error"))) + onView(withId(R.id.email)).check(matches(withText("john@test.com"))) } @Test @@ -85,5 +130,4 @@ class SignInActivityTest { } - } \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/profile/ProfileSetupTest.kt b/app/src/androidTest/java/ch/sdp/vibester/profile/ProfileSetupTest.kt index 5aa640d89..e238f146d 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/profile/ProfileSetupTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/profile/ProfileSetupTest.kt @@ -3,23 +3,14 @@ package ch.sdp.vibester.profile import android.content.Intent import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider -import androidx.test.espresso.Espresso -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.intent.Intents -import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.* -import ch.sdp.vibester.GreetingActivity import ch.sdp.vibester.R -import org.junit.After -import org.junit.Before -import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import java.io.Serializable @RunWith(AndroidJUnit4::class) @@ -49,5 +40,59 @@ class ProfileSetupTest { onView(withId(R.id.username)).check(matches(isDisplayed())) // onView(withId(R.id.avatar)).check(matches(isDisplayed())) } + + @Test + fun checkEditProfile() { + val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2) + val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java) + intent.putExtra("userProfile", inputProfile) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + val newUsername = "newUser" + onView(withId(R.id.editUser)).perform(ViewActions.click()) + onView(withId(0)).perform(ViewActions.typeText(newUsername), ViewActions.closeSoftKeyboard()) + onView(withText("OK")).perform(ViewActions.click()) + onView(withId(R.id.username)).check(matches(withText(newUsername))) + + } + + @Test + fun checkEditProfileClickCancel() { + val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2) + val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java) + intent.putExtra("userProfile", inputProfile) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + onView(withId(R.id.editUser)).perform(ViewActions.click()) + onView(withText("Cancel")).perform(ViewActions.click()) + onView(withId(R.id.username)).check(matches(withText("username0"))) + } + + @Test + fun checkEditHandle() { + val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2) + val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java) + intent.putExtra("userProfile", inputProfile) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + val newUserHandle = "newHandle" + onView(withId(R.id.editHandle)).perform(ViewActions.click()) + onView(withId(0)).perform(ViewActions.typeText(newUserHandle), ViewActions.closeSoftKeyboard()) + onView(withText("OK")).perform(ViewActions.click()) + onView(withId(R.id.handle)).check(matches(withText("newHandle"))) + + } + + @Test + fun checkEditHandleClickCancel() { + val inputProfile = UserProfile("user0", "username0","bit.ly/3IUnyAF", 5, 8, 34, 2) + val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileSetup::class.java) + intent.putExtra("userProfile", inputProfile) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + onView(withId(R.id.editHandle)).perform(ViewActions.click()) + onView(withText("Cancel")).perform(ViewActions.click()) + onView(withId(R.id.handle)).check(matches(withText("user0"))) + } } \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/Register.kt b/app/src/main/java/ch/sdp/vibester/Register.kt index 18cfc07e5..ed14001c8 100644 --- a/app/src/main/java/ch/sdp/vibester/Register.kt +++ b/app/src/main/java/ch/sdp/vibester/Register.kt @@ -16,7 +16,7 @@ import com.google.firebase.auth.AuthResult class Register : AppCompatActivity() { -// private lateinit var googleSignInClient: GoogleSignInClient + private lateinit var googleSignInClient: GoogleSignInClient private lateinit var authenticator: FireBaseAuthenticator @@ -27,61 +27,79 @@ class Register : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_google_log_in) -// @FixMe -// Commenting this for now until we find a proper way to test it, then will merge it to main + val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail() + .build() -// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) -// .requestEmail() -// .build() - -// googleSignInClient = GoogleSignIn.getClient(this, gso) - - // Initialize Firebase Auth + googleSignInClient = GoogleSignIn.getClient(this, gso) authenticator = FireBaseAuthenticator() val btCreateAcc = findViewById