OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include <vector> |
| 6 |
| 7 #include "base/mac/foundation_util.h" |
| 8 #include "components/autofill/core/browser/autofill_profile.h" |
| 9 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller.
h" |
| 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 11 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 12 #include "ios/chrome/grit/ios_strings.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 class ShippingAddressSelectionViewControllerTest |
| 18 : public CollectionViewControllerTest { |
| 19 protected: |
| 20 CollectionViewController* NewController() override NS_RETURNS_RETAINED { |
| 21 return [[ShippingAddressSelectionViewController alloc] init]; |
| 22 } |
| 23 |
| 24 ShippingAddressSelectionViewController* ShippingAddressSelectionController() { |
| 25 return base::mac::ObjCCastStrict<ShippingAddressSelectionViewController>( |
| 26 controller()); |
| 27 } |
| 28 }; |
| 29 |
| 30 // Tests that the correct number of items are displayed after loading the model |
| 31 // and that the correct item appears to be selected. |
| 32 TEST_F(ShippingAddressSelectionViewControllerTest, TestModel) { |
| 33 CreateController(); |
| 34 CheckController(); |
| 35 CheckTitleWithId(IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE); |
| 36 |
| 37 std::unique_ptr<autofill::AutofillProfile> profile1( |
| 38 new autofill::AutofillProfile()); |
| 39 std::unique_ptr<autofill::AutofillProfile> profile2( |
| 40 new autofill::AutofillProfile()); |
| 41 |
| 42 std::vector<autofill::AutofillProfile*> shippingAddresses; |
| 43 shippingAddresses.push_back(profile1.get()); |
| 44 shippingAddresses.push_back(profile2.get()); |
| 45 |
| 46 [ShippingAddressSelectionController() setShippingAddresses:shippingAddresses]; |
| 47 [ShippingAddressSelectionController() |
| 48 setSelectedShippingAddress:shippingAddresses[0]]; |
| 49 [ShippingAddressSelectionController() loadModel]; |
| 50 |
| 51 ASSERT_EQ(1, NumberOfSections()); |
| 52 // One item for each of shipping addresses plus 1 for the add button. |
| 53 EXPECT_EQ(shippingAddresses.size() + 1, |
| 54 static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 55 |
| 56 // The first address should appear to be selected. |
| 57 CollectionViewTextItem* item = GetCollectionViewItem(0, 0); |
| 58 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, item.accessoryType); |
| 59 item = GetCollectionViewItem(0, 1); |
| 60 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, item.accessoryType); |
| 61 } |
| 62 |
| 63 } // namespace |
OLD | NEW |