Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E test for activity #251

Merged
merged 23 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cbc5d58
test(e2e): Add start of activity addition
RemIsMyWaifuu Dec 11, 2024
1feaa2e
chore(e2e): Ktfmt compliance
RemIsMyWaifuu Dec 11, 2024
30fee7f
Merge branch 'main' into test/e2e-activity
RemIsMyWaifuu Dec 11, 2024
93fff72
fix(e2e): Fix end to end test tags and display
RemIsMyWaifuu Dec 11, 2024
30892a6
test(e2e): Expand E2E to edit an activity
RemIsMyWaifuu Dec 11, 2024
a67a4f3
chore(e2e): Ktfmt format compliance
RemIsMyWaifuu Dec 11, 2024
b884209
Merge branch 'main' into test/e2e-activity
yassine04e Dec 11, 2024
43a8307
fix(e2e): Try to fix E2E conflicts
RemIsMyWaifuu Dec 11, 2024
5e11dff
fix(e2e): Try to fix E2E errors
RemIsMyWaifuu Dec 11, 2024
378e0a2
test(e2e): Try to fix issues by refactor
RemIsMyWaifuu Dec 11, 2024
2cdeaf7
test(e2e): Change email between E2E
RemIsMyWaifuu Dec 12, 2024
7e84da4
Merge branch 'main' into test/e2e-activity
yassine04e Dec 12, 2024
3b98808
fix: Unifying the emails acrros the e2e tests
yassine04e Dec 12, 2024
7bb4838
deleting a user after travelCreationTravel e2e
yassine04e Dec 12, 2024
ce19784
chore: adding diffrent timeouts in activity e2e to diffrenciate the f…
yassine04e Dec 12, 2024
1cf1f0a
fix: correcting the test tag on the activity e2e when no activities p…
yassine04e Dec 12, 2024
666cc43
fix: Downloading the firebase emulators with npm and not curl
yassine04e Dec 12, 2024
2127110
test(e2e): Fix E2E tags due to refactor
RemIsMyWaifuu Dec 12, 2024
93380cf
chore(e2e): Rename test file
RemIsMyWaifuu Dec 12, 2024
d7b9f62
fix: removing the test on the fields in activity e2e
yassine04e Dec 12, 2024
c045fd9
fix: Correcting faulty merge
yassine04e Dec 12, 2024
a05985e
chore(e2e): Uncomment test tags and checks
RemIsMyWaifuu Dec 12, 2024
29369ba
chore(e2e): Ktfmt format compliance
RemIsMyWaifuu Dec 12, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:

- name: Install Firebase CLI
run: |
curl -sL https://firebase.tools | bash
npm install -g firebase-tools

- name: Build functions
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package com.github.se.travelpouch.e2e

import android.icu.util.GregorianCalendar
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.isNotDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import com.github.se.travelpouch.MainActivity
import com.github.se.travelpouch.di.AppModule
import com.google.firebase.Timestamp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
@UninstallModules(AppModule::class)
class ActivityCreationAndEdit {

private val DEFAULT_TIMEOUT = 10000L

@get:Rule(order = 0) val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1) val composeTestRule = createAndroidComposeRule<MainActivity>()

@Inject lateinit var firestore: FirebaseFirestore
@Inject lateinit var auth: FirebaseAuth

@Before
fun setUp() {
hiltRule.inject()

// seed DB with existing trave @Inject lateinit var auth: FirebaseAuthl and user
runBlocking {
val uid =
auth.createUserWithEmailAndPassword("[email protected]", "password").await().user!!.uid

firestore
.collection("allTravels")
.document("w2HGCwaJ4KgcXJ5nVxkF")
.set(
mapOf(
"allAttachments" to emptyMap<String, String>(),
"allParticipants" to mapOf(uid to "OWNER"),
"description" to "Description of the test travel",
"endTime" to Timestamp(GregorianCalendar(2025, 8, 24).time),
"fsUid" to "w2HGCwaJ4KgcXJ5nVxkF",
"listParticipant" to listOf(uid),
"location" to
mapOf(
"insertTime" to Timestamp.now(),
"latitude" to 44.9305652,
"longitude" to 5.7630211,
"name" to
"trou, câble, Susville, Grenoble, Isère, Auvergne-Rhône-Alpes, France métropolitaine, 38350, France"),
"startTime" to Timestamp(GregorianCalendar(2025, 8, 23).time),
"title" to "Test"))
.await()

firestore
.collection("userslist")
.document(uid)
.set(
mapOf(
"email" to "[email protected]",
"friends" to emptyList<String>(),
"fsUid" to uid,
"name" to "Example",
"username" to "example",
"userTravelList" to listOf("w2HGCwaJ4KgcXJ5nVxkF"),
"needsOnboarding" to true))
.await()

auth.signOut()
}
}

@After
fun tearDown() {
runBlocking {
auth.signOut()
auth.signInWithEmailAndPassword("[email protected]", "password").await()
val uid = auth.currentUser!!.uid
auth.currentUser!!.delete().await()

firestore
.collection("allTravels/w2HGCwaJ4KgcXJ5nVxkF/activities")
.get()
.await()
.documents
.forEach { it.reference.delete().await() } // delete all activities
firestore.collection("allTravels").document("w2HGCwaJ4KgcXJ5nVxkF").delete().await()
firestore.collection("userslist").document(uid).delete().await()
auth.signOut()
firestore.terminate().await()
}
}

