Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: ios/chrome/browser/payments/credit_card_edit_view_controller_unittest.mm

Issue 2825143002: [Payment Request] Accepted credit card type icons in the credit card editor (Closed)
Patch Set: Initial Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/payments/credit_card_edit_view_controller.h" 5 #import "ios/chrome/browser/payments/credit_card_edit_view_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "components/autofill/core/browser/field_types.h" 9 #include "components/autofill/core/browser/field_types.h"
10 #import "ios/chrome/browser/payments/cells/accepted_payment_methods_item.h"
10 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 11 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
11 #import "ios/chrome/browser/payments/payment_request_editor_field.h" 12 #import "ios/chrome/browser/payments/payment_request_editor_field.h"
12 #include "ios/chrome/browser/payments/payment_request_test_util.h" 13 #include "ios/chrome/browser/payments/payment_request_test_util.h"
13 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" 14 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
14 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" 15 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
18 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h" 19 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h"
19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " 20 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h "
20 #include "ios/web/public/payments/payment_request.h" 21 #include "ios/web/public/payments/payment_request.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 #if !defined(__has_feature) || !__has_feature(objc_arc) 24 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support." 25 #error "This file requires ARC support."
25 #endif 26 #endif
26 27
27 @interface TestCreditCardEditViewControllerMediator 28 @interface TestCreditCardEditViewControllerMediator
28 : NSObject<CreditCardEditViewControllerDataSource> 29 : NSObject<CreditCardEditViewControllerDataSource>
29 30
30 @end 31 @end
31 32
32 @implementation TestCreditCardEditViewControllerMediator 33 @implementation TestCreditCardEditViewControllerMediator
33 34
34 - (CollectionViewItem*)serverCardSummaryItem { 35 - (CollectionViewItem*)serverCardSummaryItem {
35 return [[PaymentMethodItem alloc] init]; 36 return [[PaymentMethodItem alloc] init];
36 } 37 }
37 38
39 - (CollectionViewItem*)acceptedPaymentMethodsItem {
40 return [[AcceptedPaymentMethodsItem alloc] init];
41 }
42
38 - (NSArray<EditorField*>*)editorFields { 43 - (NSArray<EditorField*>*)editorFields {
39 return @[ 44 return @[
40 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardNumber 45 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardNumber
41 label:@"Credit Card Number" 46 label:@"Credit Card Number"
42 value:@"4111111111111111" /* Visa */ 47 value:@"4111111111111111" /* Visa */
43 required:YES], 48 required:YES],
44 [[EditorField alloc] 49 [[EditorField alloc]
45 initWithAutofillUIType:AutofillUITypeCreditCardHolderFullName 50 initWithAutofillUIType:AutofillUITypeCreditCardHolderFullName
46 label:@"Cardholder Name" 51 label:@"Cardholder Name"
47 value:@"John Doe" 52 value:@"John Doe"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 94
90 // Tests that the correct number of items are displayed after loading the model. 95 // Tests that the correct number of items are displayed after loading the model.
91 TEST_F(PaymentRequestCreditCardEditViewControllerTest, TestModel) { 96 TEST_F(PaymentRequestCreditCardEditViewControllerTest, TestModel) {
92 CreateController(); 97 CreateController();
93 CheckController(); 98 CheckController();
94 99
95 [GetCreditCardEditViewController() 100 [GetCreditCardEditViewController()
96 setState:CreditCardEditViewControllerStateEdit]; 101 setState:CreditCardEditViewControllerStateEdit];
97 [GetCreditCardEditViewController() loadModel]; 102 [GetCreditCardEditViewController() loadModel];
98 103
99 // There is one section for every textfield (there are four textfields in 104 // There is one section containing the credit card type icons for the accepted
100 // total), one for the server card summary section, one for the footer, and 105 // payment methods. In addition to that, there is one section for every
101 // one for the billing address ID item. 106 // textfield (there are four textfields in total), one for the server card
102 ASSERT_EQ(7, NumberOfSections()); 107 // summary section, one for the footer, and one for the billing address ID
108 // item.
109 ASSERT_EQ(8, NumberOfSections());
103 110
104 // The server card summary section is the first section and has one item of 111 // The server card summary section is the first section and has one item of
105 // the type PaymentMethodItem. 112 // the type PaymentMethodItem.
106 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); 113 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0)));
107 id item = GetCollectionViewItem(0, 0); 114 id item = GetCollectionViewItem(0, 0);
108 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); 115 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]);
109 116
110 // The next four sections have only one item of the type AutofillEditItem. 117 // The next section is the accepted payment methods section and has one item
118 // of the type AcceptedPaymentMethodsItem.
111 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); 119 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1)));
112 item = GetCollectionViewItem(1, 0); 120 item = GetCollectionViewItem(1, 0);
113 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); 121 EXPECT_TRUE([item isMemberOfClass:[AcceptedPaymentMethodsItem class]]);
114 122
123 // The next four sections have only one item of the type AutofillEditItem.
115 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); 124 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2)));
116 item = GetCollectionViewItem(2, 0); 125 item = GetCollectionViewItem(2, 0);
117 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); 126 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]);
118 127
119 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); 128 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3)));
120 item = GetCollectionViewItem(3, 0); 129 item = GetCollectionViewItem(3, 0);
121 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); 130 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]);
122 131
123 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(4))); 132 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(4)));
124 item = GetCollectionViewItem(4, 0); 133 item = GetCollectionViewItem(4, 0);
125 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); 134 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]);
126 135
136 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(5)));
137 item = GetCollectionViewItem(5, 0);
138 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]);
139
127 // The billing address section contains one item which is of the type 140 // The billing address section contains one item which is of the type
128 // CollectionViewDetailItem. 141 // CollectionViewDetailItem.
129 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(5))); 142 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6)));
130 item = GetCollectionViewItem(5, 0); 143 item = GetCollectionViewItem(6, 0);
131 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]); 144 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]);
132 CollectionViewDetailItem* billing_address_item = item; 145 CollectionViewDetailItem* billing_address_item = item;
133 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, 146 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator,
134 billing_address_item.accessoryType); 147 billing_address_item.accessoryType);
135 148
136 // The footer section contains one item which is of the type 149 // The footer section contains one item which is of the type
137 // CollectionViewFooterItem. 150 // CollectionViewFooterItem.
138 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6))); 151 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(7)));
139 item = GetCollectionViewItem(6, 0); 152 item = GetCollectionViewItem(7, 0);
140 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); 153 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]);
141 } 154 }
142 155
143 // Tests that the correct number of items are displayed after loading the model, 156 // Tests that the correct number of items are displayed after loading the model,
144 // when creating a new credit card. 157 // when creating a new credit card.
145 TEST_F(PaymentRequestCreditCardEditViewControllerTest, 158 TEST_F(PaymentRequestCreditCardEditViewControllerTest,
146 TestModelCreateNewCreditCard) { 159 TestModelCreateNewCreditCard) {
147 CreateController(); 160 CreateController();
148 CheckController(); 161 CheckController();
149 162
150 [GetCreditCardEditViewController() 163 [GetCreditCardEditViewController()
151 setState:CreditCardEditViewControllerStateCreate]; 164 setState:CreditCardEditViewControllerStateCreate];
152 [GetCreditCardEditViewController() loadModel]; 165 [GetCreditCardEditViewController() loadModel];
153 166
154 // There is an extra section containing a switch that allows the user to save 167 // There is an extra section containing a switch that allows the user to save
155 // the credit card locally. 168 // the credit card locally.
156 ASSERT_EQ(8, NumberOfSections()); 169 ASSERT_EQ(9, NumberOfSections());
157 170
158 // The switch section is the last section before the footer and has one item 171 // The switch section is the last section before the footer and has one item
159 // of the type CollectionViewSwitchItem. The switch is on by defualt. 172 // of the type CollectionViewSwitchItem. The switch is on by defualt.
160 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6))); 173 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(7)));
161 id item = GetCollectionViewItem(6, 0); 174 id item = GetCollectionViewItem(7, 0);
162 EXPECT_TRUE([item isMemberOfClass:[CollectionViewSwitchItem class]]); 175 EXPECT_TRUE([item isMemberOfClass:[CollectionViewSwitchItem class]]);
163 CollectionViewSwitchItem* switch_item = item; 176 CollectionViewSwitchItem* switch_item = item;
164 EXPECT_EQ(YES, [switch_item isOn]); 177 EXPECT_EQ(YES, [switch_item isOn]);
165 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698