@@ -21,12 +21,13 @@ import androidx.recyclerview.widget.RecyclerView
2121import androidx.test.espresso.Espresso.onView
2222import androidx.test.espresso.action.ViewActions.click
2323import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
24- import androidx.test.espresso.action.ViewActions.swipeDown
2524import androidx.test.espresso.action.ViewActions.typeText
2625import androidx.test.espresso.assertion.ViewAssertions.matches
2726import androidx.test.espresso.contrib.RecyclerViewActions
27+ import androidx.test.espresso.intent.Intents
2828import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
2929import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
30+ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
3031import androidx.test.espresso.matcher.ViewMatchers.isRoot
3132import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
3233import androidx.test.espresso.matcher.ViewMatchers.withId
@@ -42,11 +43,15 @@ import com.infomaniak.mail.R
4243import com.infomaniak.mail.ui.Scenarios.waitFor
4344import com.infomaniak.mail.ui.Utils.assertRecipientInField
4445import com.infomaniak.mail.ui.Utils.enterEmailToField
46+ import com.infomaniak.mail.ui.Utils.getFakeAttachment
47+ import com.infomaniak.mail.ui.Utils.interceptFilePickerIntent
4548import com.infomaniak.mail.ui.Utils.onViewWithTimeout
4649import com.infomaniak.mail.ui.login.BaseActivityTest
4750import com.infomaniak.mail.ui.login.LoginActivity
4851import org.hamcrest.CoreMatchers.containsString
4952import org.hamcrest.core.AllOf.allOf
53+ import org.junit.After
54+ import org.junit.Before
5055import org.junit.Test
5156import org.junit.runner.RunWith
5257import java.util.UUID
@@ -57,8 +62,20 @@ import kotlin.time.Duration.Companion.seconds
5762@LargeTest
5863class NewMessageActivityTest : BaseActivityTest (startingActivity = LoginActivity : :class) {
5964
65+ @Before
66+ fun initIntents () = Intents .init ()
67+
68+ @After
69+ fun releaseIntents () = Intents .release()
70+
6071 @Test
61- fun sendEmail () {
72+ fun sendEmailWithAttachment () {
73+ val fakeAttachment = getFakeAttachment()
74+ interceptFilePickerIntent(fakeAttachment.uri)
75+
76+ val subjectUuid = UUID .randomUUID().toString()
77+ val subject = " UI test mail attachment #$subjectUuid "
78+
6279 onViewWithTimeout(
6380 retryInterval = 500 .milliseconds,
6481 matcher = withId(R .id.newMessageFab)
@@ -67,8 +84,59 @@ class NewMessageActivityTest : BaseActivityTest(startingActivity = LoginActivity
6784 // Waiting for the view to settle
6885 onView(isRoot()).perform(waitFor(3 .seconds))
6986
70- // Dismissing the AI BottomSheet. Clicking on "Later" is not working for some reason
71- device.click(0 , 0 )
87+ onView(withId(R .id.editorAttachment)).perform(click())
88+
89+ onViewWithTimeout(matcher = withId(R .id.attachmentsRecyclerView), assertion = matches(isDisplayed()))
90+ onViewWithTimeout(matcher = withText(fakeAttachment.name), assertion = matches(isDisplayed()))
91+
92+ onView(
93+ allOf(
94+ withId(R .id.chevron),
95+ isDescendantOfA(withId(R .id.toField))
96+ )
97+ ).perform(click())
98+ enterEmailToField(R .id.toField, " uitest.test@ik.me" , R .id.autoCompleteTo)
99+ onView(withId(R .id.subjectTextField)).perform(click(), typeText(subject), closeSoftKeyboard())
100+ onView(withId(R .id.sendButton)).perform(click())
101+
102+ // Waiting for the mail to appear in the Thread list fragment
103+ onViewWithTimeout(
104+ numberOfRetries = 20 ,
105+ retryInterval = 5_000 .milliseconds,
106+ matcher = withId(R .id.threadsList),
107+ assertion = matches(hasDescendant(withText(subject))),
108+ )
109+
110+ // Open the received email
111+ onViewWithTimeout(
112+ retryInterval = 500 .milliseconds,
113+ matcher = allOf(withId(R .id.threadsList), hasDescendant(withText(subject))),
114+ ).perform(
115+ RecyclerViewActions .actionOnItem<RecyclerView .ViewHolder >(
116+ hasDescendant(withText(subject)),
117+ click(),
118+ )
119+ )
120+
121+ // Verify that the attachment with the correct name is displayed in the received email
122+ onViewWithTimeout(
123+ retryInterval = 2_000 .milliseconds,
124+ matcher = allOf(withId(R .id.fileName), withText(fakeAttachment.name)),
125+ assertion = matches(isDisplayed()),
126+ )
127+
128+ fakeAttachment.file.delete()
129+ }
130+
131+ @Test
132+ fun sendEmail () {
133+ onViewWithTimeout(
134+ retryInterval = 500 .milliseconds,
135+ matcher = withId(R .id.newMessageFab)
136+ ).perform(click())
137+
138+ // Waiting for the view to settle
139+ onView(isRoot()).perform(waitFor(3 .seconds))
72140
73141 // Just clicking on the toField does not work ...
74142 onView(
@@ -88,10 +156,9 @@ class NewMessageActivityTest : BaseActivityTest(startingActivity = LoginActivity
88156 onView(withId(R .id.editorWebView)).perform(click(), typeText(" This is an email from UI test" ), closeSoftKeyboard())
89157 onView(withId(R .id.sendButton)).perform(click())
90158
91- onView(withId(R .id.threadsList)).perform(swipeDown())
92-
93159 // Checking if the email with a specific ID to be received
94160 onViewWithTimeout(
161+ numberOfRetries = 20 ,
95162 retryInterval = 5_000 .milliseconds,
96163 matcher = withId(R .id.threadsList),
97164 assertion = matches(hasDescendant(withText(subject))),
@@ -116,9 +183,6 @@ class NewMessageActivityTest : BaseActivityTest(startingActivity = LoginActivity
116183 // Waiting for the view to settle
117184 onView(isRoot()).perform(waitFor(3 .seconds))
118185
119- // Dismissing the AI BottomSheet. Clicking on "Later" is not working for some reason
120- device.click(0 , 0 )
121-
122186 onView(
123187 allOf(
124188 withId(R .id.chevron),
0 commit comments