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

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

Issue 2805273002: [Payment Request] Selector view controller (Closed)
Patch Set: 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
(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_request_selector_view_controller.h"
6
7 #include "base/mac/foundation_util.h"
8 #import "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
10 #import "ios/chrome/browser/payments/payment_request_selector_view_controller_da ta_source.h"
11 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
13 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h "
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 @interface PaymentRequestSelectorMediator
gambard 2017/04/10 09:47:35 Do you really want to create a class with a name a
Moe 2017/04/10 17:53:50 Done.
21 : NSObject<PaymentRequestSelectorViewControllerDataSource>
22
23 @property(nonatomic, strong) NSArray<CollectionViewItem*>* items;
24 @property(nonatomic, assign) NSUInteger selectedItemIndex;
25
26 @end
27
28 @implementation PaymentRequestSelectorMediator
29
30 @synthesize state = _state;
31 @synthesize selectedItemIndex = _selectedItemIndex;
32 @synthesize items = _items;
33
34 - (instancetype)init {
35 self = [super init];
36 if (self) {
37 _items = @[
38 [[CollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem],
gambard 2017/04/10 09:47:35 This would DCHECK in the styling done in cellForIt
Moe 2017/04/10 17:53:50 It wouldn't because it has an expected item type.
39 [[CollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem]
40 ];
41 _selectedItemIndex = 0;
42 }
43 return self;
44 }
45
46 #pragma mark - PaymentRequestSelectorViewControllerDataSource
47
48 - (CollectionViewItem*)headerItem {
49 return [[CollectionViewItem alloc] initWithType:kItemTypeHeaderItem];
50 }
51
52 - (NSArray<CollectionViewItem*>*)selectableItems {
53 return _items;
54 }
55
56 - (CollectionViewItem*)selectableItemAtIndex:(NSUInteger)index {
57 return [_items objectAtIndex:index];
58 }
59
60 - (NSString*)addButtonTitle {
61 return @"Add item";
62 }
63
64 @end
65
66 class PaymentRequestSelectorViewControllerTest
67 : public CollectionViewControllerTest {
68 protected:
69 PaymentRequestSelectorViewControllerTest() {}
70
71 CollectionViewController* NewController() override NS_RETURNS_RETAINED {
72 PaymentRequestSelectorViewController* viewController =
73 [[PaymentRequestSelectorViewController alloc] init];
74 mediator_.reset([[PaymentRequestSelectorMediator alloc] init]);
75 [viewController setDataSource:mediator_.get()];
76 return viewController;
77 }
78
79 PaymentRequestSelectorViewController*
80 GetPaymentRequestSelectorViewController() {
81 return base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
82 controller());
83 }
84
85 base::scoped_nsobject<PaymentRequestSelectorMediator> mediator_;
86 };
87
88 // Tests that the correct number of items are displayed after loading the model
89 // and that the correct item appears to be selected.
90 TEST_F(PaymentRequestSelectorViewControllerTest, TestModel) {
91 CreateController();
92 CheckController();
93
94 [GetPaymentRequestSelectorViewController() loadModel];
95
96 ASSERT_EQ(1, NumberOfSections());
97 // One header item, two selectable items, and one add button.
98 ASSERT_EQ(4, NumberOfItemsInSection(0));
99
100 // The first item should be of type CollectionViewItem.
101 id item = GetCollectionViewItem(0, 0);
102 ASSERT_TRUE([item isMemberOfClass:[CollectionViewItem class]]);
103
104 // The next two selectable items should be of type CollectionViewTextItem. The
105 // first one should appear to be selected.
106 item = GetCollectionViewItem(0, 1);
107 ASSERT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]);
108 CollectionViewTextItem* selectable_item = item;
109 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark,
110 selectable_item.accessoryType);
111
112 item = GetCollectionViewItem(0, 2);
113 ASSERT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]);
114 selectable_item = item;
115 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, selectable_item.accessoryType);
116
117 // The last item should be of type PaymentsTextItem.
118 item = GetCollectionViewItem(0, 3);
119 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]);
120 }
121
122 // Tests that the correct number of items are displayed after loading the model
123 // in the pending state.
124 TEST_F(PaymentRequestSelectorViewControllerTest, TestModelPendingState) {
125 CreateController();
126 CheckController();
127
128 [mediator_ setState:PaymentRequestSelectorViewControllerStatePending];
129 [GetPaymentRequestSelectorViewController() loadModel];
130
131 ASSERT_EQ(1, NumberOfSections());
132 // There should be only one item.
133 ASSERT_EQ(1, NumberOfItemsInSection(0));
134
135 // The item should be of type StatusItem.
136 id item = GetCollectionViewItem(0, 0);
137 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]);
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698