@Test
fun verifyActivityCreationAndEditFlow() =
runTest(timeout = 300.seconds) {

// assert that login screen is displayed
composeTestRule.onNodeWithTag("appLogo").assertIsDisplayed()
composeTestRule.onNodeWithTag("welcomText").assertIsDisplayed()
composeTestRule.onNodeWithText("Sign in with email and password").assertIsDisplayed()

// go to sign in screen with email and password and log in
composeTestRule.onNodeWithText("Sign in with email and password").performClick()

composeTestRule.onNodeWithTag("emailField").assertIsDisplayed()
composeTestRule.onNodeWithTag("passwordField").assertIsDisplayed()
composeTestRule.onNodeWithText("Sign up").assertIsDisplayed()
composeTestRule.onNodeWithText("Log in").assertIsDisplayed()

composeTestRule.onNodeWithTag("emailField").performTextInput("[email protected]")
composeTestRule.onNodeWithTag("passwordField").performTextInput("password")
composeTestRule.onNodeWithText("Log in").performClick()

// Skip onboarding
composeTestRule.waitUntil(timeoutMillis = DEFAULT_TIMEOUT) {
composeTestRule.onNodeWithTag("OnboardingScreen", useUnmergedTree = true).isDisplayed()
}
composeTestRule.onNodeWithTag("SkipButton").performClick()

// wait until we are in the travel list screen
composeTestRule.waitUntil(timeoutMillis = 2000) {
composeTestRule.onNodeWithText("Test", useUnmergedTree = true).isDisplayed()
}

composeTestRule.onNodeWithText("Test").assertIsDisplayed()
composeTestRule.onNodeWithTag("travelListItem").performClick()

// assert that there are no activities at the moment
composeTestRule.waitUntil(timeoutMillis = DEFAULT_TIMEOUT + 1) {
composeTestRule.onNodeWithTag("emptyTravelBox", useUnmergedTree = true).isDisplayed()
}

// add an activity button
composeTestRule.onNodeWithTag("addActivityButton").assertIsDisplayed().performClick()
// add activity screen
composeTestRule.onNodeWithTag("AddActivityScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("travelTitle").assertIsDisplayed()

// fill in the activity fields
composeTestRule.onNodeWithTag("titleField").performTextClearance()
composeTestRule.onNodeWithTag("titleField").performTextInput("epic activity")

composeTestRule.onNodeWithTag("descriptionField").performTextClearance()
composeTestRule
.onNodeWithTag("descriptionField")
.performTextInput("this is an epic activity")

composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("01022024")

composeTestRule.onNodeWithTag("timeField").performTextClearance()
composeTestRule.onNodeWithTag("timeField").performTextInput("15:24")

composeTestRule.onNodeWithTag("inputTravelLocation").performTextClearance()
composeTestRule.onNodeWithTag("inputTravelLocation").performTextInput("L")

// wait to have La paz displayed
composeTestRule.waitUntil(timeoutMillis = 4000) {
composeTestRule.onNodeWithText("La Paz, Bolivia").isDisplayed()
}

composeTestRule.onNodeWithText("La Paz, Bolivia").performClick()
// save it
composeTestRule.onNodeWithText("Save").assertIsDisplayed().performClick()
// there is an activity
composeTestRule.waitUntil(timeoutMillis = DEFAULT_TIMEOUT + 2) {
composeTestRule.onNodeWithTag("emptyTravel", useUnmergedTree = true).isNotDisplayed()
}
// check the activity is displayed
composeTestRule.onNodeWithText("epic activity").assertIsDisplayed()
composeTestRule.onNodeWithText("epic activity").assert(hasText("epic activity"))
composeTestRule.onNodeWithText("epic activity").assert(hasText("1/2/2024"))
composeTestRule.onNodeWithText("epic activity").assert(hasText("La Paz, Bolivia"))

// edit the activity
composeTestRule.onNodeWithText("epic activity").performClick()
composeTestRule.onNodeWithTag("EditActivityScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("titleField").assert(hasText("epic activity"))
composeTestRule
.onNodeWithTag("descriptionField")
.assert(hasText("this is an epic activity"))
composeTestRule.onNodeWithTag("dateField").assert(hasText("01/02/2024"))
composeTestRule.onNodeWithTag("inputTravelLocation").assert(hasText("La Paz, Bolivia"))

composeTestRule.onNodeWithTag("titleField").performTextClearance()
composeTestRule.onNodeWithTag("titleField").performTextInput("more epic activity")

composeTestRule.onNodeWithTag("descriptionField").performTextClearance()
composeTestRule
.onNodeWithTag("descriptionField")
.performTextInput("this is a more epic activity")

composeTestRule.onNodeWithTag("dateField").performTextClearance()
composeTestRule.onNodeWithTag("dateField").performTextInput("02022024")
// save the new info
composeTestRule.onNodeWithText("Save").assertIsDisplayed().performClick()
// check the activity is displayed
composeTestRule.onNodeWithText("more epic activity").assertIsDisplayed()
composeTestRule.onNodeWithText("more epic activity").assert(hasText("more epic activity"))
composeTestRule.onNodeWithText("more epic activity").assert(hasText("2/2/2024"))
composeTestRule.onNodeWithText("more epic activity").assert(hasText("La Paz, Bolivia"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Instrumentation
import android.content.Intent
import android.icu.util.GregorianCalendar
import android.net.Uri
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
Expand All @@ -23,13 +24,13 @@ import com.github.se.travelpouch.di.AppModule
import com.google.firebase.Timestamp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.storage.FirebaseStorage
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import java.io.File
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.test.runTest
Expand All @@ -47,12 +48,14 @@ class DocumentUpload {

@get:Rule(order = 0) val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1) val composeTestRule = createAndroidComposeRule<MainActivity>()
@OptIn(ExperimentalTestApi::class)
@get:Rule(order = 1)
val composeTestRule =
createAndroidComposeRule<MainActivity>(effectContext = Dispatchers.Main.immediate)

@get:Rule(order = 2) val intentsTestRule = IntentsTestRule(MainActivity::class.java)

@Inject lateinit var firestore: FirebaseFirestore
@Inject lateinit var storage: FirebaseStorage
@Inject lateinit var auth: FirebaseAuth

@Before
Expand All @@ -62,18 +65,22 @@ class DocumentUpload {
// seed the db
runBlocking {
val uid =
auth.createUserWithEmailAndPassword("[email protected]", "password").await().user!!.uid
auth
.createUserWithEmailAndPassword("[email protected]", "password2")
.await()
.user!!
.uid

firestore
.collection("allTravels")
.document("w2HGCwaJ4KgcXJ5nVxkF")
.document("skibidiJ4KgcXJ5nVxkF")
.set(
mapOf(
"allAttachments" to emptyMap<String, String>(),
"allParticipants" to mapOf(uid to "OWNER"),
"description" to "Description of the test travel",
"endTime" to Timestamp(GregorianCalendar(2025, 8, 24).time),
"fsUid" to "w2HGCwaJ4KgcXJ5nVxkF",
"fsUid" to "skibidiJ4KgcXJ5nVxkF",
"listParticipant" to listOf(uid),
"location" to
mapOf(
Expand All @@ -91,12 +98,12 @@ class DocumentUpload {
.document(uid)
.set(
mapOf(
"email" to "example.example.com",
"email" to "example2@example.com",
"friends" to emptyList<String>(),
"fsUid" to uid,
"name" to "Example",
"username" to "example",
"userTravelList" to listOf("w2HGCwaJ4KgcXJ5nVxkF"),
"userTravelList" to listOf("skibidiJ4KgcXJ5nVxkF"),
"needsOnboarding" to true))
.await()

Expand All @@ -115,22 +122,22 @@ class DocumentUpload {
fun tearDown() {
runBlocking {
auth.signOut()
auth.signInWithEmailAndPassword("example@example.com", "password").await()
auth.signInWithEmailAndPassword("example2@example.com", "password2").await()
val uid = auth.currentUser!!.uid
auth.currentUser!!.delete().await()

firestore
.collection("allTravels/w2HGCwaJ4KgcXJ5nVxkF/documents")
.collection("allTravels/skibidiJ4KgcXJ5nVxkF/documents")
.get()
.await()
.documents
.forEach { it.reference.delete().await() }
firestore.collection("allTravels").document("w2HGCwaJ4KgcXJ5nVxkF").delete().await()
firestore.collection("allTravels").document("skibidiJ4KgcXJ5nVxkF").delete().await()
firestore.collection("userslist").document(uid).delete().await()
auth.signOut()
firestore.terminate().await()
file.delete()
}

file.delete()
}

@Test
Expand All @@ -155,8 +162,8 @@ class DocumentUpload {
composeTestRule.onNodeWithText("Sign up").assertIsDisplayed()
composeTestRule.onNodeWithText("Log in").assertIsDisplayed()

composeTestRule.onNodeWithTag("emailField").performTextInput("example@example.com")
composeTestRule.onNodeWithTag("passwordField").performTextInput("password")
composeTestRule.onNodeWithTag("emailField").performTextInput("example2@example.com")
composeTestRule.onNodeWithTag("passwordField").performTextInput("password2")
composeTestRule.onNodeWithText("Log in").performClick()

// Skip onboarding
Expand All @@ -176,7 +183,7 @@ class DocumentUpload {

composeTestRule.waitUntil(timeoutMillis = DEFAULT_TIMEOUT) {
composeTestRule.onNodeWithTag("emptyTravel1", useUnmergedTree = true).isDisplayed()
composeTestRule.onNodeWithTag("emptyTravel2", useUnmergedTree = true).isDisplayed()
composeTestRule.onNodeWithTag("emptyTravel2", useUnmergedTree = true).isDisplayed()
}

composeTestRule.onNodeWithTag("travelActivitiesScreen").performTouchInput { swipeLeft() }
Expand Down
Loading
Loading