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

Unified Diff: ios/chrome/browser/payments/payment_request_selector_view_controller_unittest.mm

Issue 2805273002: [Payment Request] Selector view controller (Closed)
Patch Set: Addressed comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/payments/payment_request_selector_view_controller_data_source.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/payments/payment_request_selector_view_controller_unittest.mm
diff --git a/ios/chrome/browser/payments/payment_request_selector_view_controller_unittest.mm b/ios/chrome/browser/payments/payment_request_selector_view_controller_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..f66b89a8f767bbfdbce61fd38e6dfb0ce9c7b10c
--- /dev/null
+++ b/ios/chrome/browser/payments/payment_request_selector_view_controller_unittest.mm
@@ -0,0 +1,135 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/payments/payment_request_selector_view_controller.h"
+
+#include "base/mac/foundation_util.h"
+#import "ios/chrome/browser/payments/cells/payments_text_item.h"
+#import "ios/chrome/browser/payments/payment_request_selector_view_controller_data_source.h"
+#import "ios/chrome/browser/ui/autofill/cells/status_item.h"
+#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface TestPaymentRequestSelectorMediator
+ : NSObject<PaymentRequestSelectorViewControllerDataSource>
+
+@property(nonatomic, copy) NSArray<CollectionViewItem*>* items;
+
+@property(nonatomic, readwrite, assign) PaymentRequestSelectorState state;
+
+@end
+
+@implementation TestPaymentRequestSelectorMediator
+
+@synthesize state = _state;
+@synthesize selectedItemIndex = _selectedItemIndex;
+@synthesize items = _items;
+
+- (instancetype)init {
+ self = [super init];
+ if (self) {
+ _items =
+ @[ [[PaymentsTextItem alloc] init], [[PaymentsTextItem alloc] init] ];
+ _selectedItemIndex = 0;
+ }
+ return self;
+}
+
+#pragma mark - PaymentRequestSelectorViewControllerDataSource
+
+- (CollectionViewItem*)headerItem {
+ return [[CollectionViewItem alloc] init];
+}
+
+- (NSArray<CollectionViewItem*>*)selectableItems {
+ return _items;
+}
+
+- (CollectionViewItem*)selectableItemAtIndex:(NSUInteger)index {
+ return [_items objectAtIndex:index];
+}
+
+- (CollectionViewItem*)addButtonItem {
+ return [[CollectionViewItem alloc] init];
+}
+
+@end
+
+class PaymentRequestSelectorViewControllerTest
+ : public CollectionViewControllerTest {
+ protected:
+ PaymentRequestSelectorViewControllerTest() {}
+
+ CollectionViewController* InstantiateController() override {
+ PaymentRequestSelectorViewController* viewController =
+ [[PaymentRequestSelectorViewController alloc] init];
+ mediator_ = [[TestPaymentRequestSelectorMediator alloc] init];
+ [viewController setDataSource:mediator_];
+ return viewController;
+ }
+
+ PaymentRequestSelectorViewController*
+ GetPaymentRequestSelectorViewController() {
+ return base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
+ controller());
+ }
+
+ TestPaymentRequestSelectorMediator* mediator_;
+};
+
+// Tests that the correct number of items are displayed after loading the model
+// and that the correct item appears to be selected.
+TEST_F(PaymentRequestSelectorViewControllerTest, TestModel) {
+ CreateController();
+ CheckController();
+
+ [GetPaymentRequestSelectorViewController() loadModel];
+
+ ASSERT_EQ(1, NumberOfSections());
+ // One header item, two selectable items, and one add button.
+ ASSERT_EQ(4, NumberOfItemsInSection(0));
+
+ // The first item should be of type CollectionViewItem.
+ id item = GetCollectionViewItem(0, 0);
+ ASSERT_TRUE([item isMemberOfClass:[CollectionViewItem class]]);
+
+ // The next two selectable items should be of type PaymentsTextItem. The first
+ // one should appear to be selected.
+ item = GetCollectionViewItem(0, 1);
+ ASSERT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]);
+ PaymentsTextItem* selectable_item = item;
+ EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark,
+ selectable_item.accessoryType);
+
+ item = GetCollectionViewItem(0, 2);
+ ASSERT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]);
+ selectable_item = item;
+ EXPECT_EQ(MDCCollectionViewCellAccessoryNone, selectable_item.accessoryType);
+
+ // The last item should be of type CollectionViewItem.
+ item = GetCollectionViewItem(0, 3);
+ EXPECT_TRUE([item isMemberOfClass:[CollectionViewItem class]]);
+}
+
+// Tests that the correct number of items are displayed after loading the model
+// in the pending state.
+TEST_F(PaymentRequestSelectorViewControllerTest, TestModelPendingState) {
+ CreateController();
+ CheckController();
+
+ [mediator_ setState:PaymentRequestSelectorStatePending];
+ [GetPaymentRequestSelectorViewController() loadModel];
+
+ ASSERT_EQ(1, NumberOfSections());
+ // There should be only one item.
+ ASSERT_EQ(1, NumberOfItemsInSection(0));
+
+ // The item should be of type StatusItem.
+ id item = GetCollectionViewItem(0, 0);
+ EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]);
+}
« no previous file with comments | « ios/chrome/browser/payments/payment_request_selector_view_controller_data_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698