1
+ package fr.free.nrw.commons
2
+
3
+ import android.app.Activity
4
+ import android.app.Instrumentation
5
+ import android.content.Intent
6
+ import androidx.test.InstrumentationRegistry
7
+ import androidx.test.core.app.ApplicationProvider.getApplicationContext
8
+ import androidx.test.espresso.Espresso
9
+ import androidx.test.espresso.action.ViewActions
10
+ import androidx.test.espresso.assertion.ViewAssertions
11
+ import androidx.test.espresso.intent.Intents
12
+ import androidx.test.espresso.intent.matcher.IntentMatchers
13
+ import androidx.test.espresso.matcher.ViewMatchers
14
+ import androidx.test.espresso.matcher.ViewMatchers.withText
15
+ import androidx.test.rule.ActivityTestRule
16
+ import androidx.test.runner.AndroidJUnit4
17
+ import fr.free.nrw.commons.utils.ConfigUtils
18
+ import org.hamcrest.CoreMatchers
19
+ import org.junit.Before
20
+ import org.junit.Rule
21
+ import org.junit.Test
22
+ import org.junit.runner.RunWith
23
+
24
+ @RunWith(AndroidJUnit4 ::class )
25
+ class AboutActivityTest {
26
+ @get:Rule
27
+ var activityRule: ActivityTestRule <* > = ActivityTestRule (AboutActivity ::class .java)
28
+
29
+ @Before
30
+ fun setup () {
31
+ Intents .init ()
32
+ Intents .intending(CoreMatchers .not (IntentMatchers .isInternal()))
33
+ .respondWith(Instrumentation .ActivityResult (Activity .RESULT_OK , null ))
34
+ }
35
+
36
+ @Test
37
+ fun testBuildNumber () {
38
+ Espresso .onView(ViewMatchers .withId(R .id.about_version))
39
+ .check(ViewAssertions .matches(withText(ConfigUtils .getVersionNameWithSha(getApplicationContext()))))
40
+ }
41
+
42
+ @Test
43
+ fun testLaunchWebsite () {
44
+ Espresso .onView(ViewMatchers .withId(R .id.website_launch_icon)).perform(ViewActions .click())
45
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
46
+ IntentMatchers .hasData(Urls .WEBSITE_URL )))
47
+ }
48
+
49
+ @Test
50
+ fun testLaunchFacebook () {
51
+ Espresso .onView(ViewMatchers .withId(R .id.facebook_launch_icon)).perform(ViewActions .click())
52
+ Intents .intended(IntentMatchers .hasAction(Intent .ACTION_VIEW ))
53
+ Intents .intended(CoreMatchers .anyOf(IntentMatchers .hasData(Urls .FACEBOOK_WEB_URL ),
54
+ IntentMatchers .hasPackage(Urls .FACEBOOK_PACKAGE_NAME )))
55
+ }
56
+
57
+ @Test
58
+ fun testLaunchGithub () {
59
+ Espresso .onView(ViewMatchers .withId(R .id.github_launch_icon)).perform(ViewActions .click())
60
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
61
+ IntentMatchers .hasData(Urls .GITHUB_REPO_URL )))
62
+ }
63
+
64
+ @Test
65
+ fun testLaunchRateUs () {
66
+ val appPackageName = InstrumentationRegistry .getInstrumentation().targetContext.packageName
67
+ Espresso .onView(ViewMatchers .withId(R .id.about_rate_us)).perform(ViewActions .click())
68
+ Intents .intended(IntentMatchers .hasAction(Intent .ACTION_VIEW ))
69
+ Intents .intended(CoreMatchers .anyOf(IntentMatchers .hasData(" ${Urls .PLAY_STORE_URL_PREFIX }$appPackageName " ),
70
+ IntentMatchers .hasData(" ${Urls .PLAY_STORE_URL_PREFIX }$appPackageName " )))
71
+ }
72
+
73
+ @Test
74
+ fun testLaunchAboutPrivacyPolicy () {
75
+ Espresso .onView(ViewMatchers .withId(R .id.about_privacy_policy)).perform(ViewActions .click())
76
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
77
+ IntentMatchers .hasData(BuildConfig .PRIVACY_POLICY_URL )))
78
+ }
79
+
80
+ @Test
81
+ fun testLaunchTranslate () {
82
+ Espresso .onView(ViewMatchers .withId(R .id.about_translate)).perform(ViewActions .click())
83
+ Espresso .onView(ViewMatchers .withId(android.R .id.button1)).perform(ViewActions .click())
84
+ val langCode = CommonsApplication .getInstance().languageLookUpTable.codes[0 ]
85
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
86
+ IntentMatchers .hasData(" ${Urls .TRANSLATE_WIKI_URL }$langCode " )))
87
+ }
88
+
89
+ @Test
90
+ fun testLaunchAboutCredits () {
91
+ Espresso .onView(ViewMatchers .withId(R .id.about_credits)).perform(ViewActions .click())
92
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
93
+ IntentMatchers .hasData(Urls .CREDITS_URL )))
94
+ }
95
+
96
+ @Test
97
+ fun testLaunchAboutFaq () {
98
+ Espresso .onView(ViewMatchers .withId(R .id.about_faq)).perform(ViewActions .click())
99
+ Intents .intended(CoreMatchers .allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW ),
100
+ IntentMatchers .hasData(Urls .FAQ_URL )))
101
+ }
102
+
103
+ @Test
104
+ fun orientationChange () {
105
+ UITestHelper .changeOrientation(activityRule)
106
+ }
107
+ }
0 commit comments