1+ package com.amrdeveloper.linkhub
2+
3+ import android.content.Intent
4+ import androidx.test.espresso.Espresso.onView
5+ import androidx.test.espresso.assertion.ViewAssertions.matches
6+ import androidx.test.espresso.intent.rule.IntentsTestRule
7+ import androidx.test.espresso.matcher.ViewMatchers.withId
8+ import androidx.test.espresso.matcher.ViewMatchers.withText
9+ import androidx.test.ext.junit.runners.AndroidJUnit4
10+ import com.amrdeveloper.linkhub.ui.MainActivity
11+ import org.junit.Rule
12+ import org.junit.Test
13+ import org.junit.runner.RunWith
14+
15+ @RunWith(AndroidJUnit4 ::class )
16+ class ShareLinkTest {
17+ @get:Rule
18+ val intentsTestRule = IntentsTestRule (MainActivity ::class .java, true , false )
19+
20+ private fun runCaseFor (sharedLink : String , title : String , subTitle : String ) {
21+ val intent = Intent (Intent .ACTION_SEND ).apply {
22+ putExtra(Intent .EXTRA_TEXT , sharedLink)
23+ }
24+ intentsTestRule.launchActivity(intent)
25+
26+ onView(withId(R .id.link_url_edit))
27+ .check(matches(withText(sharedLink)))
28+ onView(withId(R .id.link_title_edit))
29+ .check(matches(withText(title)))
30+ onView(withId(R .id.link_subtitle_edit))
31+ .check(matches(withText(subTitle)))
32+ }
33+
34+ @Test
35+ fun generalLink () {
36+ runCaseFor(" https://amr.com" , " amr Link" , " Link from amr website" )
37+ }
38+
39+ @Test
40+ fun stackoverflowQuestion () {
41+ runCaseFor(" https://stackoverflow.com/questions/android" , " Programming question" , " Question from stackoverflow.com" )
42+ }
43+
44+ @Test
45+ fun linkContainsSpace () {
46+ // not a valid URI, skip generation
47+ runCaseFor(" https://www.example.com/hello world" , " " , " " )
48+ }
49+ }
0 commit comments