-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added AboutActivityTest #3475
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
Merged
Merged
Added AboutActivityTest #3475
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e4aa049
Added AboutActivityTest
madhurgupta10 d0132b1
Changes made as per suggestions
madhurgupta10 b3a4b21
Removed File to resolve conflict
madhurgupta10 46ed710
Removed hardcoded packagename
madhurgupta10 a43dda4
Changes as per suggestion
madhurgupta10 8713ea0
Removed Unrelated changes
madhurgupta10 18917da
Fixed Build Issues
madhurgupta10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
app/src/androidTest/java/fr/free/nrw/commons/AboutActivityTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
app/src/androidTest/java/fr/free/nrw/commons/ViewActions.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.