mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Added AboutActivityTest (#3475)
* Added AboutActivityTest * Changes made as per suggestions * Removed File to resolve conflict * Removed hardcoded packagename * Changes as per suggestion * Removed Unrelated changes * Fixed Build Issues
This commit is contained in:
parent
57ddc6af10
commit
d925e32d2f
4 changed files with 113 additions and 5 deletions
|
|
@ -0,0 +1,107 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Instrumentation
|
||||
import android.content.Intent
|
||||
import androidx.test.InstrumentationRegistry
|
||||
import androidx.test.core.app.ApplicationProvider.getApplicationContext
|
||||
import androidx.test.espresso.Espresso
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.assertion.ViewAssertions
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import fr.free.nrw.commons.utils.ConfigUtils
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AboutActivityTest {
|
||||
@get:Rule
|
||||
var activityRule: ActivityTestRule<*> = ActivityTestRule(AboutActivity::class.java)
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
Intents.init()
|
||||
Intents.intending(CoreMatchers.not(IntentMatchers.isInternal()))
|
||||
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuildNumber() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_version))
|
||||
.check(ViewAssertions.matches(withText(ConfigUtils.getVersionNameWithSha(getApplicationContext()))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchWebsite() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.website_launch_icon)).perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData(Urls.WEBSITE_URL)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchFacebook() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.facebook_launch_icon)).perform(ViewActions.click())
|
||||
Intents.intended(IntentMatchers.hasAction(Intent.ACTION_VIEW))
|
||||
Intents.intended(CoreMatchers.anyOf(IntentMatchers.hasData(Urls.FACEBOOK_WEB_URL),
|
||||
IntentMatchers.hasPackage(Urls.FACEBOOK_PACKAGE_NAME)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchGithub() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.github_launch_icon)).perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData(Urls.GITHUB_REPO_URL)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchRateUs() {
|
||||
val appPackageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_rate_us)).perform(ViewActions.click())
|
||||
Intents.intended(IntentMatchers.hasAction(Intent.ACTION_VIEW))
|
||||
Intents.intended(CoreMatchers.anyOf(IntentMatchers.hasData("${Urls.PLAY_STORE_URL_PREFIX}$appPackageName"),
|
||||
IntentMatchers.hasData("${Urls.PLAY_STORE_URL_PREFIX}$appPackageName")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchAboutPrivacyPolicy() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_privacy_policy)).perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData(BuildConfig.PRIVACY_POLICY_URL)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchTranslate() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_translate)).perform(ViewActions.click())
|
||||
Espresso.onView(ViewMatchers.withId(android.R.id.button1)).perform(ViewActions.click())
|
||||
val langCode = CommonsApplication.getInstance().languageLookUpTable.codes[0]
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData("${Urls.TRANSLATE_WIKI_URL}$langCode")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchAboutCredits() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_credits)).perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData(Urls.CREDITS_URL)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLaunchAboutFaq() {
|
||||
Espresso.onView(ViewMatchers.withId(R.id.about_faq)).perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
||||
IntentMatchers.hasData(Urls.FAQ_URL)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun orientationChange() {
|
||||
UITestHelper.changeOrientation(activityRule)
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ public class AboutActivity extends NavigationBaseActivity {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.share_app_icon:
|
||||
String shareText = String.format(getString(R.string.share_text), Urls.PLAY_STORE_URL);
|
||||
String shareText = String.format(getString(R.string.share_text), Urls.PLAY_STORE_URL_PREFIX + this.getPackageName());
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ internal object Urls {
|
|||
const val WEBSITE_URL = "https://commons-app.github.io"
|
||||
const val CREDITS_URL = "https://github.com/commons-app/apps-android-commons/blob/master/CREDITS"
|
||||
const val FAQ_URL = "https://github.com/commons-app/apps-android-commons/wiki/Frequently-Asked-Questions"
|
||||
const val PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=fr.free.nrw.commons"
|
||||
const val PLAY_STORE_PREFIX = "market://details?id="
|
||||
const val PLAY_STORE_URL_PREFIX = "https://play.google.com/store/apps/details?id="
|
||||
const val TRANSLATE_WIKI_URL = "https://translatewiki.net/w/i.php?title=Special:Translate&group=commons-android-strings&filter=%21translated&action=translate&language="
|
||||
const val FACEBOOK_WEB_URL = "https://www.facebook.com/1921335171459985"
|
||||
const val FACEBOOK_APP_URL = "fb://page/1921335171459985"
|
||||
|
|
|
|||
|
|
@ -115,12 +115,12 @@ public class Utils {
|
|||
* @param context
|
||||
*/
|
||||
public static void rateApp(Context context) {
|
||||
final String appPackageName = BuildConfig.class.getPackage().getName();
|
||||
final String appPackageName = context.getPackageName();
|
||||
try {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Urls.PLAY_STORE_PREFIX + appPackageName)));
|
||||
}
|
||||
catch (android.content.ActivityNotFoundException anfe) {
|
||||
handleWebUrl(context, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
|
||||
handleWebUrl(context, Uri.parse(Urls.PLAY_STORE_URL_PREFIX + appPackageName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue