Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ private HyperwalletIntent() {
*/
public static final short SELECT_TRANSFER_SOURCE_REQUEST_CODE = 104;

/**
* Update Transfer method request code
*/
public static final short UPDATE_TRANSFER_METHOD_REQUEST_CODE = 105;

/**
* SDK Broadcast payload error
*/
Expand All @@ -81,5 +86,10 @@ private HyperwalletIntent() {
*/
public static final String EXTRA_TRANSFER_METHOD_ADDED = "EXTRA_TRANSFER_METHOD_ADDED";

/**
* Transfer method updated, extra activity parcelable transfer method payload
*/
public static final String EXTRA_TRANSFER_METHOD_UPDATED = "EXTRA_TRANSFER_METHOD_UPDATED";


}
12 changes: 12 additions & 0 deletions commonui/src/main/res/drawable/ic_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16.8989,6.774L17.3578,6.1161C17.3741,6.0928 17.3919,6.0713 17.4111,6.0517C17.791,5.4347 17.628,4.6199 17.0264,4.198C16.5253,3.8469 15.8569,3.8701 15.3822,4.2424C15.1649,4.4128 14.8506,4.3748 14.6802,4.1575C14.5098,3.9402 14.5478,3.6259 14.7651,3.4555C15.5839,2.8134 16.7358,2.7733 17.6005,3.3792C18.6768,4.1341 18.9386,5.6184 18.1847,6.6947C18.166,6.7213 18.1453,6.7455 18.1229,6.7673L15.8996,9.9546C15.7415,10.1814 15.4292,10.2368 15.2027,10.0782L12.5123,8.1943L6.8039,16.3267L6.2983,19.5628L9.0893,17.964L13.8453,11.3236C14.0061,11.0991 14.3184,11.0475 14.5429,11.2082C14.7674,11.369 14.819,11.6814 14.6583,11.9059L9.8388,18.6349L9.6809,18.7776L5.8922,20.948C5.5283,21.1564 5.0849,20.8513 5.1496,20.4369L5.8339,16.0575C5.8457,15.9819 5.8747,15.91 5.9186,15.8474L13.5194,5.0189C13.6778,4.7931 13.9892,4.7384 14.2152,4.8965L16.8989,6.774L16.8989,6.774ZM16.3268,7.5942L14.051,6.002L13.0868,7.3758L15.366,8.9717L16.3268,7.5942L16.3268,7.5942Z"
android:strokeWidth="1"
android:fillColor="#2C2E2F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
28 changes: 10 additions & 18 deletions commonui/src/main/res/drawable/ic_trash.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="17dp"
android:height="19dp"
android:viewportWidth="17"
android:viewportHeight="19">
<path
android:pathData="M6.1332,3.6868L10.3684,3.6868L10.3684,2.6284L6.1332,2.6284L6.1332,3.6868ZM15.3208,3.6872L12.1408,3.6872C12.1416,3.6652 12.1444,3.6436 12.1444,3.6208L12.1444,2.9808C12.1444,1.8168 11.1908,0.8636 10.0268,0.8636L6.4972,0.8636C5.3324,0.8636 4.3796,1.8168 4.3796,2.9808L4.3796,3.6208C4.3796,3.6436 4.3824,3.6652 4.3832,3.6872L1.2032,3.6872C0.6208,3.6872 0.1448,4.1636 0.1448,4.7456L0.1448,5.804C0.1448,6.3868 0.6208,6.8632 1.2032,6.8632L1.5564,6.8632L1.5564,6.1568L14.968,6.1568L14.968,6.8632L15.3212,6.8632C15.9032,6.8632 16.3796,6.3868 16.3796,5.804L16.3796,4.7456C16.3792,4.1636 15.9028,3.6872 15.3208,3.6872L15.3208,3.6872Z"
android:strokeWidth="1"
android:fillAlpha="0.53999996"
android:fillColor="#000000"
android:fillType="evenOdd"
android:strokeColor="#00000000" />
<path
android:pathData="M12.1442,16.5692C12.1442,16.7636 11.985,16.9224 11.7906,16.9224L11.085,16.9224C10.8906,16.9224 10.7322,16.764 10.7322,16.5692L10.7322,9.5108C10.7322,9.3172 10.8902,9.1576 11.085,9.1576L11.7906,9.1576C11.9846,9.1576 12.1442,9.3168 12.1442,9.5108L12.1442,16.5692ZM8.9678,16.5692C8.9678,16.7636 8.8086,16.9224 8.615,16.9224L7.9086,16.9224C7.7146,16.9224 7.5558,16.764 7.5558,16.5692L7.5558,9.5108C7.5558,9.3172 7.7142,9.1576 7.9086,9.1576L8.615,9.1576C8.8078,9.1576 8.9678,9.3168 8.9678,9.5108L8.9678,16.5692ZM5.7914,16.5692C5.7914,16.7636 5.6326,16.9224 5.4386,16.9224L4.7326,16.9224C4.5382,16.9224 4.3794,16.764 4.3794,16.5692L4.3794,9.5108C4.3794,9.3172 4.5374,9.1576 4.7326,9.1576L5.4386,9.1576C5.6322,9.1576 5.7914,9.3168 5.7914,9.5108L5.7914,16.5692ZM2.2614,7.2168L2.2614,17.8044C2.2614,18.3872 2.7374,18.8636 3.3202,18.8636L13.2026,18.8636C13.785,18.8636 14.2614,18.3872 14.2614,17.8044L14.2614,7.2168L2.2614,7.2168Z"
android:strokeWidth="1"
android:fillAlpha="0.53999996"
android:fillColor="#000000"
android:fillType="evenOdd"
android:strokeColor="#00000000" />
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M14.8246,5L14.3912,3.1781C14.3756,3.0844 14.285,3 14.2544,3L10.2019,3C10.1591,3 10.0422,3.1006 10.0278,3.1827L10.0233,3.2048L9.6236,5L14.8246,5ZM14.2544,2C14.7951,2 15.285,2.4565 15.3708,2.9802L15.852,5L19.5,5C19.7761,5 20,5.2239 20,5.5C20,5.7761 19.7761,6 19.5,6L18.386,6L17.5517,19.7573C17.5065,20.5549 16.752,21 15.8789,21L11.958,20.972L8.0378,21C7.1647,21 6.4102,20.5549 6.365,19.7573L5.529,6L4.5,6C4.2239,6 4,5.7761 4,5.5C4,5.2239 4.2239,5 4.5,5L8.599,5L9.0452,2.9968C9.1486,2.4473 9.6726,2 10.2019,2L14.2544,2ZM17.385,6L6.531,6L7.3632,19.6987C7.3717,19.8484 7.6288,20 8.0343,20L11.4155,19.9765C11.4441,19.9716 11.4735,19.9692 11.5035,19.9694L11.951,19.972L12.4132,19.9694L12.5031,19.9768L12.5031,19.9768L15.8824,20C16.2879,20 16.5449,19.8484 16.5534,19.6987L17.385,6ZM12.5,8.5L12.5,18.25C12.5,18.9167 11.5,18.9167 11.5,18.25L11.5,8.5C11.5,7.8333 12.5,7.8333 12.5,8.5ZM8.9707,8.0015C9.2461,7.9804 9.4864,8.1865 9.5074,8.4618L10.2522,18.186C10.2733,18.4613 10.0672,18.7016 9.7919,18.7227C9.5165,18.7438 9.2762,18.5377 9.2551,18.2624L8.5104,8.5382C8.4893,8.2628 8.6954,8.0225 8.9707,8.0015ZM15.0379,8.0014C15.3133,8.0224 15.5195,8.2626 15.4986,8.5379L14.7586,18.2621C14.7376,18.5375 14.4974,18.7437 14.2221,18.7227C13.9467,18.7018 13.7405,18.4616 13.7614,18.1862L14.5014,8.4621C14.5224,8.1867 14.7626,7.9805 15.0379,8.0014Z"
android:strokeWidth="1"
android:fillColor="#2C2E2F"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
1 change: 1 addition & 0 deletions commonui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<string name="authentication_error_header">Authentication Error</string>
<string name="cancelButtonLabel">Cancel</string>
<string name="edit" translatable="false">Edit</string>
<string name="remove">Remove</string>
<string name="mobileAreYouSure">Are you sure?</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ public Object answer(InvocationOnMock invocation) {
assertThat(errors.getErrors().get(0), is(inError));
}

@Test
public void testGetFields_callsListenerWithFieldResultFromCacheWhenNotNull() throws Exception {
String responseBody = externalResourceManager.getResourceContent(
"successful_tmc_update_field_bank_account_response.json");
final TransferMethodUpdateConfigurationFieldResult result = JsonUtils.fromJsonString(responseBody,
new TypeReference<TransferMethodUpdateConfigurationFieldResult>() {
});

FieldMapKey fieldMapKey = new FieldMapKey(TRANSFER_METHOD_TYPE);
when(mFieldsMap.get(fieldMapKey)).thenReturn(result);

mTransferMethodUpdateConfigurationRepositoryImplMock.getFields(TRANSFER_METHOD_TYPE,TRANSFER_TOKEN, loadFieldsCallback);
verify(loadFieldsCallback, never()).onError(any(Errors.class));
}

@Test
public void testRefreshFields_clearsFieldMapWhenNotEmpty() throws Exception {
String responseBody = externalResourceManager.getResourceContent(
Expand Down
1 change: 1 addition & 0 deletions transfermethodui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation project(':commonui')
implementation project(":userrepository")
implementation project(":transfermethodrepository")
implementation project(":transferui")


androidTestImplementation "androidx.test:rules:$testRulesVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
package com.hyperwallet.android.ui.transfermethod;

import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.Root;
import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import com.hyperwallet.android.model.StatusTransition;
import com.hyperwallet.android.ui.R;
import com.hyperwallet.android.ui.common.repository.EspressoIdlingResource;
import com.hyperwallet.android.ui.common.view.error.DefaultErrorDialogFragment;
import com.hyperwallet.android.ui.testutils.rule.HyperwalletExternalResourceManager;
import com.hyperwallet.android.ui.testutils.rule.HyperwalletMockWebServer;
import com.hyperwallet.android.ui.testutils.util.RecyclerViewCountAssertion;
import com.hyperwallet.android.ui.transfermethod.repository.TransferMethodRepositoryFactory;
import com.hyperwallet.android.ui.transfermethod.rule.HyperwalletInsightMockRule;
import com.hyperwallet.android.ui.transfermethod.view.AddTransferMethodActivity;
import com.hyperwallet.android.ui.transfermethod.view.ListTransferMethodActivity;

import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.hasSibling;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.hyperwallet.android.model.StatusTransition.StatusDefinition.DE_ACTIVATED;
import static com.hyperwallet.android.ui.common.view.error.DefaultErrorDialogFragment.RESULT_ERROR;
import static com.hyperwallet.android.ui.testutils.util.EspressoUtils.atPosition;
import static com.hyperwallet.android.ui.testutils.util.EspressoUtils.nestedScrollTo;
import static com.hyperwallet.android.ui.testutils.util.EspressoUtils.withDrawable;
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

@RunWith(AndroidJUnit4.class)
public class EditTransferMethodTest {

private static final String ACCOUNT_NUMBER = "8017110254";
private static final String ROUTING_NUMBER = "211179539";

@ClassRule
public static HyperwalletExternalResourceManager sResourceManager = new HyperwalletExternalResourceManager();
@Rule
public HyperwalletInsightMockRule mHyperwalletInsightMockRule = new HyperwalletInsightMockRule();
@Rule
public HyperwalletMockWebServer mMockWebServer = new HyperwalletMockWebServer(8080);
@Rule
public ActivityTestRule<ListTransferMethodActivity> mActivityTestRule =
new ActivityTestRule<>(ListTransferMethodActivity.class, true, false);

@Before
public void setup() {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("authentication_token_response.json")).mock();
IdlingRegistry.getInstance().register(EspressoIdlingResource.getIdlingResource());
}

@After
public void cleanup() {
TransferMethodRepositoryFactory.clearInstance();
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.getIdlingResource());
}


@Test
public void testUpdateTransferMethodFragment_verifyUpdateBankAccountTransferMethod() throws InterruptedException {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("transfer_method_list_single_bank_account_response.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("transfer_method_update_bankacount_response.json")).mock();


final CountDownLatch gate = new CountDownLatch(1);
final BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
gate.countDown();

StatusTransition statusTransition = intent.getParcelableExtra(
"hyperwallet-local-broadcast-payload");
assertThat("Transition is not valid", statusTransition.getTransition(), is(DE_ACTIVATED));
}
};

// run test
mActivityTestRule.launchActivity(null);
LocalBroadcastManager.getInstance(mActivityTestRule.getActivity().getApplicationContext())
.registerReceiver(br, new IntentFilter("ACTION_HYPERWALLET_TRANSFER_METHOD_DEACTIVATED"));

// assert
onView(withId(R.id.toolbar)).check(matches(isDisplayed()));
onView(withId(R.id.toolbar))
.check(matches(
hasDescendant(withText(R.string.mobileTransferMethodsHeader))));
onView(withId(R.id.fab)).check(matches(isDisplayed()));

onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText(R.string.bank_account_font_icon)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText(R.string.bank_account)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText("United States")))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText(getEndingIn("1332"))))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));

