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 @@ -90,7 +90,6 @@ public void testListTransferMethod_userHasMultipleTransferMethods() {
mActivityTestRule.launchActivity(null);

// assert
onView(withId(R.id.toolbar)).check(matches(isDisplayed()));
onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.toolbar))))
.check(matches(withText(R.string.title_activity_list_transfer_method)));
onView(withId(R.id.fab)).check(matches(isDisplayed()));
Expand Down Expand Up @@ -146,7 +145,17 @@ public void testListTransferMethod_userHasMultipleTransferMethods() {
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(4, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));

onView(withId(R.id.list_transfer_method_item)).check(new RecyclerViewCountAssertion(5));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withText(R.string.paypal_account_font_icon)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withText(R.string.paypal_account)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withText("United States")))));
//TODO: Try to check for non existence of transfer_method_type_description_2
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));

onView(withId(R.id.list_transfer_method_item)).check(new RecyclerViewCountAssertion(6));

}

Expand Down Expand Up @@ -337,6 +346,70 @@ public void onReceive(Context context, Intent intent) {

}

@Test
public void testListTransferMethod_removePayPalAccount() throws InterruptedException {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("transfer_method_list_single_paypal_account_response.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("transfer_method_deactivate_success.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody("").mock();


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

HyperwalletStatusTransition 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(allOf(instanceOf(TextView.class), withParent(withId(R.id.toolbar))))
.check(matches(withText(R.string.title_activity_list_transfer_method)));
onView(withId(R.id.fab)).check(matches(isDisplayed()));

onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText(R.string.paypal_account_font_icon)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(0, hasDescendant(withText(R.string.paypal_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(withDrawable(R.drawable.ic_three_dots_16dp)))));

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

// confirmation dialog is shown before deletion
onView(withText(R.string.transfer_method_remove_confirmation_title)).check(matches(isDisplayed()));
onView(withText(R.string.transfer_method_remove_confirmation)).check(matches(isDisplayed()));
onView(withId(android.R.id.button1)).check(matches(withText(R.string.remove_button_label)));
onView(withId(android.R.id.button2)).check(matches(withText(R.string.cancel_button_label)));

onView(withId(android.R.id.button1)).perform(click());

gate.await(5, SECONDS);
LocalBroadcastManager.getInstance(mActivityTestRule.getActivity().getApplicationContext()).unregisterReceiver(
br);
assertThat("Action is not broadcasted", gate.getCount(), is(0L));

onView(withId(R.id.empty_transfer_method_list_layout)).check(matches(isDisplayed()));
onView(withText(R.string.empty_list_transfer_method_information)).check(matches(isDisplayed()));

}

@Test
public void testListTransferMethod_removeBankAccountClickCancel() throws InterruptedException {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;

import android.os.Handler;

Expand Down Expand Up @@ -89,6 +90,10 @@ public void deactivateTransferMethod(@NonNull final HyperwalletTransferMethod tr
break;
case BANK_CARD:
deactivateBankCardAccount(transferMethod, callback);
break;
case PAYPAL_ACCOUNT:
deactivatePayPalAccount(transferMethod, callback);
break;
default: //no default action
}
}
Expand Down Expand Up @@ -135,6 +140,27 @@ public Handler getHandler() {
});
}

private void deactivatePayPalAccount(@NonNull final HyperwalletTransferMethod transferMethod,
@NonNull final DeactivateTransferMethodCallback callback) {
getHyperwallet().deactivatePayPalAccount(transferMethod.getField(TOKEN), null,
new HyperwalletListener<HyperwalletStatusTransition>() {
@Override
public void onSuccess(@Nullable HyperwalletStatusTransition result) {
callback.onTransferMethodDeactivated(result);
}

@Override
public void onFailure(HyperwalletException exception) {
callback.onError(exception.getHyperwalletErrors());
}

@Override
public Handler getHandler() {
return mHandler;
}
});
}

private void createBankAccount(final HyperwalletTransferMethod transferMethod,
final LoadTransferMethodCallback callback) {
HyperwalletBankAccount bankAccount = (HyperwalletBankAccount) transferMethod;
Expand Down
4 changes: 3 additions & 1 deletion ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@
<string name="wire_account">Wire Account</string>
<string name="paper_check">Paper Check</string>
<string name="prepaid_card">Prepaid Card</string>
<string name="paypal_account">PayPal</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be PayPal Account ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to @jsaini-hw it should be PayPal


<string name="bank_account_font_icon">\uE000</string>
<string name="bank_card_font_icon">\uE005</string>
<string name="wire_account_font_icon">\uE00D</string>
<string name="paper_check_font_icon">\uE002</string>
<string name="prepaid_card_font_icon">\uE00E</string>
<string name="prepaid_card_font_icon">\uE00A</string>
<string name="paypal_account_font_icon">\uE021</string>

<string name="search_hint">Search Hint</string>
<string name="search_country">Search Country</string>
Expand Down
Loading