Commit 2c2c3a72 authored by Tanisha Mandre's avatar Tanisha Mandre Committed by Commit Bot

Tests for 'Add Payment method' button with feature flag.

- Test that the delete button is visible in edit mode when a card is selected.
- Tests that bot the delete button and the 'add payment method' button are visible in edit mode and are correctly enabled/disabled.

Bug:1004349

Change-Id: I53bc9b0a4089fdf085db58f60cd2cc64650916ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807298
Commit-Queue: Tanisha Mandre <tanishamandre@google.com>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697587}
parent 18d91290
...@@ -107,6 +107,7 @@ source_set("eg_tests") { ...@@ -107,6 +107,7 @@ source_set("eg_tests") {
] ]
deps = [ deps = [
":autofill", ":autofill",
":feature_flags",
"//components/autofill/core/browser", "//components/autofill/core/browser",
"//components/autofill/core/browser:test_support", "//components/autofill/core/browser:test_support",
"//components/strings", "//components/strings",
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h" #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h" #import "ios/chrome/test/earl_grey/chrome_actions.h"
...@@ -56,6 +58,18 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -56,6 +58,18 @@ id<GREYMatcher> NavigationBarEditButton() {
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil); grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
} }
// Matcher for the Delete button in the list view, located at the bottom of the
// screen.
id<GREYMatcher> BottomToolbarDeleteButton() {
return grey_accessibilityID(kSettingsToolbarDeleteButtonId);
}
// Matcher for the Delete button in the list view, located at the bottom of the
// screen.
id<GREYMatcher> BottomToolbar() {
return grey_accessibilityID(kAutofillPaymentMethodsToolbarId);
}
} // namespace } // namespace
// Various tests for the Autofill credit cards section of the settings. // Various tests for the Autofill credit cards section of the settings.
...@@ -124,6 +138,15 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -124,6 +138,15 @@ id<GREYMatcher> NavigationBarEditButton() {
performAction:grey_tap()]; performAction:grey_tap()];
} }
// Helper to open the settings page for the Autofill credit card list in edit
// mode.
- (void)openCreditCardListInEditMode {
[self openCreditCardsSettings];
[[EarlGrey selectElementWithMatcher:NavigationBarEditButton()]
performAction:grey_tap()];
}
// Close the settings. // Close the settings.
- (void)exitSettingsMenu { - (void)exitSettingsMenu {
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
...@@ -237,4 +260,132 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -237,4 +260,132 @@ id<GREYMatcher> NavigationBarEditButton() {
[self exitSettingsMenu]; [self exitSettingsMenu];
} }
// Checks that the toolbar appears in edit mode once a card is selected and
// disappears when a card is deselected.
- (void)testToolbarInEditMode {
autofill::CreditCard creditCard = [self addCreditCard];
[self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
}
// Checks the toolbar buttons in the edit mode of the list of credit cards. The
// delete button should appear on selecting a card and be removed when no card
// is selected. There should be no 'Add payment method' button if the
// kSettingsAddPaymentMethod flag is not enabled.
- (void)testToolbarButtonsInEditMode {
autofill::CreditCard creditCard = [self addCreditCard];
[self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_nil()];
}
// Checks that the toolbar always appears in edit mode when the 'Add Payment
// method' feature is enabled.
- (void)testToolbarInEditModeAddPaymentMethodFeatureEnabled {
base::test::ScopedFeatureList featureList;
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
autofill::CreditCard creditCard = [self addCreditCard];
[self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Checks the 'Add Payment Method' button is always visible when the feature is
// enabled and directs a user to the Add Payent method view.
- (void)testToolbarAddPaymentMethodButtonFeatureEnabled {
base::test::ScopedFeatureList featureList;
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
autofill::CreditCard creditCard = [self addCreditCard];
[self openCreditCardListInEditMode];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardView()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Checks the 'Delete' button is always visible when the feature is displayed.
// The button is enabled when a card is selected and disabled when a card is not
// selected.
- (void)testToolbarDeleteButtonWithAddPaymentMethodFeatureEnabled {
base::test::ScopedFeatureList featureList;
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
autofill::CreditCard creditCard = [self addCreditCard];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
[self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_enabled())];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_enabled()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_enabled())];
}
// Checks that deleting a card exits from edit mode.
- (void)testDeletingCreditCard {
autofill::CreditCard creditCard = [self addCreditCard];
[self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
assertWithMatcher:grey_nil()];
// If the done button is nil it is no longer in edit mode.
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
assertWithMatcher:grey_nil()];
}
@end @end
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
extern NSString* const kAutofillPaymentMethodsToolbarId;
extern NSString* const kAutofillCreditCardTableViewId; extern NSString* const kAutofillCreditCardTableViewId;
extern NSString* const kAutofillCreditCardSwitchViewId; extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kSettingsAddPaymentMethodButtonId; extern NSString* const kSettingsAddPaymentMethodButtonId;
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId"; NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId";
NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch"; NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch";
NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId = NSString* const kSettingsAddPaymentMethodButtonId =
@"kSettingsAddPaymentMethodButtonId"; @"kSettingsAddPaymentMethodButtonId";
...@@ -119,6 +121,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -119,6 +121,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
[super viewDidLoad]; [super viewDidLoad];
self.tableView.allowsMultipleSelectionDuringEditing = YES; self.tableView.allowsMultipleSelectionDuringEditing = YES;
self.tableView.accessibilityIdentifier = kAutofillCreditCardTableViewId; self.tableView.accessibilityIdentifier = kAutofillCreditCardTableViewId;
self.navigationController.toolbar.accessibilityIdentifier =
kAutofillPaymentMethodsToolbarId;
base::RecordAction(base::UserMetricsAction("AutofillCreditCardsViewed")); base::RecordAction(base::UserMetricsAction("AutofillCreditCardsViewed"));
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) { if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) {
...@@ -386,6 +390,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -386,6 +390,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
_personalDataManager->RemoveByGUID(item.GUID); _personalDataManager->RemoveByGUID(item.GUID);
} }
self.editing = NO;
__weak AutofillCreditCardTableViewController* weakSelf = self; __weak AutofillCreditCardTableViewController* weakSelf = self;
[self.tableView [self.tableView
performBatchUpdates:^{ performBatchUpdates:^{
......
...@@ -42,7 +42,7 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -42,7 +42,7 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
} // namespace } // namespace
NSString* const kSettingsToolbarDeleteButtonId = NSString* const kSettingsToolbarDeleteButtonId =
@"PasswordsToolbarDeleteButtonId"; @"SettingsToolbarDeleteButtonId";
@interface SettingsRootTableViewController () @interface SettingsRootTableViewController ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment