| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/payments/payment_method_selection_view_controller.h" | |
| 6 | |
| 7 #include "base/mac/foundation_util.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "components/autofill/core/browser/autofill_test_utils.h" | |
| 10 #include "components/autofill/core/browser/credit_card.h" | |
| 11 #include "components/autofill/core/browser/test_personal_data_manager.h" | |
| 12 #include "components/strings/grit/components_strings.h" | |
| 13 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | |
| 14 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | |
| 15 #include "ios/chrome/browser/payments/payment_request.h" | |
| 16 #import "ios/chrome/browser/payments/payment_request_test_util.h" | |
| 17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | |
| 18 #include "ios/chrome/grit/ios_strings.h" | |
| 19 #include "ios/web/public/payments/payment_request.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 23 #error "This file requires ARC support." | |
| 24 #endif | |
| 25 | |
| 26 class PaymentRequestPaymentMethodSelectionViewControllerTest | |
| 27 : public CollectionViewControllerTest { | |
| 28 protected: | |
| 29 PaymentRequestPaymentMethodSelectionViewControllerTest() | |
| 30 : autofill_profile_(autofill::test::GetFullProfile()), | |
| 31 credit_card1_(autofill::test::GetCreditCard()), | |
| 32 credit_card2_(autofill::test::GetCreditCard2()) { | |
| 33 // Add testing profile and credit cards to | |
| 34 // autofill::TestPersonalDataManager. | |
| 35 personal_data_manager_.AddTestingProfile(&autofill_profile_); | |
| 36 credit_card1_.set_billing_address_id(autofill_profile_.guid()); | |
| 37 personal_data_manager_.AddTestingCreditCard(&credit_card1_); | |
| 38 credit_card2_.set_billing_address_id(autofill_profile_.guid()); | |
| 39 personal_data_manager_.AddTestingCreditCard(&credit_card2_); | |
| 40 } | |
| 41 | |
| 42 CollectionViewController* InstantiateController() override { | |
| 43 payment_request_ = base::MakeUnique<PaymentRequest>( | |
| 44 payment_request_test_util::CreateTestWebPaymentRequest(), | |
| 45 &personal_data_manager_); | |
| 46 | |
| 47 return [[PaymentMethodSelectionViewController alloc] | |
| 48 initWithPaymentRequest:payment_request_.get()]; | |
| 49 } | |
| 50 | |
| 51 PaymentMethodSelectionViewController* | |
| 52 GetPaymentMethodSelectionViewController() { | |
| 53 return base::mac::ObjCCastStrict<PaymentMethodSelectionViewController>( | |
| 54 controller()); | |
| 55 } | |
| 56 | |
| 57 autofill::AutofillProfile autofill_profile_; | |
| 58 autofill::CreditCard credit_card1_; | |
| 59 autofill::CreditCard credit_card2_; | |
| 60 autofill::TestPersonalDataManager personal_data_manager_; | |
| 61 std::unique_ptr<PaymentRequest> payment_request_; | |
| 62 }; | |
| 63 | |
| 64 // Tests that the correct number of items are displayed after loading the model | |
| 65 // and that the correct item appears to be selected. | |
| 66 TEST_F(PaymentRequestPaymentMethodSelectionViewControllerTest, TestModel) { | |
| 67 CreateController(); | |
| 68 CheckController(); | |
| 69 CheckTitleWithId(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL); | |
| 70 | |
| 71 [GetPaymentMethodSelectionViewController() loadModel]; | |
| 72 | |
| 73 ASSERT_EQ(1, NumberOfSections()); | |
| 74 // One item for each of payment method plus 1 for the add button. | |
| 75 ASSERT_EQ(3U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | |
| 76 | |
| 77 // The first two items should be of type PaymentMethodItem. The first one | |
| 78 // should appear to be selected. | |
| 79 id item = GetCollectionViewItem(0, 0); | |
| 80 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); | |
| 81 PaymentMethodItem* payment_method_item = item; | |
| 82 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, | |
| 83 payment_method_item.accessoryType); | |
| 84 | |
| 85 item = GetCollectionViewItem(0, 1); | |
| 86 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); | |
| 87 payment_method_item = item; | |
| 88 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, | |
| 89 payment_method_item.accessoryType); | |
| 90 | |
| 91 // The last item should be of type TextAndMessageItem. | |
| 92 item = GetCollectionViewItem(0, 2); | |
| 93 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | |
| 94 } | |
| OLD | NEW |