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

Side by Side Diff: ios/showcase/payments/sc_payments_selector_egtest.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 <EarlGrey/EarlGrey.h>
6
7 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h"
8 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
9 #import "ios/showcase/test/showcase_eg_utils.h"
10 #import "ios/showcase/test/showcase_test_case.h"
11
12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support."
14 #endif
15
16 namespace {
17 using ::showcase_utils::Open;
18 using ::showcase_utils::Close;
19 using ::chrome_test_util::ButtonWithAccessibilityLabel;
20
21 // Returns the GREYMatcher for the header item.
22 id<GREYMatcher> HeaderItem() {
23 return grey_allOf(grey_accessibilityLabel(@"Header item"),
24 grey_kindOfClass([UILabel class]),
25 grey_sufficientlyVisible(), nil);
26 }
27
28 // Returns the GREYMatcher for the selectable item with the given label.
29 // |selected| states whether or not the item must be selected.
30 id<GREYMatcher> SelectableItemWithLabel(NSString* label, BOOL selected) {
31 id<GREYMatcher> matcher = grey_allOf(ButtonWithAccessibilityLabel(label),
32 grey_sufficientlyVisible(), nil);
33 if (selected) {
34 return grey_allOf(
35 matcher, grey_accessibilityTrait(UIAccessibilityTraitSelected), nil);
36 }
37 return matcher;
38 }
39
40 // Returns the GREYMatcher for the add button.
41 id<GREYMatcher> AddButton() {
42 return grey_allOf(ButtonWithAccessibilityLabel(@"Add an item"),
43 grey_sufficientlyVisible(), nil);
44 }
45
46 } // namespace
47
48 // Tests for the payment request selector view controller.
49 @interface SCPaymentsSelectorTestCase : ShowcaseTestCase
50 @end
51
52 @implementation SCPaymentsSelectorTestCase
53
54 - (void)setUp {
55 [super setUp];
56 Open(@"PaymentRequestSelectorViewController");
57 }
58
59 - (void)tearDown {
60 Close();
61 [super tearDown];
62 }
63
64 // Tests if all the expected items are present and that none is selected.
65 - (void)testVerifyItems {
66 [[EarlGrey selectElementWithMatcher:HeaderItem()]
67 assertWithMatcher:grey_notNil()];
68
69 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
70 @"First selectable item", NO)]
71 assertWithMatcher:grey_notNil()];
72 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
73 @"Second selectable item", NO)]
74 assertWithMatcher:grey_notNil()];
75 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
76 @"Third selectable item", NO)]
77 assertWithMatcher:grey_notNil()];
78 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
79 @"Fourth selectable item", NO)]
80 assertWithMatcher:grey_notNil()];
81
82 [[EarlGrey selectElementWithMatcher:AddButton()]
83 assertWithMatcher:grey_notNil()];
84 }
85
86 // Tests that selectable items can be selected.
87 - (void)testCanSelectItems {
88 // Tap the first selectable item which is currently not selected.
89 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
90 @"First selectable item", NO)]
91 performAction:grey_tap()];
92
93 // Confirm the delegate is informed.
94 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
95 @"protocol_alerter_done")]
96 performAction:grey_tap()];
97
98 // Confirm the first selectable item is now selected. Tap it again.
99 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
100 @"First selectable item", YES)]
101 performAction:grey_tap()];
102
103 // Confirm the delegate is informed.
104 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
105 @"protocol_alerter_done")]
106 performAction:grey_tap()];
107
108 // Confirm the first selectable item is still selected.
109 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
110 @"First selectable item", YES)]
111 assertWithMatcher:grey_notNil()];
112
113 // Tap the second selectable item which is currently not selected.
114 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
115 @"Second selectable item", NO)]
116 performAction:grey_tap()];
117
118 // Confirm the delegate is informed.
119 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
120 @"protocol_alerter_done")]
121 performAction:grey_tap()];
122
123 // Confirm the second selectable item is now selected.
124 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel(
125 @"Second selectable item", YES)]
126 assertWithMatcher:grey_notNil()];
127 }
128
129 // Tests that item can be added.
130 - (void)testCanAddItem {
131 // Tap the add button.
132 [[EarlGrey selectElementWithMatcher:AddButton()] performAction:grey_tap()];
133
134 // Confirm the delegate is informed.
135 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
136 @"protocol_alerter_done")]
137 performAction:grey_tap()];
138 }
139
140 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698