| 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/shipping_option_selection_view_controller.h
" | |
| 6 | |
| 7 #include "base/mac/foundation_util.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "components/autofill/core/browser/test_personal_data_manager.h" | |
| 11 #include "components/strings/grit/components_strings.h" | |
| 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | |
| 13 #include "ios/chrome/browser/payments/payment_request.h" | |
| 14 #import "ios/chrome/browser/payments/payment_request_test_util.h" | |
| 15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | |
| 16 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | |
| 17 #include "ios/web/public/payments/payment_request.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 21 #error "This file requires ARC support." | |
| 22 #endif | |
| 23 | |
| 24 class PaymentRequestShippingOptionSelectionViewControllerTest | |
| 25 : public CollectionViewControllerTest { | |
| 26 protected: | |
| 27 CollectionViewController* InstantiateController() override { | |
| 28 payment_request_ = base::MakeUnique<PaymentRequest>( | |
| 29 payment_request_test_util::CreateTestWebPaymentRequest(), | |
| 30 &personal_data_manager_); | |
| 31 | |
| 32 return [[ShippingOptionSelectionViewController alloc] | |
| 33 initWithPaymentRequest:payment_request_.get()]; | |
| 34 } | |
| 35 | |
| 36 ShippingOptionSelectionViewController* | |
| 37 GetShippingOptionSelectionViewController() { | |
| 38 return base::mac::ObjCCastStrict<ShippingOptionSelectionViewController>( | |
| 39 controller()); | |
| 40 } | |
| 41 | |
| 42 autofill::TestPersonalDataManager personal_data_manager_; | |
| 43 std::unique_ptr<PaymentRequest> payment_request_; | |
| 44 }; | |
| 45 | |
| 46 // Tests that the correct number of items are displayed after loading the model | |
| 47 // and that the correct item appears to be selected. | |
| 48 TEST_F(PaymentRequestShippingOptionSelectionViewControllerTest, TestModel) { | |
| 49 CreateController(); | |
| 50 CheckController(); | |
| 51 CheckTitleWithId(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | |
| 52 | |
| 53 [GetShippingOptionSelectionViewController() loadModel]; | |
| 54 | |
| 55 ASSERT_EQ(1, NumberOfSections()); | |
| 56 // One item for each of shipping options. | |
| 57 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | |
| 58 | |
| 59 // The next two items should be of type PaymentsTextItem. The first one | |
| 60 // should appear to be selected. | |
| 61 id item = GetCollectionViewItem(0, 0); | |
| 62 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | |
| 63 PaymentsTextItem* text_item = item; | |
| 64 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, text_item.accessoryType); | |
| 65 | |
| 66 item = GetCollectionViewItem(0, 1); | |
| 67 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | |
| 68 text_item = item; | |
| 69 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, text_item.accessoryType); | |
| 70 | |
| 71 // Test the error state. | |
| 72 [GetShippingOptionSelectionViewController() setErrorMessage:@"Lorem ipsum"]; | |
| 73 [GetShippingOptionSelectionViewController() loadModel]; | |
| 74 | |
| 75 ASSERT_EQ(1, NumberOfSections()); | |
| 76 // There should be 3 items now in total. | |
| 77 ASSERT_EQ(3U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | |
| 78 | |
| 79 // The first item should also be of type TextAndMessageItem. | |
| 80 item = GetCollectionViewItem(0, 0); | |
| 81 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | |
| 82 | |
| 83 // Test the pending state. | |
| 84 [GetShippingOptionSelectionViewController() setPending:YES]; | |
| 85 [GetShippingOptionSelectionViewController() loadModel]; | |
| 86 | |
| 87 ASSERT_EQ(1, NumberOfSections()); | |
| 88 // There should be only one item. | |
| 89 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | |
| 90 | |
| 91 // The item should be of type StatusItem. | |
| 92 item = GetCollectionViewItem(0, 0); | |
| 93 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); | |
| 94 } | |
| OLD | NEW |