This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from MaximeZmt/laurislopata/DB-refactor
Laurislopata/db refactor
- Loading branch information
Showing
7 changed files
with
122 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,18 @@ import androidx.test.espresso.action.ViewActions | |
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard | ||
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.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
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.auth.FireBaseAuthenticator | ||
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 | ||
|
@@ -28,6 +32,15 @@ import kotlin.random.Random | |
class AuthenticationActivityTest { | ||
private val sleepTime: Long = 5000 | ||
|
||
@Before | ||
fun setUp() { | ||
Intents.init() | ||
} | ||
|
||
@After | ||
fun clean() { | ||
Intents.release() | ||
} | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
|
@@ -110,13 +123,14 @@ class AuthenticationActivityTest { | |
|
||
@Test | ||
fun logInCorrect() { | ||
val username = "john@test.com" | ||
val username = "lisa@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(sleepTime) | ||
onView(withId(R.id.email)).check(matches(withText("[email protected]"))) | ||
Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name)) | ||
Intents.intended(IntentMatchers.hasExtra("email", username)) | ||
} | ||
|
||
@Test | ||
|
@@ -128,8 +142,8 @@ class AuthenticationActivityTest { | |
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) | ||
onView(withId(R.id.createAcc)).perform(click()) | ||
Thread.sleep(sleepTime) | ||
onView(withId(R.id.email)).check(matches(withText(randomInt.toString().plus("@gg.com")))) | ||
Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name)) | ||
Intents.intended(IntentMatchers.hasExtra("email", username)) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,40 @@ 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.runners.AndroidJUnit4 | ||
import ch.sdp.vibester.R | ||
import ch.sdp.vibester.profile.UserProfile | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ProfileActivityTest { | ||
|
||
private val sleepTime: Long = 4000 | ||
|
||
@Before | ||
fun setUp() { | ||
Intents.init() | ||
} | ||
|
||
@After | ||
fun clean() { | ||
Intents.release() | ||
} | ||
|
||
@Test | ||
fun checkProfileData() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
intent.putExtra("userProfile", inputProfile) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
Thread.sleep(3_000) | ||
Thread.sleep(sleepTime) | ||
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()))) | ||
|
@@ -34,12 +49,11 @@ class ProfileActivityTest { | |
|
||
@Test | ||
fun checkProfileLayout() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("userProfile", inputProfile) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
Thread.sleep(3_000) | ||
Thread.sleep(sleepTime) | ||
onView(withId(R.id.profileStatistics)).check(matches(isDisplayed())) | ||
onView(withId(R.id.handle)).check(matches(isDisplayed())) | ||
onView(withId(R.id.username)).check(matches(isDisplayed())) | ||
|
@@ -48,13 +62,12 @@ class ProfileActivityTest { | |
|
||
@Test | ||
fun checkEditProfile() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("userProfile", inputProfile) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
|
||
val newUsername = "newUser" | ||
val newUsername = "Lalisa Bon" | ||
onView(withId(R.id.editUser)).perform(ViewActions.click()) | ||
onView(withId(0)).perform( | ||
ViewActions.typeText(newUsername), | ||
|
@@ -67,44 +80,41 @@ class ProfileActivityTest { | |
|
||
@Test | ||
fun checkEditProfileClickCancel() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("userProfile", inputProfile) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
Thread.sleep(3_000) | ||
Thread.sleep(sleepTime) | ||
onView(withId(R.id.editUser)).perform(ViewActions.click()) | ||
onView(withText("Cancel")).perform(ViewActions.click()) | ||
onView(withId(R.id.username)).check(matches(withText("Lalisa Bon"))) | ||
} | ||
|
||
@Test | ||
fun checkEditHandle() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("userProfile", inputProfile) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
Thread.sleep(3_000) | ||
val newUserHandle = "newHandle" | ||
Thread.sleep(sleepTime) | ||
val newUserHandle = "@lisa" | ||
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"))) | ||
onView(withId(R.id.handle)).check(matches(withText("@lisa"))) | ||
|
||
} | ||
|
||
@Test | ||
fun checkEditHandleClickCancel() { | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon", "bit.ly/3IUnyAF", 12, 8, 29, 0) | ||
val intent = | ||
Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("userProfile", inputProfile) | ||
val inputProfile = UserProfile("@lisa", "Lalisa Bon","bit.ly/3IUnyAF", "[email protected]", 12, 8, 29, 0) | ||
val intent = Intent(ApplicationProvider.getApplicationContext(), ProfileActivity::class.java) | ||
intent.putExtra("email", inputProfile.email) | ||
val scn: ActivityScenario<ProfileActivity> = ActivityScenario.launch(intent) | ||
Thread.sleep(3_000) | ||
Thread.sleep(sleepTime) | ||
onView(withId(R.id.editHandle)).perform(ViewActions.click()) | ||
onView(withText("Cancel")).perform(ViewActions.click()) | ||
onView(withId(R.id.handle)).check(matches(withText("@lisa"))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.