Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion 5calls/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ captures/
*.jks

# Mac hidden files
.DS_Store
.DS_Store

# JEnv local Java version configuration file
.java-version
1 change: 1 addition & 0 deletions 5calls/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.7.0'
testImplementation 'androidx.test.ext:junit:1.2.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.14.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.a5calls.android.a5calls.controller;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.Intents.intending;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasData;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.Intents;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.volley.toolbox.HttpResponse;

import org.a5calls.android.a5calls.R;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

/**
* Instrumentation test for AboutActivity.
*/
public class AboutActivityTest extends MainActivityBaseTest {

private ActivityScenario<AboutActivity> aboutScenario;

@Before
@Override
public void setUp() {
super.setUp();
setupMockRequestQueue();
Intents.init();
}

@After
@Override
public void tearDown() {
if (aboutScenario != null) {
aboutScenario.close();
}
Intents.release();
super.tearDown();
}

@Test
public void testCheckRegistrationButton_launchesIntent() {
// Mock the report response to avoid errors in AboutActivity
mHttpStack.setResponseToReturn(new HttpResponse(200, new ArrayList<>(), "{\"count\": 100}".getBytes()));

aboutScenario = ActivityScenario.launch(AboutActivity.class);

Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
String expectedUrl = context.getString(R.string.check_your_registration_url);

// Prepare a stub result so the intent is intercepted and blocked from launching
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent());
intending(hasAction(Intent.ACTION_VIEW)).respondWith(result);

// The button might be inside a ScrollView, so we use scrollTo()
onView(withId(R.id.check_registration_button)).perform(scrollTo(), click());

intended(allOf(hasAction(Intent.ACTION_VIEW), hasData(Uri.parse(expectedUrl))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() |
WindowInsetsCompat.Type.displayCutout());
binding.appbar.setPadding(insets.left, insets.top, insets.right, 0);
binding.scrollView.setPadding(insets.left, 0, insets.right, insets.bottom);;
binding.scrollView.setPadding(insets.left, 0, insets.right, insets.bottom);
return WindowInsetsCompat.CONSUMED;
});

Expand All @@ -88,6 +88,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
AboutActivity.this, Uri.parse(getString(R.string.dashboard_url) +
(TextUtils.isEmpty(districtId) ? "" : "?district=" + districtId))));

binding.checkRegistrationButton.setOnClickListener(v -> CustomTabsUtil.launchUrl(
AboutActivity.this, Uri.parse(getString(R.string.check_your_registration_url))));


setOpenIntentWithChooserOnClick(
binding.contactUsButton, getSendEmailIntent(getResources()), getString(R.string.send_email)
);
Expand Down Expand Up @@ -129,12 +133,7 @@ binding.contactUsButton, getSendEmailIntent(getResources()), getString(R.string.
}
});

binding.licenseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOpenSourceLicenses();
}
});
binding.licenseButton.setOnClickListener(v -> showOpenSourceLicenses());

binding.githubTextview.setMovementMethod(LinkMovementMethod.getInstance());

Expand Down Expand Up @@ -216,10 +215,9 @@ protected void onDestroy() {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -250,9 +248,7 @@ private void showOpenSourceLicenses() {
*/
private void setOpenIntentOnClick(final View view,
final Intent intent) {
view.setOnClickListener(view1 -> {
startActivity(intent);
});
view.setOnClickListener(view1 -> startActivity(intent));
}

/**
Expand Down
17 changes: 17 additions & 0 deletions 5calls/app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@
android:text="@string/dashboard_btn"
/>

<TextView
style="@style/aboutPrompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_your_registration_prompt" />

<TextView
style="@style/paragraphTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_your_registration_description" />

<Button
android:id="@+id/check_registration_button"
style="@style/fullWidthBtnStyle"
android:text="@string/check_your_registration_button" />

<TextView
style="@style/aboutPrompt"
android:text="@string/general_prompt"
Expand Down
Loading