onView(allOf(instanceOf(ImageButton.class), hasSibling(withText(R.string.bank_account)))).perform(click())
.inRoot(Matchers.<Root>instanceOf(MenuItem.class));
onView(withDrawable(R.drawable.ic_trash)).check(matches(isDisplayed()));
onView(withText(R.string.edit)).check(matches(isDisplayed())).perform(click());

onView(withId(R.id.branchIdLabel)).check(matches(isDisplayed()));

onView(withId(R.id.branchId)).perform(nestedScrollTo()).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("021000021")));

onView(ViewMatchers.withId(R.id.branchIdLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.bankAccountId))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("****")));

onView(ViewMatchers.withId(R.id.bankAccountIdLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

// ACCOUNT HOLDER INFO
onView(
Matchers.allOf(
ViewMatchers.withId(R.id.section_header_title),
ViewMatchers.withText(R.string.account_holder)
)
)
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.firstName))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("Android Mobile")));

onView(ViewMatchers.withId(R.id.firstNameLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.middleName))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("mobile-qa")));

onView(ViewMatchers.withId(R.id.middleNameLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.lastName))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("UITest")));

onView(ViewMatchers.withId(R.id.lastNameLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

// ADDRESS
onView(
Matchers.allOf(
ViewMatchers.withId(R.id.section_header_title),
ViewMatchers.withText(R.string.address)
)
).perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.country))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("Canada")));

onView(ViewMatchers.withId(R.id.countryLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.stateProvince))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("BC")));

onView(ViewMatchers.withId(R.id.stateProvinceLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.addressLine1))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("475 howe st")));

onView(ViewMatchers.withId(R.id.addressLine1Label))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.city))
.perform(nestedScrollTo())
.check(matches(withText("vancouver")))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.cityLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

onView(ViewMatchers.withId(R.id.postalCode))
.perform(nestedScrollTo())
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(matches(withText("V6Z1L2")));

onView(ViewMatchers.withId(R.id.postalCodeLabel))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));

}

private String getEndingIn(String ending) {
return String.format(InstrumentationRegistry.getInstrumentation().getTargetContext()
.getString(R.string.endingIn), ending);
}

}
Loading