OLD | NEW |
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/shipping_option_selection_view_controller.h
" | 5 #import "ios/chrome/browser/payments/shipping_option_selection_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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/test_personal_data_manager.h" | 10 #include "components/autofill/core/browser/test_personal_data_manager.h" |
11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
13 #include "ios/chrome/browser/payments/payment_request.h" | 13 #include "ios/chrome/browser/payments/payment_request.h" |
14 #import "ios/chrome/browser/payments/payment_request_test_util.h" | 14 #import "ios/chrome/browser/payments/payment_request_test_util.h" |
15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | |
17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 16 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
18 #include "ios/web/public/payments/payment_request.h" | 17 #include "ios/web/public/payments/payment_request.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
22 #error "This file requires ARC support." | 21 #error "This file requires ARC support." |
23 #endif | 22 #endif |
24 | 23 |
25 class PaymentRequestShippingOptionSelectionViewControllerTest | 24 class PaymentRequestShippingOptionSelectionViewControllerTest |
26 : public CollectionViewControllerTest { | 25 : public CollectionViewControllerTest { |
(...skipping 23 matching lines...) Expand all Loading... |
50 CreateController(); | 49 CreateController(); |
51 CheckController(); | 50 CheckController(); |
52 CheckTitleWithId(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | 51 CheckTitleWithId(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); |
53 | 52 |
54 [GetShippingOptionSelectionViewController() loadModel]; | 53 [GetShippingOptionSelectionViewController() loadModel]; |
55 | 54 |
56 ASSERT_EQ(1, NumberOfSections()); | 55 ASSERT_EQ(1, NumberOfSections()); |
57 // One item for each of shipping options. | 56 // One item for each of shipping options. |
58 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 57 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
59 | 58 |
60 // The next two items should be of type CollectionViewTextItem. The first one | 59 // The next two items should be of type PaymentsTextItem. The first one |
61 // should appear to be selected. | 60 // should appear to be selected. |
62 id item = GetCollectionViewItem(0, 0); | 61 id item = GetCollectionViewItem(0, 0); |
63 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); | 62 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
64 CollectionViewTextItem* text_item = item; | 63 PaymentsTextItem* text_item = item; |
65 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, text_item.accessoryType); | 64 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, text_item.accessoryType); |
66 | 65 |
67 item = GetCollectionViewItem(0, 1); | 66 item = GetCollectionViewItem(0, 1); |
68 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); | 67 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
69 text_item = item; | 68 text_item = item; |
70 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, text_item.accessoryType); | 69 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, text_item.accessoryType); |
71 | 70 |
72 // Test the error state. | 71 // Test the error state. |
73 [GetShippingOptionSelectionViewController() setErrorMessage:@"Lorem ipsum"]; | 72 [GetShippingOptionSelectionViewController() setErrorMessage:@"Lorem ipsum"]; |
74 [GetShippingOptionSelectionViewController() loadModel]; | 73 [GetShippingOptionSelectionViewController() loadModel]; |
75 | 74 |
76 ASSERT_EQ(1, NumberOfSections()); | 75 ASSERT_EQ(1, NumberOfSections()); |
77 // There should be 3 items now in total. | 76 // There should be 3 items now in total. |
78 ASSERT_EQ(3U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 77 ASSERT_EQ(3U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
79 | 78 |
80 // The first item should also be of type TextAndMessageItem. | 79 // The first item should also be of type TextAndMessageItem. |
81 item = GetCollectionViewItem(0, 0); | 80 item = GetCollectionViewItem(0, 0); |
82 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | 81 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
83 | 82 |
84 // Test the pending state. | 83 // Test the pending state. |
85 [GetShippingOptionSelectionViewController() setPending:YES]; | 84 [GetShippingOptionSelectionViewController() setPending:YES]; |
86 [GetShippingOptionSelectionViewController() loadModel]; | 85 [GetShippingOptionSelectionViewController() loadModel]; |
87 | 86 |
88 ASSERT_EQ(1, NumberOfSections()); | 87 ASSERT_EQ(1, NumberOfSections()); |
89 // There should be only one item. | 88 // There should be only one item. |
90 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 89 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
91 | 90 |
92 // The item should be of type StatusItem. | 91 // The item should be of type StatusItem. |
93 item = GetCollectionViewItem(0, 0); | 92 item = GetCollectionViewItem(0, 0); |
94 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); | 93 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); |
95 } | 94 } |
OLD | NEW |